4

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

5
  • 2
    Any particular reason to use MySQL? is it an existing DB? Otherwise Firebird might be a better choice. Commented Nov 22, 2009 at 12:20
  • We are migrating from Informix to MySQL in the company I work for, so I need to port a few custom applications over. Commented Nov 22, 2009 at 18:16
  • I'm also interested. Anyone with a PHP website using mySQL would love to know how to interface with it. +1 Commented Nov 22, 2009 at 20:05
  • There are dozens of third party components that will allow you to connect to MySQL. If you're using D2010 and want it right out of the box then you should use either dbGO (with ODBC) or dbExpress. Commented Nov 24, 2009 at 11:55
  • Let me explain further... The problem in setting up the initial test in "Data Explorer". Everything is set right (server name, port , database name, username & password) but I receive a "Cannot load LIBMYSQL.dll library (error code 0) when I try to test it. This works perfectly using the same database/table under Delphi for PHP 2.0. Commented Nov 28, 2009 at 9:50

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

I would vote for dbexpress. I will be more easy to switch to another database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.