'---- download mysql.dll from http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/mysql.dll (~2MB) ----
'MYSQL *mysql_init(MYSQL *mysql)
'const char *mysql_error(MYSQL *mysql)
' Returns a string that represents the client library version
' const char *mysql_get_client_info(void)
' MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag)
' The value of host may be either a host name or an IP address. If host is NULL or the string "localhost", a connection to the local host is assumed.
' db is the database name. If db is not NULL, the connection sets the default database to this value.
' If port is not 0, the value is used as the port number for the TCP/IP connection. Note that the host parameter determines the type of the connection.
' If unix_socket is not NULL, the string specifies the socket or named pipe to use. Note that the host parameter determines the type of the connection.
' The value of client_flag is usually 0, but can be set to a combination of the following flags to enable certain features.
' Return Value: A MYSQL* connection handle if the connection was successful, NULL if the connection was unsuccessful. For a successful connection, the return value is the same as the value of the first parameter.
'*** REMEMBER, ALL STRINGS PASSED MUST BE NULL '+CHR$(0)' TERMINATED ***
' int mysql_query(MYSQL *mysql, const char *stmt_str)
' Executes the SQL statement pointed to by the null-terminated string stmt_str. Normally, the string must consist of a single SQL statement without a terminating semicolon (%u201C;%u201D) or \g. If multiple-statement execution has been enabled,
'Returns Zero if the statement was successful. Nonzero if an error occurred.
'*** REMEMBER, ALL STRINGS PASSED MUST BE NULL '+CHR$(0)' TERMINATED ***
' MYSQL_RES *mysql_store_result(MYSQL *mysql)
' Returns a RESULT STRUCTURE
' unsigned int mysql_num_fields(MYSQL_RES *result)
' To pass a MYSQL* argument instead, use unsigned int mysql_field_count(MYSQL *mysql).
' Returns number of columns in result set
' my_ulonglong mysql_num_rows(MYSQL_RES *result)
' Returns the number of rows in the result set.
' MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)
' RETURNS A ROW STRUCTURE
' unsigned long *mysql_fetch_lengths(MYSQL_RES *result)
' Returns the lengths of the columns of the current row within a result set.
' Returns a pointer to an array of lengths
'--Example to search for a data in a database called `books' that has the database table 'book' whidt fields: 'id', 'title', 'publisher' and 'author'
my_server$ = "127.0.0.1"
my_user$ = "root"
my_key$ = "12345"
bdatos$ = "books"
port = 0
conn = mysql_init(0)
'------ Open Database
conexion = mysql_real_connect(conn, my_server$, my_user$, my_key$, bdatos$, port, 0, 0)
'-- Search for Shakespeare books
'-- Any SQL command could be used
busclave$
= "SELECT * FROM book WHERE author = 'Shakespeare'" + CHR$(0)CALL basedato
(busclave$
, rows
, columns
) LOCATE 10, 10:
PRINT " I can't find any book by that author ";
PRINT "Shakespeare's Books" PRINT "Title :"; DB_RESULT
(2, n
) PRINT "Publisher:"; DB_RESULT
(3, n
)
'----------------------------------------------------------- MYSQL -----------------------------------------------------------
SUB basedato
(busclave$
, rows
, columns
) '*** Hacer busqueda en la tabla ***
errf = mysql_query(conn, busclave$)
'DIM columns AS LONG
result = mysql_store_result(conn)
'DIM row AS _OFFSET
'DIM dato AS _OFFSET
columns = mysql_num_fields(result)
rows = mysql_num_rows(result)
'*** Guardar en Array ***
mysql_row = mysql_fetch_row(result)
mem_mysql_row
= _MEM(mysql_row
, columns
* LEN(an_offset%&
)) 'The upper limit is unknown at this point mysql_lengths = mysql_fetch_lengths(result)
mem_mysql_lengths
= _MEM(mysql_lengths
, columns
* 4) FOR campos
= 1 TO columns
mem_field
= _MEM(_MEMGET(mem_mysql_row
, mem_mysql_row.OFFSET
+ (campos
- 1) * LEN(an_offset%&
), _OFFSET), length
) DB_RESULT
(campos
, filas
) = SPACE$(length
) _MEMGET mem_field
, mem_field.OFFSET
, DB_RESULT
(campos
, filas
) mysql_free_result result