Documentation Home
MySQL PHP API
Download this Manual
PDF (US Ltr) - 2.8Mb
PDF (A4) - 2.8Mb
EPUB - 456.7Kb
HTML Download (TGZ) - 396.1Kb
HTML Download (Zip) - 409.9Kb


MySQL PHP API  /  ...  /  MysqlndUhConnection::changeUser

9.7.1 MysqlndUhConnection::changeUser

Copyright 1997-2014 the PHP Documentation Group.

  • MysqlndUhConnection::changeUser

    Changes the user of the specified mysqlnd database connection

Description

public bool MysqlndUhConnection::changeUser(mysqlnd_connection connection,
                                            string user,
                                            string password,
                                            string database,
                                            bool silent,
                                            int passwd_len);

Changes the user of the specified mysqlnd database connection

Parameters

connection

Mysqlnd connection handle. Do not modify!

user

The MySQL user name.

password

The MySQL password.

database

The MySQL database to change to.

silent

Controls if mysqlnd is allowed to emit errors or not.

passwd_len

Length of the MySQL password.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 9.9 MysqlndUhConnection::changeUser example


<?php
class proxy extends MysqlndUhConnection {
 /* Hook mysqlnd's connection::change_user call */
 public function changeUser($res, $user, $passwd, $db, $silent, $passwd_len) {
   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));
   $ret = parent::changeUser($res, $user, $passwd, $db, $silent, $passwd_len);
   printf("%s returns %s\n", __METHOD__, var_export($ret, true));
   return $ret;
 }
}
/* Install proxy/hooks to be used with all future mysqlnd connection */
mysqlnd_uh_set_connection_proxy(new proxy());

/* Create mysqli connection which is using the mysqlnd library */
$mysqli = new mysqli("localhost", "root", "", "test");

/* Example of a user API call which triggers the hooked mysqlnd call */
var_dump($mysqli->change_user("root", "bar", "test"));
?>

    

The above example will output:


proxy::changeUser(array (
  0 => NULL,
  1 => 'root',
  2 => 'bar',
  3 => 'test',
  4 => false,
  5 => 3,
))
proxy::changeUser returns false
bool(false)



See Also

mysqlnd_uh_set_connection_proxy
mysqli_change_user


User Comments
Sign Up Login You must be logged in to post a comment.