public function connect() { require_once "connect.inc"; $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); var_dump($link); $link = mysqli_init(); /* @ is to suppress 'Property access is not allowed yet' */ @var_dump($link); $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("DROP TABLE IF EXISTS test_bug34810_table_1"); $mysql->query("CREATE TABLE test_bug34810_table_1 (a int not null)"); $mysql->query("SET sql_mode=''"); $mysql->query("INSERT INTO test_bug34810_table_1 VALUES (1),(2),(NULL)"); $warning = $mysql->get_warnings(); if (!$warning) { printf("[001] No warning!\n"); } if ($warning->errno == 1048 || $warning->errno == 1253) { /* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */ if ("HY000" != $warning->sqlstate) { printf("[003] Wrong sql state code: %s\n", $warning->sqlstate); } if ("" == $warning->message) { printf("[004] Message string must not be empty\n"); } } else { printf("[002] Empty error message!\n"); var_dump($warning); } }
<?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); } if (!is_null($tmp = @$mysqli->close($link))) { printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } $tmp = $mysqli->close(); if (true !== $tmp) { printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } if (!is_null($tmp = @$mysqli->close())) { printf("[004] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); } if (!is_null($tmp = @$mysqli->query("SELECT 1"))) { printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } print "done!";
$tmp = NULL; $link = NULL; // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test $mysqli = new mysqli(); $res = @new mysqli_result($mysqli); if (!is_null($tmp = @$res->fetch_assoc())) { printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (!is_null($tmp = @$res->fetch_assoc($link))) { printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = $mysqli->query("SELECT id, label FROM test ORDER BY id LIMIT 1"))) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[005]\n"; var_dump($res->fetch_assoc()); print "[006]\n"; var_dump($res->fetch_assoc()); $res->free_result(); if (!($res = $mysqli->query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e"))) { printf("[007] Cannot run query, [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[008]\n"; var_dump($res->fetch_assoc()); $res->free_result(); if (NULL !== ($tmp = $res->fetch_assoc())) { printf("[008] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
<?php require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("DROP TABLE IF EXISTS not_exists"); var_dump($mysql->warning_count); $w = $mysql->get_warnings(); var_dump($w->errno); var_dump($w->message); var_dump($w->sqlstate); $mysql->close(); echo "done!";
<?php /* 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); } if (!is_null($tmp = @$mysqli->character_set_name($link))) { printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = $mysqli->query('SELECT version() AS server_version'))) { printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $res->fetch_assoc(); $res->free_result(); $version = explode('.', $tmp['server_version']); if (empty($version)) { printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n"); } if ($version[0] <= 4 && $version[1] < 1) { printf("[007] Need MySQL Server 4.1+ for the test!\n"); } if (!($res = $mysqli->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))) { printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $res->fetch_assoc(); $res->free_result(); if (!$tmp['charset']) { printf("[009] Cannot determine current character set and collation\n");
<?php require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("CREATE TABLE temp (id INT UNSIGNED NOT NULL)"); $mysql->query("INSERT INTO temp (id) VALUES (3000000897),(3800001532),(3900002281),(3100059612)"); $stmt = $mysql->prepare("SELECT id FROM temp"); $stmt->execute(); $stmt->bind_result($id); while ($stmt->fetch()) { if (PHP_INT_SIZE == 8) { if (gettype($id) !== 'int' && gettype($id) != 'integer') { printf("[001] Expecting integer on 64bit got %s/%s\n", gettype($id), var_export($id, true)); } } else { if (gettype($id) !== 'string') { printf("[002] Expecting string on 32bit got %s/%s\n", gettype($id), var_export($id, true)); } if (version_compare(PHP_VERSION, '6.0', '==') == 1 && !is_unicode($id)) { printf("[003] Expecting unicode string\n"); } } print $id; print "\n"; } $stmt->close(); $mysql->query("DROP TABLE temp"); $mysql->close(); print "done!";
} /* it is undefined which pooled connection we get - thread ids may differ */ if (!($res = mysqli_query($link, "SELECT 'ok' AS it_works")) || !($row = mysqli_fetch_assoc($res))) { printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } var_dump($row); mysqli_free_result($res); 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); } if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, $port, $socket))) { printf("[009] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); } /* it is undefined which pooled connection we get - thread ids may differ */ if (!($res = $link->query("SELECT 'works also with oo' AS syntax")) || !($row = $res->fetch_assoc())) { printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } var_dump($row); mysqli_free_result($res); mysqli_close($link); if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket))) { printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); } if (!($link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))) { printf("[014] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (NULL !== ($tmp = $link->connect($host, $user, $passwd, $db, $port, $socket))) { printf("[015] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); } print "done!";
<?php require_once "connect.inc"; $tmp = NULL; $link = NULL; // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test $mysqli = new mysqli(); $res = @new mysqli_result($mysqli); $test_table_name = 'test_mysqli_fetch_assoc_oo_table_1'; require 'table.inc'; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (!($res = $mysqli->query("SELECT id, label FROM test_mysqli_fetch_assoc_oo_table_1 ORDER BY id LIMIT 1"))) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[005]\n"; var_dump($res->fetch_assoc()); print "[006]\n"; var_dump($res->fetch_assoc()); $res->free_result(); if (!($res = $mysqli->query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e"))) { printf("[007] Cannot run query, [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[008]\n"; var_dump($res->fetch_assoc()); $res->free_result(); if (NULL !== ($tmp = $res->fetch_assoc())) { printf("[008] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } mysqli_close($link);
<?php require 'connect.inc'; require 'table.inc'; $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysqli_result = $mysqli->query('SELECT * FROM test'); $row = $mysqli_result->fetch_row(); $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); $res = mysqli_query($link, 'SELECT * FROM test'); assert(mysqli_fetch_row($res) === $row); printf("Parent class:\n"); var_dump(get_parent_class($mysqli_result)); printf("\nMethods:\n"); $methods = get_class_methods($mysqli_result); $expected_methods = array('__construct' => true, 'close' => true, 'data_seek' => true, 'fetch_array' => true, 'fetch_assoc' => true, 'fetch_field' => true, 'fetch_field_direct' => true, 'fetch_fields' => true, 'fetch_object' => true, 'fetch_row' => true, 'field_seek' => true, 'free' => true, 'free_result' => true); if ($IS_MYSQLND) { $expected_methods['fetch_all'] = true; } foreach ($methods as $k => $method) { if (isset($expected_methods[$method])) { unset($expected_methods[$method]); unset($methods[$k]); } if ($method == 'mysqli_result') { // get_class_method reports different constructor names unset($expected_methods['__construct']); unset($methods[$k]); } } if (!empty($expected_methods)) { printf("Dumping list of missing methods.\n");
<?php require_once "connect.inc"; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[001] Cannot connect\n"); } require 'table.inc'; if (!($res = $mysqli->query("SELECT id, label FROM test ORDER BY id LIMIT 1"))) { printf("[002] [%d] %s\n", $mysqli->errno, $mysqli->error); } var_dump($res->lengths); while ($row = $res->fetch_assoc()) { var_dump($res->lengths); } var_dump($res->lengths); $res->free_result(); var_dump($res->lengths); $mysqli->close(); print "done!";
<?php $drop = <<<EOSQL DROP TABLE test_bug35103_table_1; DROP TABLE test_bug35103_table_2; EOSQL; require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("DROP TABLE IF EXISTS test_bug35103_table_1"); $mysql->query("CREATE TABLE test_bug35103_table_1 (a bigint(20) default NULL) ENGINE=MYISAM"); $mysql->query("INSERT INTO test_bug35103_table_1 VALUES (9223372036854775807),(-9223372036854775808),(-2147483648),(-2147483649),(-2147483647),(2147483647),(2147483648),(2147483649)"); $mysql->query("DROP TABLE IF EXISTS test_bug35103_table_2"); $mysql->query("CREATE TABLE test_bug35103_table_2 (a bigint(20) unsigned default NULL)"); $mysql->query("INSERT INTO test_bug35103_table_2 VALUES (18446744073709551615),(9223372036854775807),(9223372036854775808),(2147483647),(2147483649),(4294967295)"); $stmt = $mysql->prepare("SELECT a FROM test_bug35103_table_1 ORDER BY a"); $stmt->bind_result($v); $stmt->execute(); $i = 0; echo "BIG INT SIGNED, TEST\n"; while ($i++ < 8) { $stmt->fetch(); echo $v, "\n"; } $stmt->close(); echo str_repeat("-", 20), "\n"; $stmt = $mysql->prepare("SELECT a FROM test_bug35103_table_2 ORDER BY a"); $stmt->bind_result($v2); $stmt->execute(); $j = 0; echo "BIG INT UNSIGNED TEST\n"; while ($j++ < 6) {
<?php require_once "connect.inc"; $mysqli = new mysqli(); if (NULL !== ($tmp = @$mysqli->affected_rows)) { printf("[000a] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } 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); } if (0 !== ($tmp = $mysqli->affected_rows)) { printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query('DROP TABLE IF EXISTS test')) { printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!$mysqli->query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine)) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')")) { printf("[005] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (1 !== ($tmp = $mysqli->affected_rows)) { printf("[006] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); } // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented $mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')"); if (-1 !== ($tmp = $mysqli->affected_rows)) { printf("[007] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4")) {
} /* 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()); } $warning = new mysqli_warning($mysqli); if (false !== ($tmp = $warning->next())) { printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); } 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()); } if (!$mysqli->query("DROP TABLE IF EXISTS t1")) { printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } if (!$mysqli->query("CREATE TABLE t1 (a smallint)")) { printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } /* out of range, three warnings */ if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)")) { printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $warning = new mysqli_warning($mysqli); $i = 1; while ($warning->next() && '' != ($tmp = $warning->message)) { if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($tmp)) { printf("[033a] Warning should have been a unicode string, got %s/%s", gettype($tmp), $tmp); }
require 'connect.inc'; $warning = new mysqli_warning(); $warning = new mysqli_warning(null); $warning = new mysqli_warning(null, null); $mysqli = new mysqli(); $warning = new mysqli_warning($mysqli); $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $stmt = new mysqli_stmt($mysqli); $warning = new mysqli_warning($stmt); $stmt = $mysqli->stmt_init(); $warning = new mysqli_warning($stmt); $obj = new stdClass(); $warning = new mysqli_warning($obj); include "table.inc"; $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $res = $mysqli->query('INSERT INTO test(id, label) VALUES (1, "zz")'); $warning = mysqli_get_warnings($mysqli); printf("Parent class:\n"); var_dump(get_parent_class($warning)); printf("\nMethods:\n"); $methods = get_class_methods($warning); $expected_methods = array('next' => true); foreach ($methods as $k => $method) { if (isset($expected_methods[$method])) { unset($methods[$k]); unset($expected_methods[$method]); } } if (!empty($methods)) { printf("Dumping list of unexpected methods.\n"); var_dump($methods);
<?php require_once "connect.inc"; $tmp = NULL; $link = NULL; $mysqli = new mysqli(); if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } $test_table_name = 'test_mysqli_fetch_all_oo_table_1'; require 'table.inc'; if (!($res = $mysqli->query("SELECT * FROM test_mysqli_fetch_all_oo_table_1 ORDER BY id LIMIT 2"))) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[005]\n"; var_dump($res->fetch_all()); $res->free_result(); if (!($res = $mysqli->query("SELECT * FROM test_mysqli_fetch_all_oo_table_1 ORDER BY id LIMIT 2"))) { printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[007]\n"; var_dump($res->fetch_all(MYSQLI_NUM)); $res->free_result(); if (!($res = $mysqli->query("SELECT * FROM test_mysqli_fetch_all_oo_table_1 ORDER BY id LIMIT 2"))) { printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[008]\n"; var_dump($res->fetch_all(MYSQLI_BOTH)); $res->free_result(); if (!($res = $mysqli->query("SELECT * FROM test_mysqli_fetch_all_oo_table_1 ORDER BY id LIMIT 2"))) { printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
<?php require 'connect.inc'; $db = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $result = $db->query('SELECT 1', MYSQLI_USE_RESULT); $db->close(); var_dump($result->fetch_object());
<?php require_once "connect.inc"; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[001] Cannot connect\n"); } $test_table_name = 'test_mysqli_fetch_lengths_oo_table_1'; require 'table.inc'; if (!($res = $mysqli->query("SELECT id, label FROM test_mysqli_fetch_lengths_oo_table_1 ORDER BY id LIMIT 1"))) { printf("[002] [%d] %s\n", $mysqli->errno, $mysqli->error); } var_dump($res->lengths); while ($row = $res->fetch_assoc()) { var_dump($res->lengths); } var_dump($res->lengths); $res->free_result(); var_dump($res->lengths); $mysqli->close(); print "done!"; $test_table_name = 'test_mysqli_fetch_lengths_oo_table_1'; require_once "clean_table.inc"; $test_table_name = 'test_mysqli_fetch_lengths_oo_table_1'; require_once "clean_table.inc";
<?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); } if (!is_bool($tmp = $mysqli->autocommit(true))) { printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query('SET AUTOCOMMIT = 0')) { printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!($res = $mysqli->query('SELECT @@autocommit as auto_commit'))) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $res->fetch_assoc(); $res->free_result(); if ($tmp['auto_commit']) { printf("[005] Cannot turn off autocommit\n"); } if (true !== ($tmp = $mysqli->autocommit(true))) { printf("[006] Expecting true, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = $mysqli->query('SELECT @@autocommit as auto_commit'))) { printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $res->fetch_assoc(); $res->free_result(); if (!$tmp['auto_commit']) { printf("[008] Cannot turn on autocommit\n"); }
<?php require_once "connect.inc"; $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); var_dump($mysqli->autocommit(false)); $result = $mysqli->query("SELECT @@autocommit"); var_dump($result->fetch_row()); var_dump($mysqli->autocommit(true)); $result = $mysqli->query("SELECT @@autocommit"); var_dump($result->fetch_row());
<?php require_once "connect.inc"; set_error_handler('handle_catchable_fatal'); $tmp = NULL; $link = NULL; $mysqli = new mysqli(); $res = @new mysqli_result($mysqli); if (!is_null($tmp = @$res->fetch_object())) { printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (!($res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5"))) { printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!is_null($tmp = @$res->fetch_object($link))) { printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } try { if (!is_null($tmp = @$res->fetch_object($link, $link))) { printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } } catch (Error $e) { handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine()); } try { if (!is_null($tmp = @$res->fetch_object($link, $link, $link))) { printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
<?php require 'connect.inc'; $test_table_name = 'test_mysqli_class_mysqli_result_interface_table_1'; require 'table.inc'; $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysqli_result = $mysqli->query('SELECT * FROM test_mysqli_class_mysqli_result_interface_table_1'); $row = $mysqli_result->fetch_row(); $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); $res = mysqli_query($link, 'SELECT * FROM test_mysqli_class_mysqli_result_interface_table_1'); assert(mysqli_fetch_row($res) === $row); printf("Parent class:\n"); var_dump(get_parent_class($mysqli_result)); printf("\nMethods:\n"); $methods = get_class_methods($mysqli_result); $expected_methods = array('__construct' => true, 'close' => true, 'data_seek' => true, 'fetch_array' => true, 'fetch_assoc' => true, 'fetch_field' => true, 'fetch_field_direct' => true, 'fetch_fields' => true, 'fetch_object' => true, 'fetch_row' => true, 'field_seek' => true, 'free' => true, 'free_result' => true); if ($IS_MYSQLND) { $expected_methods['fetch_all'] = true; } foreach ($methods as $k => $method) { if (isset($expected_methods[$method])) { unset($expected_methods[$method]); unset($methods[$k]); } if ($method == 'mysqli_result') { // get_class_method reports different constructor names unset($expected_methods['__construct']); unset($methods[$k]); } } if (!empty($expected_methods)) {
$tmp = NULL; $link = NULL; $mysqli = new mysqli(); if (!is_null($tmp = @$mysqli->commit())) { printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); } 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); } if (true !== ($tmp = $mysqli->commit())) { printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); } if (true !== ($tmp = $mysqli->autocommit(false))) { printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query('DROP TABLE IF EXISTS test')) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) { printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $mysqli->commit(); if ($tmp !== true) { printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query('ROLLBACK')) { printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); }
include_once "connect.inc"; $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); } if (false !== ($tmp = $mysqli->change_user($user . '_unknown_really', $passwd . 'non_empty', $db))) { printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp); } if (false !== ($tmp = $mysqli->change_user($user, $passwd . '_unknown_really', $db))) { printf("[007] Expecting false, got %s/%s\n", gettype($tmp), $tmp); } if (false !== ($tmp = $mysqli->change_user($user, $passwd, $db . '_unknown_really'))) { printf("[008] Expecting false, got %s/%s\n", gettype($tmp), $tmp); } if (!$mysqli->query('SET @mysqli_change_user_test_var=1')) { printf("[009] Failed to set test variable: [%d] %s\n", $mysqli->errno, $mysqli->error); } if (!($res = $mysqli->query('SELECT @mysqli_change_user_test_var AS test_var'))) { printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error); } $tmp = $res->fetch_assoc(); $res->free_result(); if (1 != $tmp['test_var']) { printf("[011] Cannot set test variable\n"); } if (true !== ($tmp = $mysqli->change_user($user, $passwd, $db))) { printf("[012] Expecting true, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = $mysqli->query('SELECT database() AS dbname, user() AS user'))) { printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error);
<?php require_once "connect.inc"; $tmp = NULL; $link = NULL; $mysqli = new mysqli(); $res = @new mysqli_result($mysqli); $test_table_name = 'test_mysqli_fetch_field_direct_oo_table_1'; require 'table.inc'; if (!($mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))) { printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket); } if (!($res = $mysqli->query("SELECT id AS ID, label FROM test_mysqli_fetch_field_direct_oo_table_1 AS TEST ORDER BY id LIMIT 1"))) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } var_dump($res->fetch_field_direct(-1)); var_dump($res->fetch_field_direct(0)); var_dump($res->fetch_field_direct(2)); $res->free_result(); if (NULL !== ($tmp = $res->fetch_field_direct(0))) { printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } $mysqli->close(); print "done!"; $test_table_name = 'test_mysqli_fetch_field_direct_oo_table_1'; require_once "clean_table.inc";
<?php require_once "connect.inc"; $tmp = NULL; $link = NULL; require 'table.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); } if (!($res = $mysqli->query("SELECT * FROM test ORDER BY id LIMIT 5"))) { printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); } print "[005]\n"; var_dump($res->fetch_array()); print "[006]\n"; var_dump($res->fetch_array(MYSQLI_NUM)); print "[007]\n"; var_dump($res->fetch_array(MYSQLI_BOTH)); print "[008]\n"; var_dump($res->fetch_array(MYSQLI_ASSOC)); print "[009]\n"; var_dump($res->fetch_array()); $res->free_result(); if (!($res = $mysqli->query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e"))) { printf("[010] Cannot run query, [%d] %s\n", $mysqli->errno, ${$mysqli}->error); } print "[011]\n"; var_dump($res->fetch_array(MYSQLI_BOTH)); $res->free_result(); if (!($res = $mysqli->query("SELECT 1 AS a, 2 AS b, 3 AS c, 4 AS C"))) { printf("[012] Cannot run query, [%d] %s\n", $mysqli->errno, ${$mysqli}->error);
<?php require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("CREATE TABLE test_bug35517_table_1 (id INT UNSIGNED NOT NULL)"); $mysql->query("INSERT INTO test_bug35517_table_1 (id) VALUES (3000000897),(3800001532),(3900002281),(3100059612)"); $stmt = $mysql->prepare("SELECT id FROM test_bug35517_table_1"); $stmt->execute(); $stmt->bind_result($id); while ($stmt->fetch()) { if (PHP_INT_SIZE == 8) { if (gettype($id) !== 'int' && gettype($id) != 'integer') { printf("[001] Expecting integer on 64bit got %s/%s\n", gettype($id), var_export($id, true)); } } else { if (gettype($id) !== 'string') { printf("[002] Expecting string on 32bit got %s/%s\n", gettype($id), var_export($id, true)); } if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($id)) { printf("[003] Expecting unicode string\n"); } } print $id; print "\n"; } $stmt->close(); $mysql->query("DROP TABLE test_bug35517_table_1"); $mysql->close(); print "done!"; require_once "connect.inc"; if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
<?php require_once "connect.inc"; /*** test mysqli_connect 127.0.0.1 ***/ $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $mysql->query("DROP TABLE IF EXISTS test_066_table_1"); $mysql->query("CREATE TABLE test_066_table_1 (a int not null) ENGINE=myisam"); $mysql->query("INSERT INTO test_066_table_1 VALUES (1),(2),(NULL)"); if ($warning = $mysql->get_warnings()) { do { printf("Warning\n"); } while ($warning->next()); } $mysql->close(); print "done!"; require_once "connect.inc"; if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) { printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); } if (!mysqli_query($link, "DROP TABLE IF EXISTS test_066_table_1")) { printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } mysqli_close($link);