Pure Basic and MySql

Everything else that doesn't fall into one of the other PB categories.
Lima
User
User
Posts: 43
Joined: Tue Jul 14, 2015 2:52 pm

Pure Basic and MySql

Post by Lima »

Someone help me to understand how the PureBasic works with MySQL databases?
Examples of PureBasic online documentation do not work or miss something I could not identify.
How is the connection to the MySQL server?
How indicate which ODBC Driver/version I want to use?

You can join PureBasic code that works?

Advance grateful for any information
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Pure Basic and MySql

Post by netmaestro »

BERESHEIT
Lima
User
User
Posts: 43
Joined: Tue Jul 14, 2015 2:52 pm

Re: Pure Basic and MySql

Post by Lima »

Thank you for the information.

Only now I could test and the result is not entirely positive.

I find it very strange that the native commands PB not function.

On the other hand, since it did not merit the attention of anyone else,
I must conclude that does not exist in the user community
anyone else who uses Mysql or unable to lend a hand?

Thanks again.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Pure Basic and MySql

Post by Paul »

I find it very strange that the native commands PB not function.
PB works fine with MySQL. Just download ODBC drivers so you can connect to the MySQL server.
Image Image
Lima
User
User
Posts: 43
Joined: Tue Jul 14, 2015 2:52 pm

Re: Pure Basic and MySql

Post by Lima »

Thank you very much for your help.

Result = OpenDatabase (#Database, DatabaseName$, User$, Password$ [, Plugin])

In the example above, '' DatabaseName$" is not the MySql Database Name but the name assigned to the ODBC configuration and it is not clear in the help of PB.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Pure Basic and MySql

Post by Paul »

For anyone else having problems, here is a quick example of how to connect to a MySQL database using PureBasic and ODBC drivers...

MySQL Server is installed on a Server at: myserver.com
On the server side I used phpMyAdmin to log in and create a new user...
name: paul
pass: xxxx
and created a database for user paul called: mydatabase

On my personal computer I downloaded the 32bit ODBC driver since I am using PureBasic 32bit
https://dev.mysql.com/downloads/connect ... /3.51.html
Since I am running 64bit Windows I could not use the default ODBC Data Source tool.
I used the 32bit version... C:\Windows\System\SysWOW64\odbcad32.exe

Under User Tab I clicked Add User and selected MySQL ODBC driver
Then I entered the following data...
name: mysql
desc: mysql
server: myserver.com port:3306
user: paul
pass: xxxx
database: mydatabase
Pressing TEST button gave me success message meaning everything has been set up correctly.

Then tested with some PB code...

Code: Select all

UseODBCDatabase()
db=OpenDatabase(#PB_Any,"mysql","paul","xxxx")

If db
  If DatabaseQuery(db,"Create table Test(id int,mydata text)")
    Debug "Created new table"
    If DatabaseQuery(db,"Insert into Test(id,mydata)values(1,'hello')")
      Debug "Data added to table"
      Else
      Debug DatabaseError()
    EndIf
    
    Else
    Debug DatabaseError()
  EndIf
  
  CloseDatabase(db)
EndIf
Image Image
Lima
User
User
Posts: 43
Joined: Tue Jul 14, 2015 2:52 pm

Re: Pure Basic and MySql

Post by Lima »

Thank you Paul.

I understood and I appreciate the effort shown to clarify the issue.
But I still say that the PB manual information is unclear.
User avatar
HeX0R
Addict
Addict
Posts: 1227
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Pure Basic and MySql

Post by HeX0R »

Lima wrote:I find it very strange that the native commands PB not function.
You can use standard functions, see here
Post Reply