It is currently Wed Jun 19, 2013 12:34 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to connect PB to mysql with OpenDatabase?
PostPosted: Sat Jul 19, 2003 10:49 am 
Offline
New User
New User

Joined: Sat Jul 19, 2003 10:37 am
Posts: 8
Location: heidelberg / germany
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 19, 2003 10:58 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4231
Location: Strasbourg / France
Just a little remark : you don't test if the ODBC driver is found.

Code:
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


Top
 Profile  
 
 Post subject: Re: how to connect PB to mysql with OpenDatabase?
PostPosted: Sat Jul 19, 2003 12:22 pm 
Offline
User
User

Joined: Fri Apr 25, 2003 4:48 pm
Posts: 22
Location: Germany
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.


Top
 Profile  
 
 Post subject: how to connect PB to mysql with OpenDatabase?
PostPosted: Sat Jul 19, 2003 1:27 pm 
Offline
New User
New User

Joined: Sat Jul 19, 2003 10:37 am
Posts: 8
Location: heidelberg / germany
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


Top
 Profile  
 
 Post subject: it is working!
PostPosted: Sat Jul 19, 2003 1:50 pm 
Offline
New User
New User

Joined: Sat Jul 19, 2003 10:37 am
Posts: 8
Location: heidelberg / germany
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye