Page 1 of 1

how to connect PB to mysql with OpenDatabase?

Posted: Sat Jul 19, 2003 10:49 am
by kimio
i have a slight problem:

i just want to set up a connection from my PB-programm to a local mysql-database (mysql vers. 4.0; myODBC aktual version).

i dont want to use the OpenDatabaseRequester, because i want to open only one specific database.

my database connection parameters are:

ODBC DataSourceName = billing
host = localhost
database_name = billing
user = root
password = test

i tried this syntax: OpenDatabase(#2, billing$,root$, test$), but the result is '0' (=database not found or user/password wrong).

i can get the database from the mysql-controlcenter (=GUI for mysql-databases) without any problem using the parameters:

host = localhost
user = root
password = test

the whole code of my small programm is:

If InitDatabase() = 0
MessageRequester("Error", "Can't initialize Database (ODBC v3 or better) environment", 0)
End
EndIf

Result=OpenDatabase(#2, billing$,root$, test$)
MessageRequester("fehler1 = 0", Str(Result),#PB_MessageRequester_Ok)

query.s = "INSERT INTO billing.aktverb persID, anschlussID VALUES '123','123'"
Result=DatabaseQuery(query$)
MessageRequester("fehler2 = 0", Str(Result),#PB_MessageRequester_Ok)
CloseDatabase(#2)


it would be great, if anyone can help me!

thanks!

kimio

Posted: Sat Jul 19, 2003 10:58 am
by gnozal
Just a little remark : you don't test if the ODBC driver is found.

Code: Select all

DriverODBC.s = "MySQL" ; change here !
If ExamineDatabaseDrivers()
 While NextDatabaseDriver()
  If DatabaseDriverName() = DriverODBC
   Base_OK.b = 1
  EndIf
 Wend
EndIf
If Base_OK = 0
 ; ODBC driver not found !
Else
  If OpenDatabase(0, DriverODBC, BaseUser, BasePWD)
   ; Do database Stuff
  EndIf
EndIf 

Re: how to connect PB to mysql with OpenDatabase?

Posted: Sat Jul 19, 2003 12:22 pm
by woki
If DSN = billing exists than OpenDatabase(2, "billing","root", "test") should do it.

query.s = "INSERT INTO aktverb (persID, anschlussID) VALUES ('123','123')"
is ok if persID and anschlussID are defined as string

Result=DatabaseQuery(query.s)
CloseDatabase(2)

that's it.

how to connect PB to mysql with OpenDatabase?

Posted: Sat Jul 19, 2003 1:27 pm
by kimio
ok...i have tried everything, but it still does not work. the programm does not find the ODBC-driver.

->@gnozal: DriverODBC.s = "MySQL" ; change here !

in my ODBC-DSN-Information the description is "MySQL ODBC 3.51 Driver DSN". the change to this description does also not work. ( i am working today at home with my WIN98 SE system. but this should not be a problem, i guess?)

i have started working with this demo-download-version without the debugger. its my first day with PB. maybe it would be the best to get the full version with debugger.

thank you two a lot for your help!

kimio

it is working!

Posted: Sat Jul 19, 2003 1:50 pm
by kimio
ok, it works!

here is the full code.

----------------------------------------

InitDatabase()
DriverODBC.s = "billing" ; change here !
If ExamineDatabaseDrivers()
While NextDatabaseDriver()
If DatabaseDriverName() = DriverODBC
Base_OK.b = 1
EndIf
Wend
EndIf
If Base_OK = 0
MessageRequester("ODBC-driver", "not found",#PB_MessageRequester_Ok)
; ODBC driver not found !
Else
If OpenDatabase(2, aktverb$, root$, test$)
query.s = "INSERT INTO aktverb (persID, anschlussID) VALUES ('123','123')"
Result=DatabaseQuery(query.s)
MessageRequester("fehler2 = 0", Str(Result),#PB_MessageRequester_Ok)
CloseDatabase(0)
EndIf
EndIf