이 기사에서는 Delphi7을 MySQL 데이터베이스에 연결하는 구현 방법을 간략하게 소개합니다. 구체적인 단계는 다음과 같습니다.
먼저 다운로드하세요: http://www.justsoftwasolutions.co.uk/delphi/dbexpress_and_mysql_5.html
그런 다음 다운로드한 dbxopenmysql5_dll.zip의 압축을 풀고 dbxopenmysql50.dll과 libmysql.dll을 모두 프로젝트 폴더에 넣습니다.
TSQLConnection, TSQLQuery, TStringGrid, 3개의 TButton 및 TLable을 폼에 넣습니다.
다음 코드를 추가하세요.
단위 Unit1;인터페이스는 Windows, 메시지, SysUtils, 변형, 클래스, 컨트롤, 양식, 대화 상자, DBXpress, FMTBcd, StdCtrls, 그리드, DB, SqlExpr을 사용합니다. TForm1 = class(TForm) SQLConnection1: TSQLConnection1: TSQLQuery1; : TStringGrid 버튼1: TButton; TButton; TButton; TLabel; 프로시저 Button2Click(Sender: TObject); private { 개인 선언 } end; var Form1: TForm1; 구현 {$R *.dfm} 절차 TForm1.Button1Click(발신자: TObject);begin SQLConnection1 := TSQLConnection.Create(nil); SQLConnection1.DriverName := 'dbxmysql'; SQLConnection1.GetDriverFunc := 'getSQLDriverMYSQL50'; SQLConnection1.LibraryName := 'dbxopenmysql50.dll'; SQLConnection1.VendorLib := 'libmysql.dll'; SQLConnection1.LoginPrompt := false; SQLConnection1.Params.Append('Database=mysql'); SQLConnection1.Params.Append('User_Name=root'); '비밀번호='); SQLConnection1.Params.Append('HostName=localhost'); SQLConnection1.Connected = true인 경우 SQLQuery1.SQLConnection := SQLConnection1; end else Label1.Caption := ' 실패!';end; 절차 TForm1.Button2Click(Sender: TObject);var i, j: 정수;시작 SQLQuery1.SQL.Clear; SQLQuery1.SQL.Add('SELECT * FROM user'); SQLQuery1.Active := true; i := 0; SQLQuery1.eof가 아닌 경우:= 0 .FieldCount - 1 do StringGrid1.cells[j, i] := SQLQuery1.Fields[j].AsString; SQLQuery1.next; end; SQLQuery1.Active := false;end; 프로시저 TForm1.Button3Click(Sender: TObject);SQLConnection1.Connected = true인 경우 SQLConnection1.Close;end;
테스트 후 정상적인 연결 및 쿼리가 가능합니다.