uw Wed Oct 10 10:55:52 2007 UTC Modified files: /php-src/ext/mysql/tests mysql_max_links.phpt mysql_max_persistent.phpt mysql_pconn_disable.phpt mysql_pconn_kill.phpt mysql_pconn_max_links.phpt mysql_pconn_reuse.phpt mysql_query_load_data_openbasedir.phpt mysql_sql_safe_mode.phpt mysql_trace_mode.phpt mysql_pconnect.phpt Log: Adding tests to ext/mysql in HEAD = synching with 5_3
http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_max_links.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_max_links.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_max_links.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_max_links.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,69 @@ +--TEST-- +mysql_[p]connect() - max_links/max_persistent +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--INI-- +mysql.max_links=2 +--FILE-- +<?php +require_once('connect.inc'); + +function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) { + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + $link = mysql_connect($host, $user, $passwd, true); + + if (!$link) { + printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", + $offset, $host, $user, $passwd, + mysql_errno(), mysql_error()); + return false; + } + + return $link; +} + +$links = array(); + +// try to open 3 links +$links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket); +$links[1] = my_connect(20, $host, $user, $passwd, $db, $port, $socket); +$links[2] = my_connect(30, $host, $user, $passwd, $db, $port, $socket); +if (false !== $links[2]) + printf("[040] Last connection should not have been allowed!\n"); + +// free some links but let index 1 remain +unset($links[2]); +mysql_close($links[0]); +unset($links[0]); + +// should be allowed -> second open connection +$links[0] = my_connect(50, $host, $user, $passwd, $db, $port, $socket); +$links[2] = my_connect(60, $host, $user, $passwd, $db, $port, $socket); +ksort($links); +var_dump($links); + +mysql_close($links[0]); +mysql_close($links[1]); +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[030] Cannot connect using host '%s', user '%s', password '****', [0] 0 + +Warning: mysql_connect(): Too many open links (2) in %s on line %s +[060] Cannot connect using host '%s', user '%s', password '****', [0] 0 +array(3) { + [0]=> + resource(%d) of type (mysql link) + [1]=> + resource(%d) of type (mysql link) + [2]=> + bool(false) +} +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_max_persistent.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_max_persistent.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_max_persistent.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_max_persistent.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,90 @@ +--TEST-- +mysql_[p]connect() - max_links/max_persistent +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('connect.inc'); + +$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket); +if (!$link) + die("skip Cannot connect to MySQL"); + +mysql_close($link); + +mysqli_query('DROP USER pcontest', $link); +if (!mysql_query('CREATE USER pcontest IDENTIFIED BY "pcontest"', $link)) { + printf("skip Cannot create second DB user [%d] %s", mysql_errno($link), mysql_error($link)); + mysql_close($link); + die(); +} + +// we might be able to specify the host using CURRENT_USER(), but... +if (!mysql_query(sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db), $link)) { + printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysql_errno($link), mysql_error($link)); + mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); + mysql_query('DROP USER pcontest', $link); + mysql_close($link); + die(); +} +mysql_close($link); +?> +--INI-- +mysql.max_links=2 +mysql.allow_persistent=1 +mysql.max_persistent=1 +--FILE-- +<?php +require_once('connect.inc'); + +function my_connect($offset, $host, $user, $passwd, $db, $port, $socket) { + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + + $link = mysql_pconnect($host, $user, $passwd); + if (!$link) { + printf("[%03d] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", + $offset, $host, $user, $passwd, + mysql_errno(), mysql_error()); + return false; + } + + if (!mysql_select_db($db, $link)) + return false; + + return $link; +} + +$links = array(); + +// try to open 2 links +$links[0] = my_connect(10, $host, $user, $passwd, $db, $port, $socket); +$links[1] = my_connect(20, $host, 'pcontest', 'pcontest', $db, $port, $socket); +if (false !== $links[1]) + printf("[030] Last connection should not have been allowed!\n"); + +// free some links but let index 1 remain +unset($links[1]); +mysql_close($links[0]); +unset($links[0]); + +// should be allowed -> only open connection +$links[0] = my_connect(40, $host, $user, $passwd, $db, $port, $socket); +var_dump($links); + +mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $links[0]); +mysql_query('DROP USER pcontest', $links[0]); + +mysql_close($links[0]); +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_pconnect(): Too many open persistent links (1) in %s on line %d +[020] Cannot connect using host '%s', user '%s', password '****', [0] 0 +array(1) { + [0]=> + resource(%d) of type (mysql link persistent) +} +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_pconn_disable.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_pconn_disable.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_pconn_disable.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_pconn_disable.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,58 @@ +--TEST-- +mysql_pconnect() - disabling feature +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysql.allow_persistent=0 +mysql.max_persistent=1 +mysql.max_links=2 +--FILE-- +<?php + require_once("connect.inc"); + require_once("table.inc"); + // assert(ini_get('mysql.allow_persistent') == false); + + if ($socket) + $myhost = sprintf("%s:%s", $host, $socket); + else if ($port) + $myhost = sprintf("%s:%s", $host, $port); + else + $myhost = $host; + + if (($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[001] Can connect to the server.\n"); + + if (($res = @mysql_query('SELECT id FROM test ORDER BY id ASC', $plink)) && + ($row = mysql_fetch_assoc($res)) && + (mysql_free_result($res))) { + printf("[002] Can fetch data using persistent connection! Data = '%s'\n", + $row['id']); + } + + $thread_id = mysql_thread_id($plink); + mysql_close($plink); + + if (!($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[003] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error()); + + if (mysql_thread_id($plink) != $thread_id) + printf("[004] Looks like the second call to pconnect() did not give us the same connection.\n"); + + $thread_id = mysql_thread_id($plink); + mysql_close($plink); + + if (!($plink = mysql_connect($myhost, $user, $passwd, true))) + printf("[005] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error()); + + if (mysql_thread_id($plink) == $thread_id) + printf("[006] Looks like connect() did not return a new connection.\n"); + + print "done!"; +?> +--EXPECTF-- +[001] Can connect to the server. +[002] Can fetch data using persistent connection! Data = '1' +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_pconn_kill.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_pconn_kill.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_pconn_kill.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_pconn_kill.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,106 @@ +--TEST-- +mysql_pconnect() - killing persitent connection +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysql.allow_persistent=1 +mysql.max_persistent=2 +--FILE-- +<?php + include "connect.inc"; + include "table.inc"; + + if ($socket) + $myhost = sprintf("%s:%s", $host, $socket); + else if ($port) + $myhost = sprintf("%s:%s", $host, $port); + else + $myhost = $host; + + if (!($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $myhost, $user, $db, $port, $socket); + mysql_select_db($db, $plink); + + $pthread_id = mysql_thread_id($plink); + $thread_id = mysql_thread_id($link); + + if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link))) + printf("[002] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + $processlist = array(); + while ($row = mysql_fetch_assoc($res)) + $processlist[$row['Id']] = $row; + mysql_free_result($res); + + if (!isset($processlist[$thread_id])) + printf("[003] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link)); + if (!isset($processlist[$pthread_id])) + printf("[004] Cannot find persistent connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + if (!mysql_query(sprintf("KILL %d", $pthread_id), $link)) + printf("[005] Cannot kill persistent connection thread, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + while (1) { + if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link))) + printf("[006] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + $processlist2 = array(); + while ($row = mysql_fetch_assoc($res)) + $processlist2[$row['Id']] = $row; + mysql_free_result($res); + if (isset($processlist2[$pthread_id])) { + sleep(1); + } else { + break; + } + } + + if (!isset($processlist2[$thread_id])) + printf("[007] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + mysql_close($plink); + + if (!($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error()); + mysql_select_db($db, $plink); + + if (!($res = mysql_query("SELECT 1", $plink))) + printf("[010] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink)); + mysql_free_result($res); + + var_dump(mysql_ping($plink)); + + if (!($res = mysql_query("SELECT 1", $plink))) + printf("[011] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink)); + mysql_free_result($res); + + if (!($link2 = mysql_connect($myhost, $user, $passwd, true))) + printf("[012] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $myhost, $user, $db, $port, $socket); + mysql_select_db($db, $link2); + if (!mysql_query(sprintf("KILL %d", $thread_id), $link2)) + printf("[013] Cannot kill regular connection thread, [%d] %s\n", mysql_errno($link2), mysql_error($link2)); + + if (!($link = mysql_connect($myhost, $user, $passwd, true))) + printf("[014] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $myhost, $user, $db, $port, $socket); + mysql_select_db($db, $link); + if (!($res = mysql_query("SELECT * FROM test", $link))) + printf("[015] Cannot run query on new regular connection, [%d] %s\n", @mysql_errno($link), @mysql_error($link)); + + if (!($res = mysql_query("SELECT * FROM test", $link2))) + printf("[016] Cannot run query on other regular connection, [%d] %s\n", @mysql_errno($link2), @mysql_error($link2)); + + mysql_free_result($res); + mysql_close($plink); + mysql_close($link); + mysql_close($link2); + print "done!"; +?> +--EXPECTF-- +bool(true) +done! http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_pconn_max_links.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_pconn_max_links.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_pconn_max_links.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_pconn_max_links.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,169 @@ +--TEST-- +Persistent connections and mysql.max_persistent +--SKIPIF-- +<?php + require_once('skipif.inc'); + require_once('skipifconnectfailure.inc'); + require_once('connect.inc'); + + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + // we need a second DB user to test for a possible flaw in the ext/mysql[i] code + if (!$link = mysql_connect($host, $user, $passwd, true)) + die(sprintf("skip Cannot connect [%d] %s", mysql_errno(), mysql_error())); + + if (!mysql_select_db($db, $link)) + die(sprintf("skip [%d] %s", mysql_errno($link), mysql_error($link))); + + mysql_query('DROP USER pcontest', $link); + if (!mysql_query('CREATE USER pcontest IDENTIFIED BY "pcontest"', $link)) { + printf("skip Cannot create second DB user [%d] %s", mysql_errno($link), mysql_error($link)); + mysql_close($link); + die(); + } + + // we might be able to specify the host using CURRENT_USER(), but... + if (!mysql_query(sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db), $link)) { + printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysql_errno($link), mysql_error($link)); + mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); + mysql_query('DROP USER pcontest', $link); + mysql_close($link); + die(); + } + mysql_close($link); +?> +--INI-- +mysql.max_links=2 +mysql.max_persistent=1 +mysql.allow_persistent=1 +--FILE-- +<?php + require_once("connect.inc"); + require_once('table.inc'); + + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + if (!$plink = mysql_pconnect($host, 'pcontest', 'pcontest')) + printf("[001] Cannot connect using the second DB user created during SKIPIF, [%d] %s\n", + mysql_errno(), mysql_error()); + + if (!mysql_select_db($db, $plink)) + printf("[002] [%d] %s\n", mysql_errno($plink), mysql_error($plink)); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + $phpinfo = substr($phpinfo, strpos($phpinfo, 'MySQL Support => enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[003] Cannot get # active persistent links from phpinfo()"); + $num_plinks = $matches[1]; + + if (!$res = mysql_query('SELECT id, label FROM test WHERE id = 1', $plink)) + printf("[004] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + + if (!$row = mysql_fetch_assoc($res)) + printf("[005] Cannot run fetch result, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + mysql_free_result($res); + var_dump($row); + + // change the password for the second DB user and kill the persistent connection + if (!mysql_query('SET PASSWORD FOR pcontest = PASSWORD("newpass")', $link)) + printf("[006] Cannot change PW of second DB user, [%d] %s\n", mysql_errno($link), mysql_error($link)); + + // persistent connections cannot be closed but only be killed + $pthread_id = mysql_thread_id($plink); + if (!mysql_query(sprintf('KILL %d', $pthread_id), $link)) + printf("[007] Cannot KILL persistent connection of second DB user, [%d] %s\n", mysql_errno($link), mysql_error($link)); + // give the server a second to really kill the thread + sleep(1); + + if (!$res = mysql_query("SHOW FULL PROCESSLIST", $link)) + printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link)); + + $running_threads = array(); + while ($row = mysql_fetch_assoc($res)) + $running_threads[$row['Id']] = $row; + mysql_free_result($res); + + if (isset($running_threads[$pthread_id])) + printf("[009] Persistent connection has not been killed"); + + // we might get the old handle + if ($plink = @mysql_pconnect($host, 'pcontest', 'pcontest')) + printf("[010] Can connect using the old password, [%d] %s\n", + mysql_errno(), mysql_error()); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + $phpinfo = substr($phpinfo, strpos($phpinfo, 'MySQL Support => enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[011] Cannot get # active persistent links from phpinfo()"); + + $num_plinks_kill = $matches[1]; + if ($num_plinks_kill >= $num_plinks) + printf("[012] Statistics seems to be wrong, got %d active persistent links, expecting < %d links", + $num_plinks_kill, $num_plinks); + + // The first connection has been closed, the last pconnect() was unable to connect -> no connection open + // We must be able to connect because max_persistent limit has not been reached + if (!$plink = mysql_pconnect($host, 'pcontest', 'newpass')) + printf("[013] Cannot connect using the second DB, [%d] %s\n", + mysql_errno(), mysql_error()); + + if (!mysql_select_db($db, $plink)) + printf("[014] [%d] %s\n", mysql_errno($plink), mysql_error($plink)); + + if (!$res = mysql_query('SELECT id, label FROM test WHERE id = 1', $plink)) + printf("[015] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + + if (!$row = mysql_fetch_assoc($res)) + printf("[016] Cannot run fetch result, [%d] %s\n", + mysql_errno($plink), mysql_error($plink)); + mysql_free_result($res); + var_dump($row); + + mysql_query('REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest', $link); + mysql_query('DROP USER pcontest', $link); + mysql_close($link); + print "done!"; +?> +--EXPECTF-- +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +done! +--UEXPECTF-- +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +done! http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_pconn_reuse.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_pconn_reuse.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_pconn_reuse.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_pconn_reuse.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,66 @@ +--TEST-- +mysql_pconnect() - disabling feature +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysql.allow_persistent=1 +mysql.max_persistent=1 +mysql.max_links=2 +--FILE-- +<?php + require_once("connect.inc"); + require_once("table.inc"); + mysql_close($link); + + if ($socket) + $myhost = sprintf("%s:%s", $host, $socket); + else if ($port) + $myhost = sprintf("%s:%s", $host, $port); + else + $myhost = $host; + + if (($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[001] Can connect to the server.\n"); + + if ((mysql_select_db($db, $plink)) && + ($res = mysql_query('SELECT id FROM test', $plink)) && + ($row = mysql_fetch_assoc($res)) && + (mysql_free_result($res))) { + printf("[002] Can fetch data using persistent connection! Data = '%s'\n", + $row['id']); + } else { + printf("[002] [%d] %s\n", mysql_errno($plink), mysql_error($plink)); + } + + $thread_id = mysql_thread_id($plink); + mysql_close($plink); + + if (!($plink = mysql_pconnect($myhost, $user, $passwd))) + printf("[003] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error()); + + if (mysql_thread_id($plink) != $thread_id) + printf("[004] Looks like the second call to pconnect() did not give us the same connection.\n"); + + $thread_id = mysql_thread_id($plink); + mysql_close($plink); + + if (!($plink = mysql_connect($myhost, $user, $passwd, true))) + printf("[005] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error()); + + if (mysql_thread_id($plink) == $thread_id) + printf("[006] Looks like connect() did not return a new connection.\n"); + + if (($link = mysql_connect($myhost, $user, $passwd, true))) + printf("[007] Can connect although limit has been reached, [%d] %s\n", mysql_errno(), mysql_error()); + + print "done!"; +?> +--EXPECTF-- +[001] Can connect to the server. +[002] Can fetch data using persistent connection! Data = '1' + +Warning: mysql_connect(): Too many open links (2) in %s on line %d +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,108 @@ +--TEST-- +LOAD DATA INFILE - open_basedir +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); + +if (file_exists('./simple.csv') && !unlink('./simple.csv')) + die("skip Cannot remove previous CSV file"); + +if (!$fp = fopen('./simple.csv', 'w')) + die("skip Cannot create test CSV file"); + +flose($fp); [EMAIL PROTECTED]('./simple.csv'); +?> +--INI-- +safe_mode=0 +open_basedir="." +--FILE-- +<?php [EMAIL PROTECTED]("connect.inc"); +if (!isset($db)) { + // run-tests, I love you for not allowing me to set ini settings dynamically + print "[006] [1148] The used command is not allowed with this MySQL version +[007] [0] +[008] LOAD DATA not run? +[010] [1148] The used command is not allowed with this MySQL version +done!"; + die(); +} +require('table.inc'); +mysql_close($link); +if ($socket) + $host = sprintf("%s:%s", $host, $socket); +else if ($port) + $host = sprintf("%s:%s", $host, $port); + +if (!$link = mysql_connect($host, $user, $passwd, true, 128)) { + printf("[001] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n", + $host, $user, $passwd, + mysql_errno(), mysql_error()); +} + +if (!mysql_select_db($db, $link)) { + printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} + +if (file_exists('./simple.csv')) + unlink('./simple.csv'); + +if (!$fp = fopen('./simple.csv', 'w')) + printf("[003] Cannot open CSV file\n"); + +if (ini_get('unicode.semantics')) { + if (!fwrite($fp, (binary)"'97';'x';\n") || + !fwrite($fp, (binary)"'98';'y';\n") || + !fwrite($fp, (binary)"99;'z';\n")) { + printf("[004] Cannot write CVS file '%s'\n", $file); + } +} else { + if (!fwrite($fp, "97;'x';\n") || + !fwrite($fp, "98;'y';\n") || + !fwrite($fp, "99;'z';\n")) { + printf("[005] Cannot write CVS file '%s'\n", $file); + } +} +fclose($fp); + +$sql = sprintf("LOAD DATA LOCAL INFILE '%s' + INTO TABLE test + FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' + LINES TERMINATED BY '\n'", + mysql_real_escape_string(realpath('./simple.csv'), $link)); + +if (!mysql_query($sql, $link)) + printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!($res = mysql_query('SELECT label FROM test WHERE id = 97', $link)) || + !($row = mysql_fetch_assoc($res)) || + !mysql_free_result($res)) + printf("[007] [%d] '%s'\n", mysql_errno($link), mysql_error($link)); + +if ($row['label'] != "x") + printf("[008] LOAD DATA not run?\n"); + +if (!mysql_query('DELETE FROM test', $link)) + printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +$sql = "LOAD DATA LOCAL INFILE '/tmp/idonotexist' + INTO TABLE test + FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' + LINES TERMINATED BY '\n'"; + +if (!mysql_query($sql, $link)) + printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +mysql_close($link); +unlink("./simple.csv"); + +print "done!"; +?> +--EXPECTF-- +[006] [1148] %s +[007] [0] '' +[008] LOAD DATA not run? +[010] [1148] %s +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_sql_safe_mode.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_sql_safe_mode.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_sql_safe_mode.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_sql_safe_mode.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,39 @@ +--TEST-- +mysql_[p]connect() - safe_mode +--SKIPIF-- +<?php +require_once('skipif.inc'); +$link = @mysql_connect("", "", "", true); +if ($link) + die("skip Test cannot be run if annonymous connections are allowed"); +?> +--INI-- +sql.safe_mode=1 +--FILE-- +<?php +require_once('connect.inc'); +if ($socket) + $host = sprintf("%s:%s", $host, $socket); +else if ($port) + $host = sprintf("%s:%s", $host, $port); + +if ($link = mysql_connect($host, $user, $passwd, true)) { + printf("[001] Safe mode not working properly?\n"); + mysql_close($link); +} + +if ($link = mysql_pconnect($host, $user, $passwd)) { + printf("[002] Safe mode not working properly?\n"); + mysql_close($link); +} +print "done!\n"; +?> +--EXPECTF-- +Notice: mysql_connect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d + +Warning: mysql_connect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d + +Notice: mysql_pconnect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d + +Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d +done! \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_trace_mode.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/mysql/tests/mysql_trace_mode.phpt diff -u /dev/null php-src/ext/mysql/tests/mysql_trace_mode.phpt:1.2 --- /dev/null Wed Oct 10 10:55:52 2007 +++ php-src/ext/mysql/tests/mysql_trace_mode.phpt Wed Oct 10 10:55:52 2007 @@ -0,0 +1,33 @@ +--TEST-- +mysql.trace_mode=1 +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--INI-- +mysql.trace_mode=1 +error_reporting=E_ALL | E_NOTICE | E_STRICT +--FILE-- +<?php +require_once('connect.inc'); +require_once('table.inc'); + +$res1 = mysql_query('SELECT id FROM test', $link); + +if (!$res2 = mysql_db_query('phptest', 'SELECT id FROM test', $link)) + printf("[001] [%d] %s\n", mysql_errno($link), mysql_error($link)); +mysql_free_result($res2); +print mysql_escape_string("I don't mind character sets, do I?\n"); + +$res3 = mysql_query('BOGUS_SQL', $link); +mysql_close($link); + +print "done!\n"; +?> +--EXPECTF-- +Notice: mysql_db_query(): This function is deprecated; use mysql_query() instead%sin %s on line %d + +Warning: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in %s on line %d +I don\'t mind character sets, do I?\n +Warning: mysql_query(): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BOGUS_SQL' at line 1 in %s on line %d +done! + +Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/mysql/tests/mysql_pconnect.phpt?r1=1.3&r2=1.4&diff_format=u Index: php-src/ext/mysql/tests/mysql_pconnect.phpt diff -u php-src/ext/mysql/tests/mysql_pconnect.phpt:1.3 php-src/ext/mysql/tests/mysql_pconnect.phpt:1.4 --- php-src/ext/mysql/tests/mysql_pconnect.phpt:1.3 Thu Aug 9 11:53:17 2007 +++ php-src/ext/mysql/tests/mysql_pconnect.phpt Wed Oct 10 10:55:52 2007 @@ -1,82 +1,85 @@ --TEST-- mysql_pconnect() --SKIPIF-- -<?php -require_once('skipif.inc'); +<?php +require_once('skipif.inc'); require_once('skipifconnectfailure.inc'); ?> +--INI-- +mysql.max_persistent=10 +mysql.allow_persistent=1 --FILE-- <?php -include "connect.inc"; + include "connect.inc"; -$tmp = NULL; -$link = NULL; + $tmp = NULL; + $link = NULL; -// mysql_pconnect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) -if (NULL !== ($tmp = @mysql_pconnect($link, $link, $link, $link, $link, $link))) - printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + // mysql_pconnect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) + if (NULL !== ($tmp = @mysql_pconnect($link, $link, $link, $link, $link, $link))) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); -$myhost = (is_null($socket)) ? ((is_null($port)) ? $host : $host . ':' . $port) : $host . ':' . $socket; -if (!$link = mysql_pconnect($myhost, $user, $passwd, true)) - printf("[002] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", - $host, $myhost, $user, $db, $port, $socket); + $myhost = (is_null($socket)) ? ((is_null($port)) ? $host : $host . ':' . $port) : $host . ':' . $socket; + if (!$link = mysql_pconnect($myhost, $user, $passwd, true)) + printf("[002] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $myhost, $user, $db, $port, $socket); -mysql_close($link); + mysql_close($link); -if ($link = mysql_pconnect($myhost, $user . 'unknown_really', $passwd . 'non_empty', true)) - printf("[003] Can connect to the server using host=%s/%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", - $host, $myhost, $user . 'unknown_really', $db, $port, $socket); + if ($link = mysql_pconnect($myhost, $user . 'unknown_really', $passwd . 'non_empty', true)) + printf("[003] Can connect to the server using host=%s/%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", + $host, $myhost, $user . 'unknown_really', $db, $port, $socket); -if (false !== $link) - printf("[004] Expecting boolean/false, got %s/%s\n", gettype($link), $link); + if (false !== $link) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($link), $link); -// Run the following tests without an anoynmous MySQL user and use a password for the test user! + // Run the following tests without an anoynmous MySQL user and use a password for the test user! -if (!ini_get('sql.safe_mode')) { + if (!ini_get('sql.safe_mode')) { - if ($socket) { - ini_set('mysql.default_socket', $socket); + if ($socket) { + ini_set('mysql.default_socket', $socket); + if (!is_resource($link = mysql_pconnect($host, $user, $passwd, true))) { + printf("[005] Usage of mysql.default_socket failed\n") ; + } else { + mysql_close($link); + } + } else { + ini_set('mysql.default_socket', null); + } + + ini_set('mysql.default_port', $port); if (!is_resource($link = mysql_pconnect($host, $user, $passwd, true))) { - printf("[005] Usage of mysql.default_socket failed\n") ; + printf("[006] Usage of mysql.default_port failed\n") ; } else { mysql_close($link); } - } else { - ini_set('mysql.default_socket', null); - } - ini_set('mysql.default_port', $port); - if (!is_resource($link = mysql_pconnect($host, $user, $passwd, true))) { - printf("[006] Usage of mysql.default_port failed\n") ; - } else { - mysql_close($link); - } - - ini_set('mysql.default_password', $passwd); - if (!is_resource($link = mysql_pconnect($myhost, $user))) { - printf("[007] Usage of mysql.default_password failed\n") ; - } else { - mysql_close($link); - } + ini_set('mysql.default_password', $passwd); + if (!is_resource($link = mysql_pconnect($myhost, $user))) { + printf("[007] Usage of mysql.default_password failed\n") ; + } else { + mysql_close($link); + } - ini_set('mysql.default_user', $user); - if (!is_resource($link = mysql_pconnect($myhost))) { - printf("[008] Usage of mysql.default_user failed\n"); - } else { - mysql_close($link); - } + ini_set('mysql.default_user', $user); + if (!is_resource($link = mysql_pconnect($myhost))) { + printf("[008] Usage of mysql.default_user failed\n"); + } else { + mysql_close($link); + } - ini_set('mysql.default_host', $myhost); - if (!is_resource($link = mysql_pconnect())) { - printf("[009] Usage of mysql.default_host failed\n") ; - } else { - mysql_close($link); + ini_set('mysql.default_host', $myhost); + if (!is_resource($link = mysql_pconnect())) { + printf("[009] Usage of mysql.default_host failed\n") ; + } else { + mysql_close($link); + } } -} -print "done!"; + print "done!"; ?> --EXPECTF-- Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d -done! \ No newline at end of file +done!
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php