2003-03-15 23:01:35 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-11-12 14:01:04 +00:00
|
|
|
<!-- $Revision: 1.9 $ -->
|
2003-03-15 23:01:35 +00:00
|
|
|
<refentry id="function.mysqli-select-db">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>mysqli_select_db</refname>
|
2004-01-28 23:18:42 +00:00
|
|
|
<refname>mysqli->select_db</refname>
|
2003-05-25 02:04:10 +00:00
|
|
|
<refpurpose>Selects the default database for database queries</refpurpose>
|
2003-03-15 23:01:35 +00:00
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
2003-05-24 01:29:22 +00:00
|
|
|
<type>bool</type><methodname>mysqli_select_db</methodname>
|
2004-11-12 14:01:04 +00:00
|
|
|
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
|
2003-05-25 02:04:10 +00:00
|
|
|
<methodparam><type>string</type><parameter>dbname</parameter></methodparam>
|
2003-03-15 23:01:35 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2003-05-18 23:40:46 +00:00
|
|
|
The <function>mysqli_select_db</function> function selects the default
|
|
|
|
database (specified by the <parameter>dbname</parameter> parameter) to be
|
|
|
|
used when performing queries against the database connection
|
|
|
|
represented by the <parameter>link</parameter> parameter.
|
2003-03-15 23:01:35 +00:00
|
|
|
</para>
|
2004-01-28 23:18:42 +00:00
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
This function should only be used to change the default database for the connection.
|
|
|
|
You can select the default database with 4th parameter in <function>mysqli_connect</function>.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
2004-10-31 16:05:14 +00:00
|
|
|
&reftitle.returnvalues;
|
2003-05-18 23:40:46 +00:00
|
|
|
<para>
|
2003-05-24 01:29:22 +00:00
|
|
|
&return.success;
|
2003-05-23 23:58:23 +00:00
|
|
|
</para>
|
2003-03-15 23:01:35 +00:00
|
|
|
</refsect1>
|
2004-01-28 23:18:42 +00:00
|
|
|
<refsect1>
|
2004-10-31 16:05:14 +00:00
|
|
|
&reftitle.seealso;
|
2004-01-28 23:18:42 +00:00
|
|
|
<para>
|
2004-10-31 16:05:14 +00:00
|
|
|
<function>mysqli_connect</function>&listendand;
|
|
|
|
<function>mysqli_real_connect</function>.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2004-02-26 18:32:30 +00:00
|
|
|
<refsect1>
|
2004-10-31 16:05:14 +00:00
|
|
|
&reftitle.examples;
|
2004-02-26 18:32:30 +00:00
|
|
|
<example>
|
|
|
|
<title>Object oriented style</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
|
|
|
|
|
|
|
|
/* check connection */
|
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return name of current default database */
|
|
|
|
if ($result = $mysqli->query("SELECT DATABASE()")) {
|
|
|
|
$row = $result->fetch_row();
|
|
|
|
printf("Default database is %s.\n", $row[0]);
|
|
|
|
$result->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change db to world db */
|
|
|
|
$mysqli->select_db("world");
|
|
|
|
|
|
|
|
/* return name of current default database */
|
|
|
|
if ($result = $mysqli->query("SELECT DATABASE()")) {
|
|
|
|
$row = $result->fetch_row();
|
|
|
|
printf("Default database is %s.\n", $row[0]);
|
|
|
|
$result->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
$mysqli->close();
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<example>
|
|
|
|
<title>Procedural style</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
|
|
|
|
|
|
|
|
/* check connection */
|
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return name of current default database */
|
|
|
|
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
|
|
|
|
$row = mysqli_fetch_row($result);
|
|
|
|
printf("Default database is %s.\n", $row[0]);
|
|
|
|
mysqli_free_result($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change db to world db */
|
|
|
|
mysqli_select_db($link, "world");
|
|
|
|
|
|
|
|
/* return name of current default database */
|
|
|
|
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
|
|
|
|
$row = mysqli_fetch_row($result);
|
|
|
|
printf("Default database is %s.\n", $row[0]);
|
|
|
|
mysqli_free_result($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
mysqli_close($link);
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
2004-10-31 16:05:14 +00:00
|
|
|
&example.outputs;
|
2004-02-26 18:32:30 +00:00
|
|
|
<screen>
|
|
|
|
<![CDATA[
|
|
|
|
Default database is test.
|
|
|
|
Default database is world.
|
|
|
|
]]>
|
|
|
|
</screen>
|
|
|
|
</refsect1>
|
2003-03-15 23:01:35 +00:00
|
|
|
</refentry>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|