<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.3 $ --> <refentry id="function.maxdb-select-db"> <refnamediv> <refname>maxdb_select_db</refname> <refname>maxdb->select_db</refname> <refpurpose>Selects the default database for database queries</refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>bool</type><methodname>maxdb_select_db</methodname> <methodparam><type>resource</type><parameter>link</parameter></methodparam> <methodparam><type>string</type><parameter>dbname</parameter></methodparam> </methodsynopsis> <para> The <function>maxdb_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. </para> <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>maxdb_connect</function>. </para> </note> </refsect1> <refsect1> <title>Return values</title> <para> &return.success; </para> </refsect1> <refsect1> <title>See also</title> <para> <function>maxdb_connect</function> <function>maxdb_real_connect</function> </para> </refsect1> <refsect1> <title>Example</title> <example> <title>Object oriented style</title> <programlisting role="php"> <![CDATA[ <?php $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s\n", maxdb_connect_error()); exit(); } /* return name of current default database */ if ($result = $maxdb->query("SELECT SERVERDB FROM USERS WHERE USERNAME='MONA'")) { $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } /* change db to non existing db */ $maxdb->select_db("XXXXXXXX"); /* return name of current default database */ if ($result = $maxdb->query("SELECT SERVERDB FROM USERS WHERE USERNAME='MONA'")) { $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } $maxdb->close(); ?> ]]> </programlisting> </example> <example> <title>Procedural style</title> <programlisting role="php"> <![CDATA[ <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s\n", maxdb_connect_error()); exit(); } /* return name of current default database */ if ($result = maxdb_query($link, "SELECT SERVERDB FROM USERS WHERE USERNAME='MONA'")) { $row = maxdb_fetch_row($result); printf("Default database is %s.\n", $row[0]); maxdb_free_result($result); } /* change db to non existing db */ maxdb_select_db($link, "XXXXXXXX"); /* return name of current default database */ if ($result = maxdb_query($link, "SELECT SERVERDB FROM USERS WHERE USERNAME='MONA'")) { $row = maxdb_fetch_row($result); printf("Default database is %s.\n", $row[0]); maxdb_free_result($result); } maxdb_close($link); ?> ]]> </programlisting> </example> <para> The above examples would produce the following output: </para> <screen> <![CDATA[ Default database is <...>. Warning: maxdb_select_db(): -10709 Connection failed (RTE:database not running) <...> Warning: maxdb_query(): -10821 Session not connected [] <...> Warning: maxdb_close(): -10821 Session not connected [] <...> ]]> </screen> </refsect1> </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 -->