delphi中用dbexpress連接MySql5
解決:
http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html有解決方案。支持5.0.x版本。
下載后的配置
在\delphi7\dbexpress\dbxdrivers.ini 添加[MYSQL5]節:
[MYSQL5]
GetDriverFunc=getSQLDriverMYSQL50
LibraryName=dbxopenmysql50.dll
VendorLib=libmysql50.dll
BlobSize=-1
Database=DBNAME
ErrorResourceFile=
HostName=ServerName
LocaleCode=0000
Password=password
User_Name=user
ServerCharSet=GBK
在\delphi7\dbexpress\dbxdrivers.ini的 [Installed Drivers] 節追加一行:
MYSQL5=1
然后dbExpress面板的TSQLConnection就可以可視化配置了。
libraryName改成(path) debopenmysql50.dll 如 c:\debopenmysql50.dll
getDriverFunc也改成getSQLDriverMYSQL50<-這個是上面那個dll裡面的function
vendorLib 旁邊打(path)libmysql.dll 如 c:\libmysql.dll
記得要用mysql5.0裡面付的libmysql.dll
libmySQL.dll 以及 dbxopenmysql50.dll 放在程式資料夾下
然後照一般的設定Database、Hostname、User_Name、Password
然後連線就ok了,前提是MySql要記得開.
最終程序結構如下:
var
Connection: TSQLConnection;
begin
Connection := TSQLConnection.Create(nil);
Connection.DriverName := 'dbxmysql';
Connection.GetDriverFunc := 'getSQLDriverMYSQL50';
Connection.LibraryName := 'dbxopenmysql50.dll';
Connection.VendorLib := 'libmysql.dll';
Connection.Params.Append('Database=NAME_OF_DATABASE);
Connection.Params.Append('User_Name=NAME_OF_USER');
Connection.Params.Append('Password=PASSWORD');
Connection.Params.Append('HostName=localhost');
Connection.Open;
// ... do stuff
Connection.Free;
end;
或者
conn.ConnectionName = "<連接名>";
conn.DriverName = "MYSQL5";
conn.GetDriverFunc = "getSQLDriverMYSQL50";
conn.KeepConnection = true;
conn.LibraryName = "dbxopenmysql50.dll";
conn.LoadParamsOnConnect = false;
conn.LoginPrompt = false;
conn.VendorLib = "libmysql50.dll";
conn.Params.Append("Database=<數據庫名>");
conn.Params.Append("User_Name=<用戶名>");
conn.Params.Append("Password=<密碼>");
conn.Params.Append("HostName=<主機名名>");
conn.Params.Append("ServerCharSet=UTF-8"); //或者GBK/GB2312
conn.Open();
// DB操作
conn.Close();
參見
http://delphi.ktop.com.tw/board.php?cid=168&fid=918&tid=839939(臺灣)
http://www.kaimei.org/doc/skillup/dbx_mys1.html(日文)
補:
風林火山有3篇文章討論此問題.http://blog.csdn.net/freewind88/category/221073.aspx