• Print

Author Topic: MYSQL CLIENT for QB64  (Read 1663 times)

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4227
  • QB Forever
    • Email
MYSQL CLIENT for QB64
« on: September 10, 2011, 06:30:41 AM »
Code: [Select]
'MYSQL CLIENT for QB64

'Notes:
'1) Make sure you are running QB64 V0.942 or higher
'2) Download 'mysql.dll' and place it in your qb64 folder (http://www.qb64.net/mysql.dll)
'3) Create 'mysql_helper.h' in your QB64 folder (see below)
'4) Run & enjoy browsing our sample database as a member with read-only priv.

'#### mysql_helper.h (you create this file) ####
'    void *offset_to_offset(void* offset){
'    return offset;
'    }
'    void *offset_at_offset(void** offset){
'    return *offset;
'    }
DECLARE CUSTOMTYPE LIBRARY "mysql_helper"
    FUNCTION offset_to_string$ ALIAS offset_to_offset (BYVAL offset AS _OFFSET)
    FUNCTION offset_at_offset%& (BYVAL offset AS _OFFSET)
END DECLARE

'#### download mysql.dll from http://www.qb64.net/mysql.dll (~2MB) ####
DECLARE DYNAMIC LIBRARY "mysql"
    FUNCTION mysql_get_client_info$
    FUNCTION mysql_init%& (BYVAL x AS LONG)
    FUNCTION mysql_real_connect& (BYVAL mysql AS _OFFSET, host AS STRING, user AS STRING, password AS STRING, db AS STRING, BYVAL port AS _UNSIGNED LONG, BYVAL unix_socket AS _OFFSET, BYVAL client_flag AS _UNSIGNED _OFFSET)
    SUB mysql_close (BYVAL mysql AS _OFFSET)
    SUB mysql_query (BYVAL mysql AS _OFFSET, what AS STRING)
    FUNCTION mysql_store_result%& (BYVAL mysql AS _OFFSET)
    FUNCTION mysql_num_fields& (BYVAL result AS _OFFSET)
    FUNCTION mysql_fetch_row%& (BYVAL result AS _OFFSET)
    SUB mysql_free_result (BYVAL result AS _OFFSET)
    '...
END DECLARE

DIM conn AS _OFFSET

PRINT "MYSQL Client: " + mysql_get_client_info$

conn = mysql_init(0)
IF conn = 0 THEN PRINT "Could not init MYSQL client!": END

'*** Open the db ***
'PRINT mysql_real_connect(conn, "qb64db2.db.7445102.hostedresource.com", "", "", "qb64db2", 0, 0, 0)
PRINT mysql_real_connect(conn, "qb64db2.db.7445102.hostedresource.com", "qb64guest", "QB64forever", "qb64db2", 0, 0, 0)

'*** Write to the db (not possible as a guest!) ***
GOTO skip_write '(guests can't do this anyway)
mysql_query conn, "CREATE TABLE writers(name VARCHAR(25))"
mysql_query conn, "INSERT INTO writers VALUES('Leo Tolstoy')"
mysql_query conn, "INSERT INTO writers VALUES('Jack London')"
mysql_query conn, "INSERT INTO writers VALUES('Honore de Balzac')"
mysql_query conn, "INSERT INTO writers VALUES('Lion Feuchtwanger')"
mysql_query conn, "INSERT INTO writers VALUES('Emile Zola')"
skip_write:

'*** Read from the db ***
mysql_query conn, "SELECT * FROM writers"
DIM result AS _OFFSET
result = mysql_store_result(conn)
DIM num_fields AS LONG
num_fields = mysql_num_fields(result)
DIM row AS _OFFSET
DO
    row = mysql_fetch_row(result)
    IF row THEN
        FOR i = 0 TO num_fields - 1
            PRINT offset_to_string(offset_at_offset(row))
        NEXT
    END IF
LOOP UNTIL row = 0
mysql_free_result result

'*** Close the db ***
mysql_close conn

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #1 on: September 10, 2011, 10:44:58 AM »
What should I do with this?
I do not understand

