1 |
|
Driver={MySQL ODBC 5.1 Driver}; Server=127.0.0.1; Database=world; User=root; Password=a123; Option=3; |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 |
|
procedure TForm1.FormCreate(Sender: TObject); begin //---------------互相关联------------------------ zqry1.Connection := zcon1; ds1.DataSet := zqry1; dbgrd1.DataSource := ds1; //---------------设置参数------------------------ zcon1.Protocol := ‘mysql‘; zcon1.Port := 3306; zcon1.HostName := ‘127.0.0.1‘; zcon1.User := ‘root‘; zcon1.Password := ‘a123‘; zcon1.Database := ‘world‘; zcon1.Connected := True; //---------------查询显示------------------------ zqry1.Close; zqry1.SQL.Text := ‘SELECT * FROM City‘; zqry1.Active := True; end; |
1 2 3 4 5 6 7 |
|
begin zqry1.Close; zqry1.SQL.Text := ‘set names gbk‘; zqry1.ExecSQL; zqry1.SQL.Text := ‘select * from city‘; zqry1.Active := True; end; |
或者在TZConnection的Properties属性添加"codepage=gbk"。
3.其他方式
另外,还有其他的第三方控件可以连接MySql等其他数据库,如:AnyDAC、MyDAC 、DAC for MySQL等等。
Delphi 7连接MySql 5.5.15,布布扣,bubuko.com
原文地址:http://blog.csdn.net/lailai186/article/details/32111497