Previous Top Index Next

MySQL Database Functions

BRexx API for accessing MySQL databases. Prior to version 2.1.x the MySQL API was included as a compile option when compliling the interpreter. From version 2.1.x, MySQL can be compiled as static with the brexx program or as a shared library that has to be imported to the interpreter before use with the command CALL import "".


ends the connection to the MySQL server. Doesn't return anything
call dbclose


connects to a MySQL server. Returns "0" if ok, otherwise the error number. Use the dberror to find the error.
dbconnect('localhost','root','rootpsw','mysql') /* connect to the mysql db */
dbconnect('localhost',,,'test') /* open the test db */


Returns the error number for the most recently invoked MySQL function. "0" if everything is Ok. Use the option "A" to get the error message.
dberror() /* '0' */
dberror("A") /* 'Cannot connect...' */


Escapes special characters in a string for use in a SQL statement taking into account the current charset of the connection. Use this function when you want to manipulate BLOB fields or strings with non-ascii characters.

DBFIELD([num|name [,"N","T","K","L","M","U","A","F"]])

Returns information on the fields resulted from last query. With no options returns the number of fields returned (same as the DBINFO("F"). Indexing to a field can be down with the number or the name of the field.
Namename of the field (default)
Defaultdefault value of the field
Typetype of the field
Keyis the field the primary key
Lengthlength of field
Maxlengthmaximum allowable size of data for field
Nullif the field is defined as NOT NULL
Autoincrementis the field autoincrement
Flagsthe field flags
dbfield() /* 5 */
dbfield(1) /* Name */
dbfield('Name','T') /* String */
dbfield('Name','A') /* 0 */


return the value of the row row and col column number or name column name. Use the DBISNULL() to find out if the returned value is NULL.
dbget(2,5) /* 'hello' */
dbget(2,"Name") /* 'test' */


return "1" if the value of the row row and col column number or name column name is NULL.
dbisnull(2,5) /* 0 */
dbisnull(2,"Name") /* 1 */


returns information about the last operation. Number of Rows, the number of Fields, or the last autoincrement Insert id. Use the dbinfo("R") to return the number of affected rows from the last operation (like, delete, update ...). Use the dbinfo("F") to check if the last operation returned data.
dbinfo('R') /* 5 */
dbinfo('F') /* 10 */
dbinfo('I') /* 1023 */


Executes a SQL query specified as a sqlcmd string. Returns the number of affected rows.
dbsql('select * from test',2)
dbsql('insert into test set (name="Vasilis")')
dbsql('select last_insert_id()')

Previous Top Index Next