libstd/mysql
Bindings to the MySQL/MariaDB client library plus helpers to connect, run statements, read result sets and escape values. On Linux it is libmariadb.so; on Windows libmariadb.dll, from MariaDB Connector/C or the lib folder of a MariaDB installation. It is not a system DLL: its folder must be on PATH to compile and to run the program.
#include <libstd/mysql>
Includes libstd/stdio. Links the shared library libmariadb.so, libmariadb.dll (FFI).
Example
#include <libstd/mysql>
conn = mysql_connect_or_die("127.0.0.1", "root", "", 0 as str, MYSQL_DEFAULT_PORT)
mysql_query_w(conn, "CREATE DATABASE IF NOT EXISTS demo")
mysql_query_w(conn, "USE demo")
mysql_query_w(conn, "CREATE TABLE IF NOT EXISTS Users(id INT, nome VARCHAR(50))")
mysql_query_w(conn, "INSERT INTO Users VALUES(1, '" + mysql_escape(conn, "Al'ice") + "')")
res = mysql_query_result(conn, "SELECT id, nome FROM Users ORDER BY id")
mysql_print_result(res) // one row per line, fields separated by " | "
mysql_free_result(res)
mysql_close(conn)
Constants
| Name | Value | Meaning |
|---|---|---|
MYSQL_DEFAULT_PORT | 3306 |
Functions
Allocates a connection handle.
Connects to a server.
Closes a connection.
Checks that the connection is alive.
Client library version.
Server version.
Runs an SQL statement; 0 on success.
Last error message.
Last error code.
Rows affected by the last statement.
Auto-increment id of the last insert.
Escapes a string for use inside a query.
Fetches the whole result set to the client.
Streams the result set row by row.
Frees a result set.
Rows in a stored result.
Columns in a result.
Columns of the last statement.
The next row (an array of C strings), or null.
Lengths of the fields of the current row.
The next column definition.
If response is not 0, prints mysql_error, closes the connection and exits.
mysql_init + mysql_real_connect, exiting with a clear message on failure. Pass 0 as str as db to select none.Runs a statement without a result set, with automatic error checking.
Runs a SELECT and returns its stored result set (all rows fetched to the client).
1 if field index of a row is SQL NULL.
Field index of a row as a string (NULL becomes "").
Name of the next column (the library advances an internal cursor): call it mysql_num_fields times in a row.
A copy of value with SQL special characters escaped, ready to be concatenated into a query.
Prints a whole result set, one row per line.