Page 1 of 1

Would like an example of accessing a MySQL DB in Delphi 7.

Posted: 07.12.2005, 03:50
by Chesso
Hello im new here(and new to anything db related besides some simple php/mysql) :).

Im wondering if anyone can show me an example(and explain) how i can access(read/write) to a MySQL Database. Im pretty sure the version is 4.1 it's with EasyPHP along with apache.

The database i need to access is a friends because im making a front-end gui for his console application and being able to access(read/write) accounts would be very usefull.

Thanks in advance.

Posted: 07.12.2005, 11:03
by zippo
Excuse me, but I'm not sure and I have to ask: You want to di it in Delphi, right?

Well if this is correct, then you can do the following:

Set the query property to RequestLive := true (this enables writing)

To open a query, just fill the SQL property (example MyQry.SQL.Text := 'Select * From TABLE') and execute the .Open method.

Now to edit you can do this (I presume you are located on the row you want to edit, if not use Next, Previous or Locate methods of MyQry).

MyQry.Edit
MyQRY.FieldByName('MY_FIELD').AsString := 'hello'. You can use AsInteger, AsFloat, AsDateTime,... etc. Consult the help.

MyQry.Post.

This is manually, but if you use the DB components (TDBEdit, TDBGrid,.. etc.) the most is done automatically.

It seems complex here, but it's easy when you have enough drill :)

Posted: 07.12.2005, 15:14
by Chesso
Heh heh yeah delphi, im just interested to know how exactly does it know that MySQL is running and such it's a question that's been bugging me :P

Posted: 07.12.2005, 17:02
by Chesso
Sorry for the double post but i just came across something, i opened one of the example projects in Delphi 7 and it refused to compile(saying RequestLive property or something didn't exist among other errors).

Im using 6.5.1 alpha CVS is their perhaps an older version i should use? i need to access MySQL 4.1.

Posted: 07.12.2005, 17:48
by Michael
Hi Chesso,

the examples are not fully adapted to the 6.5.1 alpha, yet. But one thing I can tell you so far: RequestLive changed to ReadOnly. Where RequestLive = true means ReadOnly = false (the default setting!).

Please read the "changes.htm" that comes with the each CVS-build and you will be informed.

Regards.

P.S.: To get into ZeosLib's DBOs I would suggest to read this article of our Knowledge base: The ZeosLib DBOs 6.1.5 with Delphi 7 and Firebird 1.5. Even if it's Firebird we are talking about the basics are the same... ;-)