SQL Client

From QB64 Wiki
Revision as of 01:24, 25 January 2012 by imported>Clippy (Created page with ''''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. :* 1) Make…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

  • 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

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 con END


See also: DECLARE LIBRARY



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page