mysql_select_db(3) | MariaDB Connector/C | mysql_select_db(3) |
mysql_select_db - selects a database as default
#include <mysql.h> int mysql_select_db(MYSQL * mysql,
const char * db);
Selects a database as default. Returns zero on success, non-zero on failure
# switch to default database test USE test; # check default database SELECT DATABASE(); +------------+ | database() | +------------+ | test | +------------+
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);
if (rc)
return rc; /* Error */
if (strcmp("test", default_db) != NULL)
{
printf("Wrong default database\n");
return 1;
}
printf("Default database: %s", default_db);
return 0; }
Version 3.3.1 |