TV LIVE

mardi 29 novembre 2011

Delphi and MySQL



When it comes the time for a developer to create good database applications that need interaction with database servers, one might think twice about using Delphi for this task, and they couldn´t be more wrong. There are tools for Delphi that simplify the process of connecting to the most known RDBM´s like MySQL, Microsoft SQL, PostgreSQL, Oracle, etc…
Most of the software I develop at work is in Delphi and at the beginning (years ago) I was using simple paradox database tables, which might be good for simple applications but if you need to create real applications that need to be used by multiple users simultaneously, its the worst choice you can make.
All the software was becoming a problem to maintain, with tables becoming corrupted and users complaining, so I made the decision of moving to a real database system and rewrite most of my code. It was the best choice I could have made.
MySQL was the chosen database because I already had good experience working with PHP and MySQL.
Now, for the good stuff.

How to connect to MySQL database from Delphi?

After a quick search on google, I found a few components to connect to MySQL with Delphi, but most of them implicated using external stuff like ODBC connections which I was avoiding. After experimenting with several components I found that the best one was also the simplest to install – the ZeosLib.
A quick description of ZeosLib from their sourceforge project website :
The ZeosLib is a set of database components for MySQL, PostgreSQL, Interbase, Firebird, MS SQL, Sybase, Oracle and SQLite for Delphi, FreePascal/Lazarus, Kylix and C++ Builder.
By installing the ZeosLib set of components you will be able to use any of the following databases :
  • MySQL (normal and embedded)
  • PostgreSQL
  • Firebird (normal and embedded)
  • Interbase
  • SQLite
  • MS SQL Server
  • Oracle
  • Sybase
  • ADO Connections
After installing the components you just add them to a form or datamodule and you may use any of the existing database controls present by default on Delphi, which make the process of migrating applications much easier.
Since ZeosLib can be used with various database systems, if later you decide to change to another one, just change the protocol on the connection component and the rest of the process should be easy as pie.
Here are a few links that might give more help about ZeosLib :
http://sourceforge.net/projects/zeoslib/ – The sourceforge project page for ZeosLib.
http://zeos.firmos.at/portal.php – The official portal of ZeosLib, you can find the support forum there.
http://zeos.firmos.at/kb.php?mode=article&k=6 – gto’s Zeos Quick Start Guide

Aucun commentaire:

Enregistrer un commentaire