<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.maxdb-change-user">
 <refnamediv>
  <refname>maxdb_change_user</refname>
  <refname>maxdb::change_user</refname>
  <refpurpose>Changes the user of the specified database connection</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <para>&style.procedural;</para>
  <methodsynopsis>
   <type>bool</type><methodname>maxdb_change_user</methodname>
   <methodparam><type>resource</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>&style.oop;</para>
  <methodsynopsis>
   <type>bool</type><methodname>maxdb::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>
  <para>
   <function>maxdb_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>
   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 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
   <example>
    <title>&style.oop;</title>
    <programlisting role="php">
<![CDATA[
<?php

/* connect database test */
$maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB");

/* check connection */
if (maxdb_connect_errno()) {
   printf("Connect failed: %s\n", maxdb_connect_error());
   exit();
}

if ($result = $maxdb->query("SELECT * FROM dual")) {
   $row = $result->fetch_row();
   printf("Result: %s\n", $row[0]);
   $result->free();
}

/* reset all and select a new database */
if (!$maxdb->change_user("DBADMIN", "SECRET", "DEMODB")) {
  printf("Database not running\n");
} else {
  printf("Database running\n");
}

/* close connection */
$maxdb->close();
?>
]]>
    </programlisting>
   </example>
   <example>
    <title>&style.procedural;</title>
    <programlisting role="php">
<![CDATA[
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");

/* check connection */
if (!$link) {
   printf("Connect failed: %s\n", maxdb_connect_error());
   exit();
}

if ($result = maxdb_query($link, "SELECT * FROM dual")) {
   $row = maxdb_fetch_row($result);
   printf("Result: %s\n", $row[0]);
   maxdb_free_result($result);
}

/* reset all and select a new database */
if (!maxdb_change_user($link, "DBADMIN", "SECRET", "DEMODB")) {
  printf("Database not running\n");
} else {
  printf("Database running\n");
}

/* close connection */
maxdb_close($link);
?>
]]>
   </programlisting>
  </example>
  &example.outputs.similar;
  <screen>
<![CDATA[
Result: a
Database running
]]>
  </screen>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>maxdb_connect</function></member>
    <member><function>maxdb_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:"~/.phpdoc/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
-->