<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.14 $ --> <refentry id="function.mysqli-change-user"> <refnamediv> <refname>mysqli_change_user</refname> <refname>mysqli->change_user</refname> <refpurpose>Changes the user of the specified database connection</refpurpose> </refnamediv> <refsect1> <title>Description</title> <para>Procedural style:</para> <methodsynopsis> <type>bool</type><methodname>mysqli_change_user</methodname> <methodparam><type>mysqli</type><parameter>link</parameter></methodparam> <methodparam><type>string</type><parameter>user</parameter></methodparam> <methodparam><type>string</type><parameter>password</parameter></methodparam> <methodparam><type>string</type><parameter>database</parameter></methodparam> </methodsynopsis> <para>Object oriented style (method):</para> <classsynopsis> <ooclass><classname>mysqli</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>change_user</methodname> <methodparam><type>string</type><parameter>user</parameter></methodparam> <methodparam><type>string</type><parameter>password</parameter></methodparam> <methodparam><type>string</type><parameter>database</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <function>mysqli_change_user</function> is used to change the user of the specified database connection as given by the <parameter>link</parameter> parameter and to set the current database to that specified by the <parameter>database</parameter> parameter. </para> <para> If desired, the &null; value may be passed in place of the <parameter>database</parameter> parameter resulting in only changing the user and not selecting a database. To select a database in this case use the <function>mysqli_select_db</function> function. </para> <para> In order to successfully change users a valid <parameter>username</parameter> and <parameter>password</parameter> parameters must be provided and that user must have sufficient permissions to access the desired database. If for any reason authorization fails, the current user authentication will remain. </para> <note> <para> Using this command will always cause the current database connection to behave as if was a completely new database connection, regardless of if the operation was completed successfully. This reset includes performing a rollback on any active transactions, closing all temporary tables, and unlocking all locked tables. </para> </note> </refsect1> <refsect1> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1> &reftitle.seealso; <para> <function>mysqli_connect</function>&listendand; <function>mysqli_select_db</function>. </para> </refsect1> <refsect1> &reftitle.examples; <example> <title>Object oriented style</title> <programlisting role="php"> <![CDATA[ <?php /* connect database test */ $mysqli = new mysqli("localhost", "my_user", "my_password", "test"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* Set Variable a */ $mysqli->query("SET @a:=1"); /* reset all and select a new database */ $mysqli->change_user("my_user", "my_password", "world"); if ($result = $mysqli->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database: %s\n", $row[0]); $result->close(); } if ($result = $mysqli->query("SELECT @a")) { $row = $result->fetch_row(); if ($row[0] === NULL) { printf("Value of variable a is NULL\n"); } $result->close(); } /* close connection */ $mysqli->close(); ?> ]]> </programlisting> </example> <example> <title>Procedural style</title> <programlisting role="php"> <![CDATA[ <?php /* connect database test */ $link = mysqli_connect("localhost", "my_user", "my_password", "test"); /* check connection */ if (!$link) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* Set Variable a */ mysqli_query($link, "SET @a:=1"); /* reset all and select a new database */ mysqli_change_user($link, "my_user", "my_password", "world"); if ($result = mysqli_query($link, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); printf("Default database: %s\n", $row[0]); mysqli_free_result($result); } if ($result = mysqli_query($link, "SELECT @a")) { $row = mysqli_fetch_row($result); if ($row[0] === NULL) { printf("Value of variable a is NULL\n"); } mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?> ]]> </programlisting> </example> &example.outputs; <screen> <![CDATA[ Default database: world Value of variable a is NULL ]]> </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 -->