mirror of
https://github.com/php/php-src.git
synced 2024-12-23 16:59:20 +08:00
Second last set of new tests for ext/mysql
This commit is contained in:
parent
f01e360850
commit
865d199df3
69
ext/mysql/tests/mysql_max_links.phpt
Normal file
69
ext/mysql/tests/mysql_max_links.phpt
Normal file
@ -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!
|
90
ext/mysql/tests/mysql_max_persistent.phpt
Normal file
90
ext/mysql/tests/mysql_max_persistent.phpt
Normal file
@ -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!
|
52
ext/mysql/tests/mysql_num_fields.phpt
Normal file
52
ext/mysql/tests/mysql_num_fields.phpt
Normal file
@ -0,0 +1,52 @@
|
||||
--TEST--
|
||||
mysql_num_fields()
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
require_once('skipifconnectfailure.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
include "connect.inc";
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
if (!is_null($tmp = @mysql_num_fields()))
|
||||
printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
if (false !== ($tmp = @mysql_num_fields($link)))
|
||||
printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
require('table.inc');
|
||||
|
||||
function func_test_mysql_num_fields($link, $query, $expected, $offset, $test_free = false) {
|
||||
|
||||
if (!($res = mysql_query($query, $link))) {
|
||||
printf("[%03d] [%d] %s\n", $offset, mysql_errno($link), mysql_error($link));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($expected !== ($tmp = mysql_num_fields($res)))
|
||||
printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
|
||||
gettype($expected), $expected,
|
||||
gettype($tmp), $tmp);
|
||||
|
||||
mysql_free_result($res);
|
||||
|
||||
if ($test_free && (false !== ($tmp = mysql_num_fields($res))))
|
||||
printf("[%03d] Expecting boolean/false, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
|
||||
}
|
||||
|
||||
func_test_mysql_num_fields($link, "SELECT 1 AS a", 1, 5);
|
||||
func_test_mysql_num_fields($link, "SELECT id, label FROM test", 2, 10);
|
||||
func_test_mysql_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15);
|
||||
func_test_mysql_num_fields($link, "SELECT id FROM test", 1, 20, true);
|
||||
|
||||
mysql_close($link);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: mysql_num_fields(): %d is not a valid MySQL result resource in %s on line %d
|
||||
done!
|
66
ext/mysql/tests/mysql_num_rows.phpt
Normal file
66
ext/mysql/tests/mysql_num_rows.phpt
Normal file
@ -0,0 +1,66 @@
|
||||
--TEST--
|
||||
mysql_num_rows()
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
require_once('skipifconnectfailure.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
include "connect.inc";
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
if (!is_null($tmp = @mysql_num_rows()))
|
||||
printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
if (false !== ($tmp = @mysql_num_rows($link)))
|
||||
printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
require('table.inc');
|
||||
|
||||
function func_test_mysql_num_rows($link, $query, $expected, $offset, $test_free = false) {
|
||||
|
||||
if (!$res = mysql_query($query, $link)) {
|
||||
printf("[%03d] [%d] %s\n", $offset, mysql_errno($link), mysql_error($link));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($expected !== ($tmp = mysql_num_rows($res)))
|
||||
printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
|
||||
gettype($expected), $expected,
|
||||
gettype($tmp), $tmp);
|
||||
|
||||
mysql_free_result($res);
|
||||
|
||||
if ($test_free && (false !== ($tmp = mysql_num_rows($res))))
|
||||
printf("[%03d] Expecting boolean/false, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
|
||||
}
|
||||
|
||||
func_test_mysql_num_rows($link, "SELECT 1 AS a", 1, 5);
|
||||
func_test_mysql_num_rows($link, "SHOW VARIABLES LIKE '%nixnutz%'", 0, 10);
|
||||
func_test_mysql_num_rows($link, "INSERT INTO test(id, label) VALUES (100, 'z')", false, 15);
|
||||
func_test_mysql_num_rows($link, "SELECT id FROM test LIMIT 2", 2, 20, true);
|
||||
|
||||
if ($res = mysql_query('SELECT COUNT(id) AS num FROM test', $link)) {
|
||||
|
||||
$row = mysql_fetch_assoc($res);
|
||||
mysql_free_result($res);
|
||||
|
||||
func_test_mysql_num_rows($link, "SELECT id, label FROM test", (int)$row['num'], 25);
|
||||
|
||||
} else {
|
||||
printf("[030] [%d] %s\n", mysql_errno($link), mysql_error($link));
|
||||
}
|
||||
|
||||
mysql_close($link);
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in %s on line %d
|
||||
|
||||
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in %s on line %d
|
||||
|
||||
Warning: mysql_num_rows(): %d is not a valid MySQL result resource in %s on line %d
|
||||
done!
|
58
ext/mysql/tests/mysql_pconn_disable.phpt
Normal file
58
ext/mysql/tests/mysql_pconn_disable.phpt
Normal file
@ -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!
|
106
ext/mysql/tests/mysql_pconn_kill.phpt
Executable file
106
ext/mysql/tests/mysql_pconn_kill.phpt
Executable file
@ -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!
|
169
ext/mysql/tests/mysql_pconn_max_links.phpt
Normal file
169
ext/mysql/tests/mysql_pconn_max_links.phpt
Normal file
@ -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!
|
66
ext/mysql/tests/mysql_pconn_reuse.phpt
Normal file
66
ext/mysql/tests/mysql_pconn_reuse.phpt
Normal file
@ -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!
|
85
ext/mysql/tests/mysql_pconnect.phpt
Normal file
85
ext/mysql/tests/mysql_pconnect.phpt
Normal file
@ -0,0 +1,85 @@
|
||||
--TEST--
|
||||
mysql_pconnect()
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
require_once('skipifconnectfailure.inc');
|
||||
?>
|
||||
--INI--
|
||||
mysql.max_persistent=10
|
||||
mysql.allow_persistent=1
|
||||
--FILE--
|
||||
<?php
|
||||
include "connect.inc";
|
||||
|
||||
$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);
|
||||
|
||||
$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);
|
||||
|
||||
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);
|
||||
|
||||
// Run the following tests without an anoynmous MySQL user and use a password for the test user!
|
||||
|
||||
|
||||
if (!ini_get('sql.safe_mode')) {
|
||||
|
||||
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("[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_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);
|
||||
}
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d
|
||||
done!
|
76
ext/mysql/tests/mysql_phpinfo.phpt
Normal file
76
ext/mysql/tests/mysql_phpinfo.phpt
Normal file
@ -0,0 +1,76 @@
|
||||
--TEST--
|
||||
phpinfo() mysql section
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
require_once('skipifconnectfailure.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
include_once("connect.inc");
|
||||
|
||||
@ob_clean();
|
||||
ob_start();
|
||||
phpinfo();
|
||||
$phpinfo = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
/* all versions should at least dump this minimum information */
|
||||
if (!stristr($phpinfo, "mysql support"))
|
||||
printf("[001] ext/mysql should have exposed itself.\n");
|
||||
|
||||
if (!stristr($phpinfo, "client api library version"))
|
||||
printf("[002] ext/mysql should have exposed the library version.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.default_host"))
|
||||
printf("[003] php.ini setting mysql.default_host not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.default_port"))
|
||||
printf("[004] php.ini setting mysql.default_port not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.default_password"))
|
||||
printf("[005] php.ini setting mysql.default_password not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.default_socket"))
|
||||
printf("[006] php.ini setting mysql.default_socket not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.default_user"))
|
||||
printf("[007] php.ini setting mysql.default_user not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.max_links"))
|
||||
printf("[008] php.ini setting mysql.max_links not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.max_persistent"))
|
||||
printf("[009] php.ini setting mysql.max_persistent not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.connect_timeout"))
|
||||
printf("[010] php.ini setting mysql.connect_timeout not shown.\n");
|
||||
|
||||
if (!stristr($phpinfo, "mysql.allow_persistent"))
|
||||
printf("[011] php.ini setting mysql.allow_persistent not shown.\n");
|
||||
|
||||
if ($IS_MYSQLND) {
|
||||
$expected = array(
|
||||
'client statistics',
|
||||
'bytes_sent', 'bytes_received', 'packets_sent', 'packets_received',
|
||||
'protocol_overhead_in', 'protocol_overhead_out', 'result_set_queries',
|
||||
'non_result_set_queries', 'no_index_used', 'bad_index_used',
|
||||
'buffered_sets', 'unbuffered_sets', 'ps_buffered_sets', 'ps_unbuffered_sets',
|
||||
'flushed_normal_sets', 'flushed_ps_sets', 'rows_fetched_from_server',
|
||||
'rows_fetched_from_client', 'rows_skipped', 'copy_on_write_saved',
|
||||
'copy_on_write_performed', 'command_buffer_too_small', 'connect_success',
|
||||
'connect_failure', 'connection_reused', 'explicit_close', 'implicit_close',
|
||||
'disconnect_close', 'in_middle_of_command_close', 'explicit_free_result',
|
||||
'implicit_free_result', 'explicit_stmt_close', 'implicit_stmt_close',
|
||||
'put_hits', 'put_misses', 'get_hits', 'get_misses',
|
||||
'size', 'free_items', 'references', 'mysql.cache_size',
|
||||
);
|
||||
foreach ($expected as $k => $entry)
|
||||
if (!stristr($phpinfo, $entry))
|
||||
printf("[012] Could not find entry for '%s'\n", $entry);
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECTF--
|
||||
done!
|
46
ext/mysql/tests/mysql_ping.phpt
Normal file
46
ext/mysql/tests/mysql_ping.phpt
Normal file
@ -0,0 +1,46 @@
|
||||
--TEST--
|
||||
mysql_ping()
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
require_once('skipifconnectfailure.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
include_once "connect.inc";
|
||||
|
||||
$tmp = NULL;
|
||||
$link = NULL;
|
||||
|
||||
require('table.inc');
|
||||
|
||||
if (!is_null($tmp = @mysql_ping($link, $link)))
|
||||
printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
var_dump(mysql_ping($link));
|
||||
|
||||
// provoke an error to check if mysql_ping resets it
|
||||
$res = mysql_query('SELECT * FROM unknown_table', $link);
|
||||
if (!($errno = mysql_errno($link)))
|
||||
printf("[002] Statement should have caused an error\n");
|
||||
|
||||
var_dump(mysql_ping($link));
|
||||
|
||||
if ($errno === mysql_errno($link))
|
||||
printf("[003] Error codes should have been reset\n");
|
||||
|
||||
var_dump(mysql_ping());
|
||||
mysql_close($link);
|
||||
|
||||
if (false !== ($tmp = mysql_ping($link)))
|
||||
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: mysql_ping(): %d is not a valid MySQL-Link resource in %s on line %d
|
||||
done!
|
Loading…
Reference in New Issue
Block a user