设为首页 加入收藏

TOP

delphi连接mysql (通过libmysql.dll连接)
2019-08-23 00:31:19 】 浏览:97
Tags:delphi 连接 mysql 通过 libmysql.dll

首先在窗体上拖拽sqlconnection和sqlquery两个控件:

然后在测试连接中,写入以下代码(注意exe生成目录下需要有dbxopenmysql50.dll和libmysql.dll

  1. SQLConnection1 := TSQLConnection.Create( nil);
  2. SQLConnection1.DriverName := 'dbxmysql';
  3. SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50';
  4. SQLConnection1.LibraryName := 'dbxopenmysql50.dll';
  5. SQLConnection1.VendorLib := 'libmysql.dll';
  6. SQLConnection1.LoginPrompt := false;
  7. SQLConnection1.Params.Append( 'Database=sampledb31');
  8. SQLConnection1.Params.Append( 'User_Name=test');
  9. SQLConnection1.Params.Append( 'Password=test');
  10. SQLConnection1.Params.Append( 'HostName=192.168.1.78');
  11.  
  12. SQLConnection1.Open;
  13. if SQLConnection1.Connected = true then
  14. begin
  15. SQLQuery1.SQLConnection := SQLConnection1;
  16. SQLQuery1.SQL.Clear;
  17. SQLQuery1.SQL.Text := 'SET NAMES gbk;';//设置mysql查询中文不乱码
  18. SQLQuery1.ExecSQL();
  19. MessageBox( 0,'连接成功','提示',MB_ICONASTERISK and MB_ICONINFORMATION);
  20. end else
  21. begin
  22. showmessage( '数据库连接失败!');
  23. SQLConnection1.Close;
  24. end;
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[笔记] FMX 移动平台 TWebBrowser.. 下一篇0005-20180422-自动化第六章-pyth..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目