1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/vendor/MDBC/man/mysql_select_db.3

85 lines
1.8 KiB
Groff
Raw Normal View History

.\" Automatically generated by Pandoc 2.5
.\"
.TH "mysql_select_db" "3" "" "Version 3.2.2" "MariaDB Connector/C"
.hy
.SS Name
.PP
mysql_select_db \- selects a database as default
.SS Synopsis
.IP
.nf
\f[C]
#include <mysql.h>
int mysql_select_db(MYSQL * mysql,
const char * db);
\f[R]
.fi
.SS Description
.PP
Selects a database as default.
Returns zero on success, non\-zero on failure
.SS Parameters
.IP \[bu] 2
\f[C]mysql\f[R] is a connection identifier, which was previously
allocated by \f[B]mysql_init(3)\f[R] and connected by
\f[B]mysql_real_connect(3)\f[R].
.IP \[bu] 2
\f[C]db\f[R] \- the default database name
.SS Notes
.IP \[bu] 2
To retrieve the name of the default database either execute the SQL
command \f[C]SELECT DATABASE()\f[R] or retrieve the value via
\f[B]mariadb_get_infov(3)\f[R] API function.
.IP \[bu] 2
The default database can also be set by the db parameter in
\f[B]mysql_real_connect(3)\f[R].
.SS Examples
.SS SQL
.IP
.nf
\f[C]
# switch to default database test
USE test;
# check default database
SELECT DATABASE();
+\-\-\-\-\-\-\-\-\-\-\-\-+
| database() |
+\-\-\-\-\-\-\-\-\-\-\-\-+
| test |
+\-\-\-\-\-\-\-\-\-\-\-\-+
\f[R]
.fi
.SS MariadDB Connector/C
.IP
.nf
\f[C]
static int set_default_db(MYSQL *mysql)
{
int rc;
char *default_db;
/* change default database to test */
rc= mysql_select_db(mysql, \[dq]test\[dq]);
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(\[dq]test\[dq], default_db) != NULL)
{
printf(\[dq]Wrong default database\[rs]n\[dq]);
return 1;
}
printf(\[dq]Default database: %s\[dq], default_db);
return 0;
}
\f[R]
.fi
.SS See also
.PP
\f[B]mysql_real_connect(3)\f[R]