mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Tidy up new my_mysqli in tests
This commit is contained in:
@@ -10,8 +10,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
<?php
|
||||
require_once 'connect.inc';
|
||||
|
||||
if (!$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
|
||||
$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!mysqli_query($mysql, "SET sql_mode=''"))
|
||||
printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));
|
||||
|
||||
@@ -67,12 +67,22 @@
|
||||
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
|
||||
$flags = ($enable_env_flags) ? get_environment_connection_flags() : 0;
|
||||
|
||||
// Because the tests are meant to test both error modes, they can set the report_mode to a different value,
|
||||
// which we do not want to override. However, we want to make sure that if a connection cannot be made,
|
||||
// the constuctor will throw an exception. We store current report_mode in variable and restore it later.
|
||||
$driver = new mysqli_driver;
|
||||
$report_mode = $driver->report_mode;
|
||||
$driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
|
||||
|
||||
if ($flags !== 0) {
|
||||
parent::__construct();
|
||||
$this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags);
|
||||
} else {
|
||||
parent::__construct($host, $user, $passwd, $db, $port, $socket);
|
||||
}
|
||||
|
||||
// Restore error mode
|
||||
$driver->report_mode = $report_mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@ mysqli
|
||||
echo $exception->getMessage() . "\n";
|
||||
}
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (0 !== ($tmp = $mysqli->affected_rows))
|
||||
printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
@@ -17,10 +17,7 @@ mysqli
|
||||
<?php
|
||||
require_once 'connect.inc';
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!is_bool($tmp = $mysqli->autocommit(true)))
|
||||
printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
@@ -18,9 +18,7 @@ if (mysqli_get_server_version($link) >= 50600)
|
||||
$link = NULL;
|
||||
$tmp = NULL;
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db)))
|
||||
printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
|
||||
@@ -32,9 +30,7 @@ if (mysqli_get_server_version($link) >= 50600)
|
||||
printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
// Reconnect because after 3 failed change_user attempts, the server blocks you off.
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$mysqli->query('SET @mysqli_change_user_test_var=1'))
|
||||
printf("[009] Failed to set test variable: [%d] %s\n", $mysqli->errno, $mysqli->error);
|
||||
|
||||
@@ -11,12 +11,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
/* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
|
||||
require_once 'connect.inc';
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$res = $mysqli->query('SELECT version() AS server_version'))
|
||||
printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
|
||||
|
||||
@@ -10,12 +10,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
<?php
|
||||
require_once 'connect.inc';
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
$tmp = $mysqli->close();
|
||||
if (true !== $tmp)
|
||||
|
||||
@@ -15,9 +15,6 @@ if (!have_innodb($link))
|
||||
<?php
|
||||
require_once 'connect.inc';
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
$mysqli = new mysqli();
|
||||
try {
|
||||
$mysqli->commit();
|
||||
@@ -25,10 +22,7 @@ if (!have_innodb($link))
|
||||
echo $exception->getMessage() . "\n";
|
||||
}
|
||||
|
||||
if (!$mysqli = new my_mysqli($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 = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (true !== ($tmp = $mysqli->commit())) {
|
||||
printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
@@ -35,9 +35,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$host, $user, $db, $port, $socket);
|
||||
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$thread_id = $link->thread_id)
|
||||
printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
@@ -83,8 +83,7 @@ if (!$TEST_EXPERIMENTAL)
|
||||
mysqli_close($link);
|
||||
|
||||
|
||||
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
|
||||
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
|
||||
printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
@@ -101,8 +100,7 @@ if (!$TEST_EXPERIMENTAL)
|
||||
printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
/* Yes, I really want to check if the object property is empty */
|
||||
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
|
||||
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
$warning = new mysqli_warning($mysqli);
|
||||
if (false !== ($tmp = $warning->next()))
|
||||
@@ -111,8 +109,7 @@ if (!$TEST_EXPERIMENTAL)
|
||||
if ('' != ($tmp = $warning->message))
|
||||
printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
|
||||
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
|
||||
printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
@@ -41,9 +41,7 @@ mysqli.max_links=-1
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$link = new my_mysqli($phost, $user, $passwd, $db, $port, $socket))
|
||||
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$phost, $user, $db, $port, $socket);
|
||||
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$thread_id = $link->thread_id)
|
||||
printf("[008] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
@@ -103,9 +101,7 @@ mysqli.max_links=-1
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$link = new my_mysqli($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);
|
||||
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (!$thread_id = $link->thread_id)
|
||||
printf("[023] Cannot determine thread id, test will fail, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
|
||||
|
||||
@@ -34,10 +34,7 @@ mysqli.max_links=-1
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[007] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$host, $user, $db, $port, $socket);
|
||||
|
||||
$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket)))
|
||||
printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
@@ -20,9 +20,7 @@ require_once 'skipifconnectfailure.inc';
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
|
||||
printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
|
||||
$host, $user, $db, $port, $socket);
|
||||
$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
|
||||
|
||||
if (false !== ($tmp = $mysqli->prepare(false)))
|
||||
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
|
||||
|
||||
Reference in New Issue
Block a user