MySQL Library
The Z-Script interpreter with embedded MySQL (myzs.exe) may be used to process database without server setup. To use embedded MySQL, the base and data directories must be set properly in "my.ini" in the current directory or in the file whose name will be passed to mysql(fname) function. Also, you should copy the share directory of a MySQL distribution to the base directory so that MySQL can find charactersets and error messages defined there.
The client library "mysql.dl"l needs to be loaded when MySQL is not embedded in Z-Script.
| Function | Parameter Type | Remark |
| mysql([fname]) | string | Creates a MySQL client object. For embedded MySQL, an optional file name (with full path) my be given for initializing MySQL client/server; and if omitted, the file name is assumed to be "my.ini" in the current directory. |
| .version() | Returns version information as string. | |
| .connect(host, user, password[, dbname]) | strings | Connects to a database on a host. Returns null if successful or error message otherwise. Note that for embedded MySQL, this function is not available. |
| .query(sql) | string | Performs SQL query. Returns error string if unsuccessful; 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) | 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. |
| .print() | Display query reuslts. | |
| .escape(s) | string | Create a legal SQL string that can be used in an SQL statement. It must be called after calling connect(...). |
| .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 connect(...). |
Client 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);
Emedded Example
sql = mysql();
ret = sql.query("USE test");
if (isstring(ret)) {
csv(ret);
return;
}
ret = sql.query("DESCRIBE pet");
if (isstring(ret)) {
csv(ret);
return;
}
sql.fetch(true);
if (isstring(ret)) {
csv(ret);
return;
}
ret = sql.query("DESCRIBE pet");
if (isstring(ret)) {
csv(ret);
return;
}
sql.fetch(true);
