تقدم هذه المقالة بإيجاز طريقة تنفيذ اتصال Delphi7 بقاعدة بيانات MySQL، والخطوات المحددة هي كما يلي:
قم بتنزيله أولاً: http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html
ثم قم بفك ضغط ملف dbxopenmysql5_dll.zip الذي تم تنزيله، ثم ضع كلاً من dbxopenmysql50.dll و libmysql.dll في مجلد المشروع.
ضع TSQLConnection وTSQLQuery وTStringGrid و3 TButtons وTLable في النموذج.
أضف الكود التالي:
وحدة Unit1؛ تستخدم واجهات Windows، والرسائل، وSysUtils، والمتغيرات، والفئات، والرسومات، وعناصر التحكم، والنماذج، ومربعات الحوار، وDBXpress، وFMTBcd، وStdCtrls، وGrids، وDB، وSqlExpr؛ : زر TStringGrid1: TButton2: TButton؛ Button3: TButton؛ Label1: TLabel؛ الإجراء Button1Click(Sender: TObject); الإجراء Button2Click(Sender: TObject); فار Form1: TForm1؛ إجراء التنفيذ {$R *.dfm}. TForm1.Button1Click(Sender: TObject);begin SQLConnection1 := TSQLConnection.Create(nil); SQLConnection1.DriverName := 'dbxmysql'; SQLConnection1.VendorLib := 'libmysql.dll'; SQLConnection1.LoginPrompt := false; SQLConnection1.Params.Append('Database=mysql'); 'كلمة المرور='); SQLConnection1.Params.Append('HostName=localhost'); SQLConnection1.Open; إذا كان SQLConnection1.Connected = صحيحًا، فابدأ SQLQuery1.SQLConnection:= SQLConnection1; فشل!';نهاية; الإجراء TForm1.Button2Click(Sender: TObject);var i, j: Integer;begin SQLQuery1.SQL.Clear; SQLQuery1.SQL.Add('SELECT * FROM user'); SQLQuery1.Active := صحيح; SQLQuery1.First; .FieldCount - 1 تفعل StringGrid1.cells[j, i] := SQLQuery1.Fields[j].AsString; SQLQuery1.next; inc(i); end; SQLQuery1.Active:= false;end; الإجراء TForm1.Button3Click(Sender: TObject);
بعد الاختبار، يمكن تحقيق الاتصال والاستعلام العادي.