Difference between revisions of "MySQLDatabases"

From Free Pascal wiki
Jump to navigationJump to search
Line 21: Line 21:
 
===The basics===
 
===The basics===
 
We will try to make a program based on the one made [[Lazarus Database Tutorial/nl#Verbinding met MySQL vanuit een Lazarus Programma|here]] which is again based on the [[Lazarus Database Tutorial#Connecting to MySQL from a Lazarus Application|original]] by [[user:kirkpatc|Chris]].
 
We will try to make a program based on the one made [[Lazarus Database Tutorial/nl#Verbinding met MySQL vanuit een Lazarus Programma|here]] which is again based on the [[Lazarus Database Tutorial#Connecting to MySQL from a Lazarus Application|original]] by [[user:kirkpatc|Chris]].
We will use the same main screen and build all functionality from scratch :) As you will see there is a lot less to take care of, because the components really take away all the hard stuff! So lets start by making a screen that looks like this [[images/2/28/Trymysql.png]].
+
 
 +
===The main form===
 +
We will use the same main screen and build all functionality from scratch :) As you will see there is a lot less to take care of, because the components really take away all the hard stuff! So lets start by making a screen that looks like this [[image:Trymysql.png]].
 +
From the SQLdb-tab place a TMySQLConnection, a TSQLTransaction and a TSQLQuery on this form.
 +
[[image:Components.png]]
 +
 
 +
===The code===

Revision as of 14:01, 7 April 2005

Introduction

Work in progress

In the Database tutorial we saw a first attempt to connect to a MySQL server. We did not use any components, either visual or non-visual at that time. This page will explain how to connect to a MySQL server in a (perhaps) easier way.

Components to use

MySQL Components

If you look in the $Lazarus/components/mysql directory you will find two lazarus packages. There is a package for MySQL version 3.2x (mysql3laz.lpk) and one for MySQL version 4.x (mysql4laz.lpk). If you did not do so yet, install the appropriate package, depending on the server version. Remember that it is not possible to use the package for version 3 to connect to a server running version 4 or vice versa. When you've installed this package you will see a new tab in the component palet, called MySQL. On this tab there are two components, TMySQLDatabase and TMySQLDataset.

SQLdb Components

Another possibility is the installation of the package in the $Lazarus/components/sqldb directory. In this directory you see a package file called sqldblaz.lpk. You need to install this package and the mysql4connlaz.lpk form the $Lazarus/components/sqldb/mysql directory. The first package contains some general components used for all databases. These component are TSQLTransation and TSQLQuery and can be found on the new SQLdb tab. After installation of the mysql4connlaz.lpk you will find a third component on the SQLdb tab called TMySQLConnection (depicted by a dolphin).

If you do not know how to install components / packages, have a look at this page for an "Install Howto". As the SQLdb components are the more general and can be used for other databases just by replacing the TMySQLConnection with for instance a TIBConnection, we will develop a program with the SQLdb components.

Our program

The basics

We will try to make a program based on the one made here which is again based on the original by Chris.

The main form

We will use the same main screen and build all functionality from scratch :) As you will see there is a lot less to take care of, because the components really take away all the hard stuff! So lets start by making a screen that looks like this Trymysql.png. From the SQLdb-tab place a TMySQLConnection, a TSQLTransaction and a TSQLQuery on this form. Components.png

The code