Use the DBExpress component of Delphi6 to connect to the remote Mysql database Delphi6. The new DBExpress is used to deal with databases such as Mysql, DB2, Interbase, and Oracle.
Copy the file to the current directory or system directory (98: system, NT: system32), and ensure that your port 3306 is consistent with the remote server.
SOURCE program:
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, DB, SqlExpr, StdCtrls, ComCtrls, FMTBcd, Grids,
DBGrids, Provider, DBClient, DBLocal, DBLocalS, DBTables;
Type
TForm1 = class (TForm)
SQLConnection: TSQLConnection;
StatusBar1: TStatusBar;
Label1: TLabel;
Performance1: TDataSource;
DBGrid1: TDBGrid;
GroupBox1: TGroupBox;
Label2: TLabel;
Password: TEdit;
User_Name: TEdit;
HostName: TEdit;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
GroupBox2: TGroupBox;
Label5: TLabel;
ESQL: TEdit;
Label6: TLabel;
Database: TEdit;
ButtonGo: TButton;
SQLClientDataSet: TSQLClientDataSet;
Procedure Button1Click (Sender: TObject );
Procedure ButtonGoClick (Sender: TObject );
Procedure FormClose (Sender: TObject; var Action: TCloseAction );
Private
{Private declarations}
Public
{Public declarations}
End;
Var
Form1: TForm1;
Implementation
{$ R *. dfm}
Procedure TForm1.Button1Click (Sender: TObject );
Begin
With SQLConnection do
Begin
Close;
Params. Values ['hostname']: = HostName. Text;
Params. Values ['username']: = User_Name.Text;
Params. Values ['password']: = Password. Text;
Params. Values ['database']: = Database. Text;
Try
Connected: = True;
Statusbar1.Panels [0]. Text: = 'connect OK ';
ButtonGo. Enabled: = True;
Except
MessageDlg ('connect error', mtError, [mbyes], 0 );
End;
End;
End;
Procedure TForm1.ButtonGoClick (Sender: TObject );
Begin
With SQLClientDataSet do
Begin
Close;
CommandText: = ESQL. Text;
Open;
End;
End;
Procedure TForm1.FormClose (Sender: TObject; var Action: TCloseAction );
Begin
SQLConnection. Close;
End;
End.