In diesem Artikel wird kurz die Implementierungsmethode für die Verbindung von Delphi7 mit der MySQL-Datenbank vorgestellt. Die spezifischen Schritte sind wie folgt:
Laden Sie es zuerst herunter: http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html
Entpacken Sie dann die heruntergeladene dbxopenmysql5_dll.zip und legen Sie sowohl dbxopenmysql50.dll als auch libmysql.dll im Projektordner ab.
Fügen Sie TSQLConnection, TSQLQuery, TStringGrid, 3 TButtons und TLable in das Formular ein.
Fügen Sie den folgenden Code hinzu:
Unit Unit1;Schnittstellen: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DBXpress, FMTBcd, StdCtrls, Grids, DB, SqlExpr;type TForm1 = class(TForm) SQLConnection1: TSQLConnection; StringGrid1 : TStringGrid; Button1: TButton; Button2: TButton; Label1: TLabel; procedure Button2Click(Sender: TObject); private { Privatdeklarationen } end; var Form1: TForm1; Implementierung {$R *.dfm} Prozedur TForm1.Button1Click(Sender: TObject);begin SQLConnection1 := TSQLConnection.Create(nil); SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50'; SQLConnection1.LibraryName := 'dbxopenmysql50.dll'; SQLConnection1.VendorLib := 'libmysql.dll'; SQLConnection1.Params.Append('Database=mysql'); SQLConnection1.Params.Append( 'Passwort='); SQLConnection1.Params.Append('HostName=localhost'); if SQLConnection1.Connected = true then begin SQLQuery1.SQLConnection := 'success!'; fehlgeschlagen!';end; procedure TForm1.Button2Click(Sender: TObject);var i, j: Integer;begin SQLQuery1.SQL.Add('SELECT * FROM user'); SQLQuery1.Active := true; while not SQLQuery1.eof do begin for j := 0 .FieldCount - 1 für StringGrid1.cells[j, i] := SQLQuery1.Fields[j].AsString; SQLQuery1.next; inc(i); SQLQuery1.Active := false;end; begin if SQLConnection1.Connected = true then SQLConnection1.Free;end;
Nach dem Testen können normale Verbindungen und Abfragen hergestellt werden.