求DELPHI7+MYSQL5的连接方案(ODBC及dbexpress方式都可以)(200)

  • 主题发起人 主题发起人 jlcsx
  • 开始时间 开始时间
J

jlcsx

Unregistered / Unconfirmed
GUEST, unregistred user!
求DELPHI7+MYSQL5的连接方案(ODBC及dbexpress方式都可以)最后能附个DEMO
 
1、http://hi.baidu.com/zsjjjj/blog/item/5df8354e773a35ccd0c86a7a.html2、http://blog.sina.com.cn/s/blog_515365250100be5d.html3、http://download.csdn.net/source/9842744、delphi中用dbexpress连接MySql5解决:http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html有解决方案。支持5.0.x版本。下载后的配置在/delphi7/dbexpress/dbxdrivers.ini 添加[MYSQL5]节:[MYSQL5]GetDriverFunc=getSQLDriverMYSQL50LibraryName=dbxopenmysql50.dllVendorLib=libmysql50.dllBlobSize=-1Database=DBNAMEErrorResourceFile=HostName=ServerNameLocaleCode=0000Password=passwordUser_Name=userServerCharSet=GBK在/delphi7/dbexpress/dbxdrivers.ini的 [Installed Drivers] 节追加一行:MYSQL5=1然后dbExpress面板的TSQLConnection就可以可视化配置了。libraryName改成(path) debopenmysql50.dll 如 c:/debopenmysql50.dllgetDriverFunc也改成getSQLDriverMYSQL50<-這個是上面那個dll裡面的functionvendorLib 旁邊打(path)libmysql.dll 如 c:/libmysql.dll記得要用mysql5.0裡面付的libmysql.dlllibmySQL.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();
 
UniDAC( http://www.devart.com ) //UniConnection1 : TUniConnection; UniConnection1.Close; UniConnection1.Username := 'root'; UniConnection1.Password := 'Password'; UniConnection1.Server := '127.0.0.1'; UniConnection1.Database := 'MySQLDB'; UniConnection1.Open;
 
同楼上,原来叫MyDAC,专用链接MySQL的
 
ADO通过ODBC直接连接: S:=Format('Provider=MSDASQL.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s',[PassWord,UserName,ODBCName]);ADO不通过ODBC,直接访问数据库 S:=Format('Provider=MSDASQL.1;Persist Security Info=False;Extended Properti' + 'es="DATABASE=%s;DRIVER={MySQL ODBC 3.51 Driver};OPTION=3;PO' + 'RT=0;SERVER=%s;UID=%s;password=%s"',[DataBaseName,DataBaseIP,UserName,PassWord]);
 
多人接受答案了。
 
后退
顶部