delphi7連接mysql5的實(shí)現(xiàn)方法
本文簡單介紹了Delphi7連接MySQL數(shù)據(jù)庫的實(shí)現(xiàn)方法,具體步驟如下:
首先先去下載:http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html
然后將下載到的dbxopenmysql5_dll.zip解壓出來,再把dbxopenmysql50.dll和libmysql.dll都放到工程文件夾下。
在Form上放上TSQLConnection、TSQLQuery、TStringGrid、3個TButton、TLable。
添加如下代碼:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, FMTBcd, StdCtrls, Grids, DB, SqlExpr;
type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
SQLQuery1: TSQLQuery;
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SQLConnection1 := TSQLConnection.Create(nil);
SQLConnection1.DriverName := 'dbxmysql';
SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50';
SQLConnection1.LibraryName := 'dbxopenmysql50.dll';
SQLConnection1.VendorLib := 'libmysql.dll';
SQLConnection1.LoginPrompt := false;
SQLConnection1.Params.Append('Database=mysql');
SQLConnection1.Params.Append('User_Name=root');
SQLConnection1.Params.Append('Password=');
SQLConnection1.Params.Append('HostName=localhost');
SQLConnection1.Open;
if SQLConnection1.Connected = true then
begin
SQLQuery1.SQLConnection := SQLConnection1;
Label1.Caption := 'success!';
end
else
Label1.Caption := 'failed!';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i, j: Integer;
begin
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('SELECT * FROM user');
SQLQuery1.Active := true;
i := 0;
SQLQuery1.First;
while not SQLQuery1.eof do
begin
for j := 0 to SQLQuery1.FieldCount - 1 do
StringGrid1.cells[j, i] := SQLQuery1.Fields[j].AsString;
SQLQuery1.next;
inc(i);
end;
SQLQuery1.Active := false;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if SQLConnection1.Connected = true then
SQLConnection1.Close;
SQLConnection1.Free;
end;
end.
經(jīng)測試,可實(shí)現(xiàn)正常連接與查詢。
- Delphi7中群發(fā)Email郵件的方法
- delphi實(shí)現(xiàn)保存和讀取圖片的方法
- Delphi遠(yuǎn)程連接Mysql的實(shí)現(xiàn)方法
- Delphi創(chuàng)建開機(jī)啟動項的方法示例
- Delphi實(shí)現(xiàn)獲取句柄并發(fā)送消息的方法
- Delphi實(shí)現(xiàn)木馬自我拷貝方法
- Delphi實(shí)現(xiàn)窗口文字淡入淡出漸變效果的方法
- Delphi實(shí)現(xiàn)獲取磁盤空間大小的方法
- Delphi中對時間操作方法匯總
- delphi實(shí)現(xiàn)將BMP格式圖形轉(zhuǎn)化為JPG格式圖形的方法
相關(guān)文章
Delphi實(shí)現(xiàn)獲取磁盤空間大小的方法
這篇文章主要介紹了Delphi實(shí)現(xiàn)獲取磁盤空間大小的方法,是一個很實(shí)用的功能,需要的朋友可以參考下2014-07-07
Delphi實(shí)現(xiàn)窗體感知鼠標(biāo)滑過并自動隱藏與顯示窗口的方法
這篇文章主要介紹了Delphi實(shí)現(xiàn)窗體感知鼠標(biāo)滑過并自動隱藏與顯示窗口的方法,涉及Delphi操作窗口及鼠標(biāo)事件的技巧,需要的朋友可以參考下2015-05-05
解決delphi TAdoQuery組件的close方法導(dǎo)致”列名無效“錯誤的問題
今天小編就為大家分享一篇解決delphi TAdoQuery組件的close方法導(dǎo)致”列名無效“錯誤的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Delphi實(shí)現(xiàn)碰撞球體完整實(shí)例代碼
這篇文章主要介紹了Delphi實(shí)現(xiàn)碰撞球體完整實(shí)例代碼,通過該實(shí)例,讀者可以完整的了解一個Delphi項目的創(chuàng)建過程,加深對Delphi運(yùn)行原理的了解,需要的朋友可以參考下2014-07-07
Delphi 根據(jù)字符串找到函數(shù)并執(zhí)行的實(shí)例
這篇文章主要介紹了Delphi 根據(jù)字符串找到函數(shù)并執(zhí)行的實(shí)例的相關(guān)資料,希望通過本能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09

