MySQL and the PB Database commands?

Just starting out? Need help? Post your questions and find answers here.
PBUser
User
User
Posts: 20
Joined: Mon Aug 20, 2007 6:03 pm
Location: Germany

MySQL and the PB Database commands?

Post by PBUser »

Hi Guys,

i want to connect to a mysql database and manage it with the pb-included Database commands. I already used the search in the german and in the english forum, but there was no entry that worked with PureBasic 4.20.

I hope, you can help me.
Thanks in advance,

PBUser
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Install MyODBC 3.51
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PBUser
User
User
Posts: 20
Joined: Mon Aug 20, 2007 6:03 pm
Location: Germany

Post by PBUser »

OK... Installed. What shall I do now?

//edit: Does this work on Windows Vista? If it doesn't work, we'll have to switch to the libmysql :-(
PBUser
User
User
Posts: 20
Joined: Mon Aug 20, 2007 6:03 pm
Location: Germany

Post by PBUser »

Anybody? ;-)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Yes this should work on Vista.
ODBC is the Microsoft Database Layer, so it would be seriously bad if it doesn't , but i did not test (successfully tested on 2K, XP, 2K3 Server).

Once MyODBC is installed, you have to configure (manually or programmaticaly) a database connection.

for that, follow instructions :

1/
start -> execute -> odbcad32.exe

2/
make sure you have MySQL ODBC 3.51 Driver in 'ODBC Driver' page

3/
system data source -> add -> select MyODBC

4/
Data Source Name = test
Description =
Server = localhost (or external hosts/IP but make sure port 3306 is opened, so check your firewall and mysql user/rights)
User = root
Password =
Database = mysql

5/
click on 'test' button to check if connection is ok

6/
ok your odbc connection is ready, now let's see what to do inside purebasic

7/
just execute this sample :

Code: Select all

;-------------------------------------------------------------------------
; Database Exemple for PureBasic 4.2x.
; This minimalist example require a 'test' data source.
; Data source must be first configured in the ODBC manager (odbcad32.exe).
;-------------------------------------------------------------------------


; Initialize the ODBC engine

If UseODBCDatabase()
  
  ; Connect to the MySQL database
  
  If OpenDatabase(0, "test", "root", "")
    
    ; Execute a SQL query
    
    If DatabaseQuery(0, "SELECT help_topic_id, name FROM mysql.help_topic")
      
      ; Fetching rows
      
      While NextDatabaseRow(0)
        Debug GetDatabaseString(0, 0) + " ==> " + GetDatabaseString(0, 1)
      Wend
      
    Else
      
      MessageRequester("Error", "DatabaseQuery() failed !" + #CRLF$ + DatabaseError())
      
    EndIf
    
    ; Once fetching done, closing opened database.
    
    CloseDatabase(0)
    
  Else
    
    MessageRequester("Error", "OpenDatabase() failed !" + #CRLF$ + DatabaseError())
    
  EndIf
  
Else
  
  MessageRequester("Error", "UseODBCDatabase() failed !")
  
EndIf

End
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

and there's also very old tutorials here that i took years ago :
PB_SQL.zip
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply