views:

1679

answers:

3

Does anyone know of a simple tuturial for setting up and using Delphi 2010 with MySQL?

A: 

Use TAdoConnection and TAdoQuery:

implementation
uses adodb;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  mAdoConnection: TAdoConnection;
  mAdoQuery: TAdoQuery;
begin
  mAdoConnection := TAdoConnection.Create(application);
  mAdoConnection.ConnectionString := 'Mode=ReadWrite;Extended Properties="DRIVER=MySQL ODBC 3.51 Driver;DATABASE=mydatabase;SERVER=myserver;UID=myusername;PASSWORD=mypassword;PORT=;OPTION=3;STMT=;"';
  mAdoConnection.LoginPrompt := False;
  mAdoConnection.Open;
  mAdoQuery:=TADOQuery.Create(application);

  with mAdoQuery do begin
    Connection:=mADOConnection;
    CursorType := ctStatic;
    ParamCheck := False;
    SQL.Add('SELECT * FROM SYSSET');
  end;
  mAdoQuery.Open;
  showmessage(mAdoQuery.fields[0].AsString);
  mAdoQuery.free;
  mAdoConnection.Free;


end;

Note: change the "My....." to your server, database, username and password. This also assumes you have the MySql ODBC driver installed on the computer.

M Schenkel
+1  A: 

dbExpress is included in Delphi 2010 which supports mySQL

For a ODBC solution, this article should get you started: Using Delphi with MySQL"

Also, these resources should prove useful:

Finally, have a look here: Delphi 2010 Compatible Third Party Tools & Components for some commercial packages.

Adrian
I would vote for dbexpress. I will be more easy to switch to another database.
Hugues Van Landeghem
My vote to AnyDAC.
oodesigner
A: 

Hi

You may find this article useful:

http://lgwm.org/articles/microolap-delphi/phonebook.htm

lallous