GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
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

mysql is a connection identifier, which was previously allocated by mysql_init(3) and connected by mysql_real_connect(3).
db - the default database name

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.
The default database can also be set by the db parameter in mysql_real_connect(3).


# 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;
}

    

mysql_real_connect(3)
Version 3.2.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.