mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-20 02:48:56 +00:00

- All id attributes are now xml:id - Add docbook namespace to all root elements - Replace <ulink /> with <link xlink:href /> - Minor markup fixes here and there git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@238160 c90b9560-bf6c-de11-be94-00142212c4b1
223 lines
5.9 KiB
XML
223 lines
5.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.17 $ -->
|
|
<refentry xml:id="function.mysqli-change-user" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>mysqli_change_user</refname>
|
|
<refname>mysqli->change_user()</refname>
|
|
<refpurpose>Changes the user of the specified database connection</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<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>
|
|
Changes the user of the specified database connection and sets the current
|
|
database.
|
|
</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>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
&mysqli.link.description;
|
|
<varlistentry>
|
|
<term><parameter>user</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The MySQL user name.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>password</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The MySQL password.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>database</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The database to change to.
|
|
</para>
|
|
<para>
|
|
If desired, the &null; value may be passed 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>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<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 role="examples">
|
|
&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>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>mysqli_connect</function></member>
|
|
<member><function>mysqli_select_db</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</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
|
|
-->
|