Clippy

  • Hero Member
  • *****
  • Posts: 14408
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: MYSQL CLIENT for QB64
« Reply #2 on: September 10, 2011, 11:06:31 AM »
SQL Tutorial


http://www.mysql.com/
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

kidfrommars

  • Full Member
  • ***
  • Posts: 215
    • C & Fortran Polyglot
Re: MYSQL CLIENT for QB64
« Reply #3 on: September 10, 2011, 02:08:44 PM »
MySQL is a database manager. It is widely used on the internet with languages such as PHP.
This is a DECLARE LIBRARY library to allow access to MySQL databases.

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4227
  • QB Forever
    • Email
Re: MYSQL CLIENT for QB64
« Reply #4 on: September 11, 2011, 02:14:35 AM »
This works in Linux (Ubuntu) too with minimal changes:
1) Use the 'Synaptic Package Manager' to install 'mysql-client-5.1'
2) Change:
DECLARE DYNAMIC LIBRARY "mysql"
to
DECLARE DYNAMIC LIBRARY "mysqlclient:16.0.0" (or just copy this .so lib to your qb64 folder and rename it 'libmysql.so')

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #5 on: September 11, 2011, 04:21:19 AM »
I will try this .

But I dont know create this file  'mysql_helper.h' in qb64

Clippy

  • Hero Member
  • *****
  • Posts: 14408
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: MYSQL CLIENT for QB64
« Reply #6 on: September 11, 2011, 04:30:20 AM »
Open Notepad or other text editor and copy and paste in code below:
Code: [Select]
  void *offset_to_offset(void* offset){
   return offset;
   }
   void *offset_at_offset(void** offset){
   return *offset;
   }

Save As: mysql_helper.h

Save As type: All Files

H file must be in QB64 folder.

Then copy rest of code above into QB64 IDE and compile.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #7 on: September 11, 2011, 05:50:24 AM »
when I paste code in qb64 ,I have an error.


Error:

ALIAS can only be used with DECLARE LIBRARY on line 17

emery

  • Hero Member
  • *****
  • Posts: 565
    • Dhpos Self Checkout module
Re: MYSQL CLIENT for QB64
« Reply #8 on: September 11, 2011, 06:09:58 AM »
HELP --
mysql_free_result result
that posts what is in the tables, i need that to go into a vraible or string ...
Checkout my free selfcheckout module for dhpos at http://dhpos.midislandsnoblazers.ca/index.php

emery

  • Hero Member
  • *****
  • Posts: 565
    • Dhpos Self Checkout module
Re: MYSQL CLIENT for QB64
« Reply #9 on: September 11, 2011, 06:10:37 AM »
Quote from: REYBOCATA on September 11, 2011, 05:50:24 AM
when I paste code in qb64 ,I have an error.


Error:

ALIAS can only be used with DECLARE LIBRARY on line 17
if you have download everything you need, restart qb64
Checkout my free selfcheckout module for dhpos at http://dhpos.midislandsnoblazers.ca/index.php

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #10 on: September 11, 2011, 06:23:51 AM »
I have in folder qb64:

mysql.dll

and


mysql_helper.h

Reset qb64 and I have  the same error

emery

  • Hero Member
  • *****
  • Posts: 565
    • Dhpos Self Checkout module
Re: MYSQL CLIENT for QB64
« Reply #11 on: September 11, 2011, 06:24:58 AM »
are you on the current version of qb64? and if so, Triple check all the files
Checkout my free selfcheckout module for dhpos at http://dhpos.midislandsnoblazers.ca/index.php

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #12 on: September 11, 2011, 06:31:45 AM »
Ver 0.936

down: 0942

emery

  • Hero Member
  • *****
  • Posts: 565
    • Dhpos Self Checkout module
Re: MYSQL CLIENT for QB64
« Reply #13 on: September 11, 2011, 06:39:21 AM »
see  ;)
Checkout my free selfcheckout module for dhpos at http://dhpos.midislandsnoblazers.ca/index.php

REYBOCATA

  • Newbie
  • *
  • Posts: 31
    • Email
Re: MYSQL CLIENT for QB64
« Reply #14 on: September 11, 2011, 07:40:24 AM »
Create EXE.

and now ,I use it as in my program

  • Print