Go to the first, previous, next, last section, table of contents.


MySQL C API

The C API is distributed with MySQL. It is included in the libmysqlclinet library. It allows C programs to access a database.

Most of the other client APIs (all except Java) use this library to connect. So for example you can use the same environment variables.

The client has a maximum communication buffer size. This is automatically increased up to the maximum size (the default for this is 512Kb). As buffers are increased (but not decreased until close) on demand, it will not take any resources if one increases this. This size check is mostly a check for erroneous queries and communication packets.

The communication buffer must be big enough to contain a single SQL statement and one row of returned data (but of course not at the same time). Each thread's communication buffer is dynamically enlarged to handle any row or query up to the imposed limit.

So if you have BLOBs that contains data up to 16M you must have at least 16M as your communication buffer limit. See section How does one change the size of MySQL buffers?.

MySQL shrinks each communication buffer to net_buffer_length after each query.

mysql_affected_rows Retrieves the number of affected rows by the last UPDATE, DELETE or INSERT.
mysql_close Closes a server connection.
mysql_connect Establish a connection to a MySQL server.
mysql_create_db Create a database.
mysql_data_seek Seeks to an arbitrary row in a query result set.
mysql_drop_db Drop a database.
mysql_eof Determine if last row has been read.
mysql_escape_string Escape a string for a SQL statement. See section Literals. How do you write strings and numbers?
mysql_error The error message from last MySQL function.
mysql_fetch_field Find out what type a table field is.
mysql_fetch_lengths Returns the length of all columns in a query result set.
mysql_fetch_row Fetch the 'next' row in the query result.
mysql_field_seek Put the column cursor on column number field.
mysql_free_result Free memory used to store a query result.
mysql_get_client_info Return version information for the current client library.
mysql_get_host_info Returns name of server host.
mysql_get_proto_info Get protocol version used by connection.
mysql_get_server_info Returns the version number of the server.
mysql_insert_id Returns ID generated for a AUTO_INCREMENT field.
mysql_list_dbs Return matching database names.
mysql_list_fields Return matching field names.
mysql_list_processes Get a list of the current server threads.
mysql_list_tables Return matching table names.
mysql_num_fields Return the number of columns in a result set.
mysql_num_rows Returns the number of rows in result set.
mysql_query Executes a SQL query.
mysql_real_query Executes a SQL query with length information.
mysql_reload Reload the user permissions table in the server.
mysql_select_db Connect to a database.
mysql_shutdown Shut down the database server.
mysql_stat Return server status in a string.
mysql_store_result Reads a result set to the client.
mysql_use_result Initiate a dynamic result set for each row. This uses much less memory than mysql_store_result() but will put more strain on the server.
int mysql_affected_rows(MYSQL *mysql)
Retrieves the number of affected rows by the last UPDATE, DELETE or INSERT.
void mysql_close(MYSQL *mysql)
Closes a server connection.
MYSQL *mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd)
Establish a connection to a MySQL server.
int mysql_create_db(MYSQL *mysql, const char *db)
Create a database.
void mysql_data_seek(MYSQL_RES *res, uint offset)
Seeks to an arbitrary row in a query result set.
int mysql_drop_db(MYSQL *mysql, const char *db)
Drop a database.
int mysql_eof(MYSQL_RES *)
Determine if last row has been read.
char *mysql_error(MYSQL *mysql)
The error message from last MySQL function.
uint mysql_escape_string(char *to,char *from,uint length)
Escape a string for a SQL statement.
MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *handle)
Find out what type a table field is. When querying for the length of a BLOB without retreving a result, MySQL returns the 'default blob length', which is 8192, when doing a select on the table. When one retrevies a result, column_object->max_length contains the real max_length for the specific query. The 8192 size is chosen because MySQL doesn't know the max length for the BLOB. This should be made configurable sometime.
unsigned int *mysql_fetch_lengths(MYSQL_RES *mysql)
Returns the length of all columns in a query result set.
MYSQL_ROW mysql_fetch_row(MYSQL_RES *mysql)
Fetch the 'next' row in the query result.
void mysql_field_seek(MYSQL_RES *result, int field)
Put the column cursor on column number field.
void mysql_free_result(MYSQL_RES *result)
Free memory used to store a query result. Must be called after you are finished with a result set..
char *mysql_get_client_info(void)
Return version information for the current client library.
char *mysql_get_host_info(MYSQL *mysql)
Returns name of server host.
int mysql_get_proto_info(MYSQL *mysql)
Get protocol version used by connection.
char *mysql_get_server_info(MYSQL *mysql)
Returns the version number of the server.
unsigned long mysql_insert_id(MYSQL *mysql)
Returns ID generated for AUTO_INCREMENT field. As the API returns a unsigned long one can't use this with BIGINT columns. In this case one has to use the LAST_INSERT_ID() SQL function.
MYSQL_RES *mysql_list_dbs(MYSQL *mysql, const char *wild)
Return matching database names.
MYSQL_RES *mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
Return matching field names.
MYSQL_RES *mysql_list_processes(MYSQL *mysql)
Get a list of the current server threads.
MYSQL_RES *mysql_list_tables(MYSQL *mysql, const char *wild)
Return matching table names.
int mysql_num_fields(MYSQL_RES *result)
Return the number of columns in a result set.
int mysql_num_rows(MYSQL_RES *result)
Returns the number of rows in result set.
int mysql_query(MYSQL *mysql, const char *query)
Executes a SQL query.
int mysql_real_query(MYSQL *mysql, const char *query, uint length)
Executes a SQL query with length information.
int mysql_reload(MYSQL *mysql)
Reload the user permissions table in the server.
int mysql_select_db(MYSQL *mysql, const char *db)
Connect to a database.
int mysql_shutdown(MYSQL *mysql)
Shut down the database server.
char *mysql_stat(MYSQL *mysql)
Return server status in a string.
MYSQL_RES *mysql_store_result(MYSQL *mysql)
Reads a result set to the client.
MYSQL_RES *mysql_use_result(MYSQL *mysql)
Initiate a dynamic result set for each row.


Go to the first, previous, next, last section, table of contents.