Skip to content

Commit

Permalink
Fixing test: it didn't do a select_db and gave a false-positive with …
Browse files Browse the repository at this point in the history
…libmysql
  • Loading branch information
Ulf Wendel committed Nov 5, 2009
1 parent c4b9737 commit ea3ef35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
14 changes: 10 additions & 4 deletions ext/mysql/tests/connect.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (!function_exists('sys_get_temp_dir')) {

if (!function_exists('my_mysql_connect')) {
/* wrapper to simplify test porting */
function my_mysql_connect($host, $user, $passwd, $db, $port, $socket, $flags = NULL) {
function my_mysql_connect($host, $user, $passwd, $db, $port, $socket, $flags = NULL, $persistent = false) {
global $connect_flags;

$flags = ($flags === NULL) ? $connect_flags : $flags;
Expand All @@ -31,9 +31,15 @@ if (!function_exists('my_mysql_connect')) {
else if ($port)
$host = sprintf("%s:%s", $host, $port);

if (!$link = mysql_connect($host, $user, $passwd, true, $flags)) {
printf("[000-a] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
$host, $user, $passwd,
if ($persistent) {
$link = mysql_pconnect($host, $user, $passwd, $flags);
} else {
$link = mysql_connect($host, $user, $passwd, true, $flags);
}

if (!$link) {
printf("[000-a] Cannot connect using host '%s', user '%s', password '****', persistent = %d, [%d] %s\n",
$host, $user, ($persistent) ? 1 : 0,
mysql_errno(), mysql_error());
return false;
}
Expand Down
16 changes: 4 additions & 12 deletions ext/mysql/tests/mysql_pconn_disable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ mysql.max_links=2
<?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)))
if (($plink = my_mysql_connect($host, $user, $passwd, $db, $port, $socket, NULL, true)))
printf("[001] Can connect to the server.\n");

if (($res = @mysql_query('SELECT id FROM test ORDER BY id ASC', $plink)) &&
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",
Expand All @@ -35,7 +27,7 @@ mysql.max_links=2
$thread_id = mysql_thread_id($plink);
mysql_close($plink);

if (!($plink = mysql_pconnect($myhost, $user, $passwd)))
if (!($plink = my_mysql_connect($host, $user, $passwd, $db, $port, $socket, NULL, true)))
printf("[003] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error());

if (mysql_thread_id($plink) != $thread_id)
Expand All @@ -44,7 +36,7 @@ mysql.max_links=2
$thread_id = mysql_thread_id($plink);
mysql_close($plink);

if (!($plink = mysql_connect($myhost, $user, $passwd, true)))
if (!($plink = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)))
printf("[005] Cannot connect, [%d] %s\n", mysql_errno(), mysql_error());

if (mysql_thread_id($plink) == $thread_id)
Expand Down

0 comments on commit ea3ef35

Please sign in to comment.