FreeBSD manual
download PDF document: mysql_select_db.3.pdf
mysql_select_db(3) MariaDB Connector/C mysql_select_db(3)
Name
mysql_select_db - selects a database as default
Synopsis
#include <mysql.h>
int mysql_select_db(MYSQL * mysql,
const char * db);
Description
Selects a database as default. Returns zero on success, non-zero on
failure
Parameters
o mysql is a connection identifier, which was previously allocated by
mysql_init(3) and connected by mysql_real_connect(3).
o db - the default database name
Notes
o To retrieve the name of the default database either execute the SQL
command SELECT DATABASE() or retrieve the value via
mariadb_get_infov(3) API function.
o The default database can also be set by the db parameter in
mysql_real_connect(3).
Examples
SQL
# switch to default database test
USE test;
# check default database
SELECT DATABASE();
+------------+
| database() |
+------------+
| test |
+------------+
MariadDB Connector/C
static int set_default_db(MYSQL *mysql)
{
int rc;
char *default_db;
/* change default database to test */
rc= mysql_select_db(mysql, "test");
if (rc)
return rc; /* Error */
/* get the default database */
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &default_db);
}
printf("Default database: %s", default_db);
return 0;
}
See also
mysql_real_connect(3)
Version 3.3.1 mysql_select_db(3)