Connect to Database via script?


moose2004

Recommended Posts

How do you connect to a MySQL database with script? This is what i have started with....

global dbase

global qr

dbase = db.OpenEx("DRIVER={MYSQL ODBC 3.51 Driver};SERVER='localhost';DSN='Test';UID='root';PWD='';DATABASE='Test'")

qr = db.Query(dbase,"select * from demo")

if(qr == 1)

system.MessageBox('found')

else

system.MessageBox('not found')

endif

db.CloseQuery(qr)

db.Close(dbase)

***All i am doing is checking to see if a table exists.... Any ideas?

Link to comment
Share on other sites

qr won't = 1. It returns a handle, but you can check for non-zero. Either way, use querytoclass() instead of query(). Really these are the only db. commands you need:

open() / openEx()

close()

queryToClass() : for SELECT statements

execute() : for all other SQL commands

queryToClass() is documented in this forum. Just do a search.

Link to comment
Share on other sites

I don't know. Most people don't post when they get it working, so presumably it was a typo. I have never had a problem getting db. working. The only issue I ever had was with the MySQL ODBC connector under 64 bit. It installs to the wrong directory. I find it easier to use their 3.x version than their 5.x version of the connector.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.