MySQL을 DB 컴포넌트 도움없이
바로 엑세스 하고자 할때 사용하는 라이브러리입니다.
TMySQL5는 컴포넌트로 설치할 수 있도록 되어 있지만
그다지 의미는 없습니다.
그냥 필요하신 분은 프로젝트에
mysql.pas
tmysql5.pas
두개만 추가해서 사용하시면 될 듯 합니다.
대략 코드는 아래와 같이 구사할 수 있습니다.
procedure TForm1.RunClick(Sender: TObject);
var
My1: TMySQL5;
k: integer;
begin
My1 := TMySQL5.Create(nil);
My1.Connect('localhost', 'user1', 'pass123');
// Call method Execute to submit your query to the server.
My1.Execute('select host,user from mysql.user');
// Demo of methods First, Next, Last and Prev usage.
Report.Clear;
My1.First;
// Use function AsString to retrive column value as string,
// otherwise use AsInteger for integer retrieval. For other type,
// use AsString and standard data conversion function, e.g. StrToDate, StrToFloat, etc.
Report.Lines.Add(My1.AsString(1) + ', ' + My1.AsString(2));
My1.Next;
Report.Lines.Add(My1.AsString(1) + ', ' + My1.AsString(2));
My1.Last;
Report.Lines.Add(My1.AsString(1) + ', ' + My1.AsString(2));
My1.Prev;
Report.Lines.Add(My1.AsString(1) + ', ' + My1.AsString(2));
// Demo of property RecordCount usage.
for k := 1 to My1.RecordCount do begin
My1.Move(k);
Report.Lines.Add(My1.AsString(1) + ', ' + My1.AsString(2));
end;
// Close connection to MySQL server.
My1.Close;
end;
이전에 순수 C 라이브러리로 MySQL API를 컨트롤해서
DB를 핸들링 한 적이 있는데 그기에 비해서
이건 훨씬 간편하고 편리합니다.
C++Builder6 Personal 버전에서 컴파일해서 실행화일 만들어지는 지만 해 봤습니다.
실제 DB를 연결하는 테스트는 해보지 않았습니다.
서핑하다가 괜잖은 것 같아서 올려 둡니다.
버전 1.0은 버그가 많은 경우가 많으니, 아마도 실전에 사용하기는 어떨지 모르겠네요.
워낙 가볍게 래핑 된 것이라서...
주의할 점은 LibMySQL.DLL이 패스상이 있거나 프로젝트가 있는 폴더가 있어야 합니다.
출처:
http://tmysql5.blogspot.com/