$link = NULL; if (NULL !== ($tmp = @mysql_list_processes($link, $link))) { printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!($res = mysql_list_processes($link))) { printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link)); } if (!($num = mysql_num_rows($res))) { printf("[003] Empty process list? [%d] %s\n", mysql_errno($link), mysql_error($link)); } $row = mysql_fetch_array($res, MYSQL_NUM); if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($row[0])) { printf("[004] Check for unicode support\n"); var_inspect($row); } mysql_free_result($res); if (!($res = mysql_list_processes())) { printf("[005] [%d] %s\n", mysql_errno(), mysql_error()); } if (!($num = mysql_num_rows($res))) { printf("[006] Empty process list? [%d] %s\n", mysql_errno(), mysql_error()); } $row = mysql_fetch_array($res, MYSQL_NUM); if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($row[0])) { printf("[007] Check for unicode support\n"); var_inspect($row); } mysql_free_result($res); mysql_close($link); print "done!\n";
printf("[002b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } if (!($link = my_mysql_connect($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); } $tmp = mysql_error($link); if (!is_string($tmp) || '' !== $tmp) { printf("[004] Expecting string/empty, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); } if (!mysql_query('DROP TABLE IF EXISTS test', $link)) { printf("[005] Failed to drop old test table: [%d] %s\n", mysql_errno($link), mysql_error($link)); } mysql_query('SELECT * FROM test', $link); $tmp = mysql_error($link); if (!is_string($tmp) || !preg_match("/Table '\\w*\\.test' doesn't exist/su", $tmp)) { printf("[006] Expecting string/[Table... doesn't exit], got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); } if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($tmp)) { printf("[007] Expecting Unicode error message!\n"); var_inspect($tmp); } mysql_close($link); var_dump(mysql_error($link)); if ($link = @mysql_connect($host . '_unknown', $user . '_unknown', $passwd, true)) { printf("[008] Can connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host . '_unknown', $user . '_unknown', $db, $port, $socket); } if ('' == mysql_error()) { printf("[009] Connect error should have been set\n"); } print "done!"; require_once "clean_table.inc";
if (!is_string($tmp = mysql_info($link)) || '' == $tmp) { printf("[008] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = mysql_query('ALTER TABLE test MODIFY label CHAR(2)', $link))) { printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link)); } if (!is_string($tmp = mysql_info($link)) || '' == $tmp) { printf("[010] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = mysql_query("UPDATE test SET label = 'b' WHERE id >= 100", $link))) { printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link)); } if (!is_string($tmp = mysql_info($link)) || '' == $tmp) { printf("[012] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); } if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($tmp)) { printf("[013] Expecting Unicode!\n"); var_inspect($info); } if (!is_string($def_tmp = mysql_info()) || '' == $def_tmp) { printf("[014] Expecting string/any_non_empty, got %s/%s\n", gettype($def_tmp), $def_tmp); } if ($def_tmp !== $tmp) { printf("[015] Results differ for default link and specified link, [%d] %s\n", mysql_errno(), mysql_error()); var_inspect($tmp); var_inspect($def_tmp); } // NOTE: no LOAD DATA INFILE test print "done!"; error_reporting(0); require_once "clean_table.inc";
<?php include_once "connect.inc"; $dbname = 'test'; $tmp = NULL; $link = NULL; if (!is_null($tmp = @mysql_stat($link))) { printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!is_null($tmp = @mysql_stat($link, "foo"))) { printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } if (!is_string($stat = mysql_stat($link)) || '' === $stat) { printf("[003] Expecting non empty string, got %s/'%s', [%d] %s\n", gettype($stat), $stat, mysql_errno($link), mysql_error($link)); } if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($stat)) { printf("[004] Expecting Unicode error message!\n"); var_inspect($stat); } if (!is_string($stat_def = mysql_stat()) || '' === $stat_def) { printf("[003] Expecting non empty string, got %s/'%s', [%d] %s\n", gettype($stat_def), $stat_def, mysql_errno(), mysql_error()); } assert(soundex($stat) === soundex($stat_def)); mysql_close($link); if (false !== ($tmp = mysql_stat($link))) { printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); } print "done!";
<?php include "connect.inc"; if (null !== ($tmp = @mysql_get_server_info(NULL))) { printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require "table.inc"; if (!is_string($info = mysql_get_server_info($link)) || '' === $info) { printf("[003] Expecting string/any_non_empty, got %s/%s\n", gettype($info), $info); } $def_info = mysql_get_server_info(); if ($def_info !== $info) { printf("[004] Server info for the default link and the specified link differ, [%d] %s\n", mysql_errno(), mysql_error()); var_dump($def_info); var_dump($info); } if (version_compare(PHP_VERSION, '5.9.9', '>') == 1 && !is_unicode($info)) { printf("[005] Expecting Unicode error message!\n"); var_inspect($info); } if (NULL !== ($tmp = @mysql_get_server_info('too many', 'just too many'))) { printf("[006] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); } print "done!";
<?php require_once "../../share/include/cherryphp"; echo var_inspect(new StdClass()) . "\n"; echo var_inspect("Hello World") . "\n"; echo var_inspect(177.944) . "\n"; echo var_inspect(['hello', 'world']) . "\n"; echo var_inspect(get_declared_classes()) . "\n"; echo var_inspect(true) . "\n"; echo var_inspect(null) . "\n";
printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); } require 'table.inc'; if (!($res = @mysql_list_dbs($link))) { printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link)); } if (!($num = mysql_num_rows($res))) { printf("[004] Empty database list? [%d] %s\n", mysql_errno($link), mysql_error($link)); } if (false !== ($tmp = mysql_db_name($res, -1))) { printf("[005] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); } if (false !== ($tmp = mysql_db_name($res, $num + 1))) { printf("[006] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); } $unicode = (bool) (version_compare(PHP_VERSION, '5.9.9', '>') == 1); for ($i = 0; $i < $num; $i++) { if ('' === ($dbname = mysql_db_name($res, $i))) { printf("[%03d] Got empty database name! [%d] %s\n", $i * 2 + 1 + 6, mysql_errno($link), mysql_error($link)); } if ($unicode && !is_unicode($dbname)) { printf("[%03d] Expecting unicode string! [%d] %s\n", $i * 2 + 2 + 6, mysql_errno($link), mysql_error($link)); var_inspect($dbname); } } mysql_free_result($res); if (false !== ($tmp = mysql_db_name($res, $num))) { printf("[999] Expecting boolean/false, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); } mysql_close($link); print "done!\n";
/** * @brief Inspect a variable, returning a printable string. */ function var_inspect($v, $omit_type = false, $expanded = false, $indent = 0) { $ind = str_repeat(" ", $indent); $suf = null; if (is_string($v)) { $v = addcslashes($v, "\f\n\r\t\v"); if (strlen($v) > 30) { $rep = substr($v, 0, 30) . html_entity_decode(" →", ENT_HTML5, "utf-8"); } else { $rep = $v; } if (!$omit_type) { $len = strlen($v); $suf = ":{$len}"; } $rep = "[0m\"" . ACOLOR_STRING . "{$rep}[0m\""; } elseif (is_bool($v)) { $rep = $v ? "TRUE" : "FALSE"; $rep = ACOLOR_BOOLEAN . "{$rep}"; } elseif (is_object($v)) { $rep = get_class($v); $vars = []; foreach ($v as $k => $vv) { $vars[] = ($expanded ? "\n{$ind} " : ' ') . "{$k}:" . var_inspect($vv, false, $expanded, $indent + 1); } if (!$expanded) { $vars = array_slice($vars, 0, 3); if (count($vars) > 0) { $vars[] = " ..."; } } $rep .= " {" . join($expanded ? '' : ',', $vars) . ($expanded ? "\n" : "") . "}"; } elseif (is_array($v)) { $vars = []; foreach ($v as $k => $vv) { $vars[] = ($expanded ? "\n{$ind} " : ' ') . "\"{$k}\"=> " . var_inspect($vv, false, $expanded, $indent + 1); } if (count($v) > 3) { $vars[] = '..'; } $len = count($v); if (!$expanded) { $vars = array_slice($vars, 0, 3); if (count($vars) > 0) { $vars[] = " ..."; } } $rep = "[" . join($expanded ? "" : ",", $vars) . ($expanded ? "\n" : "") . "{$ind}]"; $suf = "[{$len}]"; } elseif (is_double($v)) { $rep = $v; $rep = ACOLOR_DOUBLE . "{$rep}"; } elseif (is_integer($v)) { $rep = $v; $rep = ACOLOR_INTEGER . "{$rep}"; } elseif (is_null($v)) { $rep = 'NULL'; $rep = ACOLOR_NULL . "{$rep}"; } else { $rep = $v; $rep = ACOLOR_DEFAULT . "[1;36m{$rep}"; } if ($omit_type) { return $rep; } return sprintf("<[1;38m%s[0;38m%s[0m>[0m%s[0m", gettype($v), $suf, $rep); }