delphi中用dbexpress连接mysql5.7方法以及libmysql.dll和dbxopenmysql50.dll动态链接库

示例下载地址:https://download.csdn.net/download/wjw806/12358607

示例中有连接需要的libmysql.dll和dbxopenmysql50.dll动态链接库。

procedure TForm1.Button1Click(Sender: TObject);
var
  Connection: TSQLConnection;
  v1,v2:Variant;
 str1,str2:String;
 f:double;
 s:String;
begin
  Connection := TSQLConnection.Create(nil);
  Connection.DriverName := 'dbxmysql';
  Connection.GetDriverFunc := 'getSQLDriverMYSQL50';
  Connection.LibraryName := 'dbxopenmysql50.dll';
  Connection.VendorLib := 'libmysql.dll';
  Connection.Params.Append('Database=mysql');
  Connection.Params.Append('User_Name=root');
  Connection.Params.Append('Password=root');
  Connection.Params.Append('HostName=192.168.18.166');
  Connection.Params.Add('ServerCharSet=gb2312');


  Connection.LoginPrompt:=False;
  Connection.Open;

  SQLQuery1.SQLConnection:=Connection;
  ClientDataSet1.close;
  ClientDataSet1.CommandText:='select * from lh_test';
  ClientDataSet1.Open;
  DataSource1.DataSet :=ClientDataSet1;
  while not ClientDataSet1.Eof do
  begin
     v1:=ClientDataSet1.fieldByName('F101').Value ;
     v2:=ClientDataSet1.fieldByName('F102').Value ;
     if VarIsNull(v1) then
     begin
       str1:='null';
       Memo1.Lines.Add('F101 IS NUILL')

     end;

     if VarIsNull(v2) then
     begin
       str1:='null';

     end
     else begin
        f:=v2;
        Memo1.Lines.Add('F102 IS '+FloatToStr(f))
     end;

     v1:=ClientDataSet1.fieldByName('area_code').Value ;
     v2:=ClientDataSet1.fieldByName('data_period').Value ;
     if VarIsNull(v1) then
     begin
       str1:='null';
       Memo1.Lines.Add('area_code IS NUILL')

     end;

     if VarIsNull(v2) then
     begin
       str1:='null';

     end
     else begin
        s:=v2;
        Memo1.Lines.Add('data_period IS(空字符串): '+s)
     end;

    ClientDataSet1.Next
  end;


end;

 

在dbExpress面板的TSQLConnection可视化配置需要做的工作。

在\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

vendorLib 旁边打(path)libmysql.dll  如 c:\libmysql.dll

libmySQL.dll 以及 dbxopenmysql50.dll 放在程序文件夹下

设定Database、Hostname、User_Name、Password,还有字符集gb2312(否则中文乱码)

然后连接就ok了。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值