Contact: zeng  @  zegraph.com      Last update: August 2014

MySQL Library

This library implements some basic functions of the MySQL client library.

Function Parameter Type Remark
mysql() string Returns a MySQL client object.
.version()   Returns version information as string.
.connect(host, user, password[, dbname]) strings Connects to a database in a host. Returns null if successful or an error string otherwise.
.query(sql) string Performs SQL query. Returns an error string if failed; returns the number of rows if the query produce any results; and returns null otherwise.
.fetch()   Returns the next record as string or array depending on whether a record has one or more items. It returns null when all records are fetched.
.data(ptr, n[, flag]) user, integer Fetches all query results, converts them to double floating numbers, and put them into the doubel array ptr of size n. Returns the number of data converted. If the optional flag is set to true, it assumes that the first string in a row represent date and converts the string to Julian date number.
.print()   Display query reuslts.
.escape(s) string Returns a legal SQL string that can be used in an SQL statement. It must be called after calling the connect function
.escape(ptr, n) user, integer Create a legal SQL string that can be used in an SQL statement. The ptr object may contains any binary data and n must correctly represent the number of byte in ptr. It must be called after calling the connect function

Example

load("mysql.dll");

sql = mysql();
ret = sql.connect(IP, "user", "password");

ret = sql.query("USE test");
if (isstring(ret)) csv(ret);

ret = sql.query("CREATE TABLE pet4 (name VARCHAR(20), owner VARCHAR(20), " +
                 "species VARCHAR(20), sex CHAR(1), birth DATE, death DATE)");

if (isstring(ret)) csv(ret);

ret = sql.query("SHOW TABLES");
if (isstring(ret)) csv(ret);
sql.fetch(true);

ret = sql.query("DESCRIBE pet");
if (isstring(ret)) csv(ret);
sql.fetch(true);