[Lazarus] MYSQL setup

Tom Lisjac zikon770 at gmail.com
Fri Nov 21 08:50:49 CET 2008


Hi Eric,

> I have followed source advice but can't connect.
> Can anyone help and/or is there a manual?

> Error: invalid compiler: file
> There must be something in my source looking for a compiler in the wrong
> place :-(

The errors you're getting in the tutorial example are from some hard
coded paths in the database_try.lpi project file. It's not a problem
with your system. Since Lazarus has changed since the example was
written, it might be easier to start your project with the sqldb
components.

To install sqldb, go to "Package->Open package file", select and
install the lazarus/components/sqldb/sqldblaz.lpk package. After
Lazarus recompiles, you should see a "SQLdb" tab. Drop a Mysql50
(TMySQL50Connection) on a new form. In the object inspector for this
component, enter the hostname (probably localhost), a database (test
or mysql as an example or a database you've already created) and the
username and password for the database or the "root" you set when
installing mysql. At this point, establishing a successful mysql
connection is being able to set the Connected property to true without
an error.

The next step is to add TSQLTransaction and TSQLQuery (a TDataset
descendent) to your form and point them to TMySQL50Connection.
TSQLQuery is used to pass DDL or DML sql statements to the database
and return DML result sets. Put your sql statements in the SQL
stringlist and use the ExecSQL method to execute DDL statements or the
open method to return a DML result set. Adding a TDatasource to the
form and pointing it at the TSQLQuery will allow you to use the data
aware components to display the query results.

Marco Cantu has posted a pdf extract from "Essential Delphi" that
provides a good sql overview:

http://www.marcocantu.com/edelphi/EssentialSQL_md6.pdf

Hopefully this will get you started. There books and examples on the
net about using TDatasets and the data aware components.

-Tom



More information about the Lazarus mailing list