Exemple #1
0
 public function change_user($user, $password)
 {
     $this->check();
     $this->user = $user;
     $this->password = $password;
     if (!@mysqli_change_user($user, $password)) {
         elog(LWARNING, "Error in DB Change User user: {$user}, MySql Error: " . mysqli_error($this->db));
         return false;
     }
     return true;
 }
}
mysqli_free_result($res);
$num = $row['_num'];
assert($num > 0);
if (!($res = mysqli_query($link, 'DELETE FROM test'))) {
    printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!($res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))) {
    printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!($row = mysqli_fetch_assoc($res))) {
    printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
if (0 != $row['_num']) {
    printf("[007] Rows should have been deleted in this transaction\n");
}
// DELETE should be rolled back
mysqli_change_user($link, $user, $passwd, $db);
if (!($res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))) {
    printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!($row = mysqli_fetch_assoc($res))) {
    printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if ($row['_num'] != $num) {
    printf("[010] Expecting %d rows in the table test, found %d rows\n", $num, $row['_num']);
}
mysqli_free_result($res);
mysqli_close($link);
print "done!";
Exemple #3
0
 function changeUser($Username, $Password)
 {
     if (!strcmp($Username, $this->Username) or !strcmp($Password, $this->Password)) {
         mysqli_change_user($Username, $Password, $Name, $this->Handle) or trigger_error(__CLASS__ . "::" . __FUNCTION__ . "() mysqli_change_user() failed: " . mysqli_error(), E_USER_ERROR);
         $this->Username = $Username;
         $this->Password = $Password;
     }
 }
<?php

require_once "connect.inc";
$tmp = NULL;
$link = NULL;
require 'table.inc';
/*
Internal macro MYSQL_REPORT_ERROR
*/
mysqli_report(MYSQLI_REPORT_ERROR);
mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db);
mysqli_report(MYSQLI_REPORT_OFF);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
print "done!";
 public function changeUser($user, $password, $database = NULL)
 {
     /*
        Works only if the MySQLi extension is enabled, because
        mysql_change_user() is not avaliable in PHP >3.
     */
     if (TRUE == $this->usemysqli) {
         return mysqli_change_user($this->link, $user, $password, $database);
     } else {
         return FALSE;
     }
 }
<?php

require_once "connect.inc";
$tmp = NULL;
$link = NULL;
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
/* Pre 5.6: link remains useable */
if (false !== ($tmp = @mysqli_change_user($link, $user . '_unknown_really', $passwd . 'non_empty', $db))) {
    printf("[002] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
}
if (!($res = mysqli_query($link, 'SELECT 1 AS _one'))) {
    printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
var_dump($res->fetch_assoc());
print "done!";
    printf("[019] Test variable is still set!\n");
}
mysqli_close($link);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[020] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
if (false !== ($tmp = mysqli_change_user($link, str_repeat('user', 16384), str_repeat('pass', 16384), str_repeat('dbase', 16384)))) {
    printf("[021] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
/* silent protocol change if no db which requires workaround in mysqlnd/libmysql
   (empty db = no db send with COM_CHANGE_USER) */
if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, ""))) {
    printf("[023] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
}
if (!($res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user'))) {
    printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if ($tmp['dbname'] != "") {
    printf("[025] Expecting database '', got database() '%s'\n", $tmp['dbname']);
}
mysqli_close($link);
if (NULL !== ($tmp = @mysqli_change_user($link, $user, $passwd, $db))) {
    printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
print "done!";
Exemple #8
0
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if (NULL !== $tmp['test_var']) {
    printf("[019] Test variable is still set!\n");
}
mysqli_close($link);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[020] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
if (false !== ($tmp = mysqli_change_user($link, str_repeat('user', 16384), str_repeat('pass', 16384), str_repeat('dbase', 16384)))) {
    printf("[021] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[022] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
/* silent protocol change if no db which requires workaround in mysqlnd/libmysql
   (empty db = no db send with COM_CHANGE_USER) */
if (true !== ($tmp = mysqli_change_user($link, $user, $passwd, ""))) {
    printf("[023] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
}
if (!($res = mysqli_query($link, 'SELECT database() AS dbname, user() AS user'))) {
    printf("[024] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
$tmp = mysqli_fetch_assoc($res);
mysqli_free_result($res);
if ($tmp['dbname'] != "") {
    printf("[025] Expecting database '', got database() '%s'\n", $tmp['dbname']);
}
mysqli_close($link);
print "done!";
Exemple #9
0
 function mysql_change_user($user, $passwd, $database = NULL, $link = NULL)
 {
     $link = mysql_resolve_link($link);
     return mysqli_change_user($link, $user, $passwd, $database);
 }