Mysql – Delphi 2010 and MySQL

delphidelphi-2010MySQL

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

Best Answer

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.