Page 1 of 1

Pure Basic and MySql

Posted: Wed Aug 19, 2015 4:03 pm
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

Re: Pure Basic and MySql

Posted: Thu Aug 20, 2015 6:42 am
by netmaestro

Re: Pure Basic and MySql

Posted: Sat Aug 29, 2015 5:19 pm
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.

Re: Pure Basic and MySql

Posted: Sun Aug 30, 2015 12:25 am
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.

Re: Pure Basic and MySql

Posted: Sat Sep 05, 2015 11:23 pm
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.

Re: Pure Basic and MySql

Posted: Sun Sep 06, 2015 2:02 pm
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

Re: Pure Basic and MySql

Posted: Sun Sep 06, 2015 10:39 pm
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.

Re: Pure Basic and MySql

Posted: Mon Sep 07, 2015 9:20 pm
by HeX0R
Lima wrote:I find it very strange that the native commands PB not function.
You can use standard functions, see here