uw              Mon Jul 23 12:15:20 2007 UTC

  Added files:                 
    /php-src/ext/mysqli/tests   mysqli_connect_errno.phpt 
                                mysqli_connect_error.phpt 
                                mysqli_connect_oo_defaults.phpt 
                                mysqli_connect_oo.phpt 
                                mysqli_connect_oo_warnings.phpt 
                                mysqli_connect.phpt 
                                mysqli_connect_twice.phpt 
                                mysqli_real_connect.phpt 
  Log:
  Tests for mysqli_connect(), mysqli_real_connect(), mysqli_connect_errno(), 
  mysqli_connect_error()
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_errno.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_errno.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_errno.phpt
--TEST--
mysqli_connect_errno()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        // too many parameter
        if (0 !== ($tmp = @mysqli_connect_errno($link)))
                printf("[001] Expecting integer/0, got %s/%s\n", gettype($tmp), 
$tmp);

        if (!$link = mysqli_connect($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 (0 !== ($tmp = mysqli_connect_errno()))
                printf("[003] Expecting integer/0, got %s/%s\n", gettype($tmp), 
$tmp);

        mysqli_close($link);

        $link = @mysqli_connect($host, $user . 'unknown_really', $passwd . 
'non_empty', $db, $port, $socket);
        if (false !== $link)
                printf("[004] Connect to the server should fail using host=%s, 
user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s, expecting 
boolean/false, got %s/%s\n",
                        $host, $user . 'unknown_really', $db, $port, $socket, 
gettype($link), $link);

        if (0 === ($tmp = mysqli_connect_errno()))
                printf("[005] Expecting integer/any non-zero, got %s/%s\n", 
gettype($tmp), $tmp);

        print "done!";
?>
--EXPECTF--
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_error.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_error.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_error.phpt
--TEST--
mysqli_connect_error()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        // too many parameter
        if (!is_null($tmp = @mysqli_connect_error($link)))
                printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (!$link = mysqli_connect($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 ('' !== ($tmp = mysqli_connect_error()))
                printf("[003] Expecting string/'', got %s/%s\n", gettype($tmp), 
$tmp);

        mysqli_close($link);

        if ($link = @mysqli_connect($host, $user . 'unknown_really', $passwd . 
'non_empty', $db, $port, $socket))
                printf("[003] Connect to the server should fail using host=%s, 
user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
                        $host, $user . 'unknown_really', $db, $port, $socket);

        if ('' === ($tmp = mysqli_connect_error()))
                printf("[004] Expecting string/'', got %s/%s\n", gettype($tmp), 
$tmp);

        print "done!";
?>
--EXPECTF--
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_oo_defaults.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_oo_defaults.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_oo_defaults.phpt
--TEST--
new mysqli()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        ini_set('mysqli.default_socket', 'socket');
        ini_set('mysqli.default_port', 9999);
        ini_set('mysqli.default_pw', 'password');
        ini_set('mysqli.default_user', 'user');
        ini_set('mysqli.default_host', 'host');

        mysqli_report(MYSQLI_REPORT_OFF);
        mysqli_report(MYSQLI_REPORT_STRICT);

        ini_set('mysqli.default_socket', $socket);
        try {
                $mysqli = mysqli_init();
                $mysqli->real_connect($host, $user, $passwd, $db, $port);

                if (!$res = $mysqli->query("SELECT 'mysqli.default_socket' AS 
testing"))
                        printf("[001] [%d] %s\n", $mysqli->errno, 
$mysqli->error);
                var_dump($res->fetch_assoc());
                $res->free_result();

                $mysqli->close();

        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[002] Usage of mysqli.default_socket failed\n");
        }


        ini_set('mysqli.default_port', $port);
        try {
                $mysqli = mysqli_init();
                $mysqli->real_connect($host, $user, $passwd, $db);

                if (!$res = $mysqli->query("SELECT 'mysqli.default_port' AS 
testing"))
                        printf("[003] [%d] %s\n", $mysqli->errno, 
$mysqli->error);
                var_dump($res->fetch_assoc());
                $res->free_result();

                $mysqli->close();

        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[004] Usage of mysqli.default_port failed\n");
        }

        ini_set('mysqli.default_pw', $passwd);
        try {
                $mysqli = mysqli_init();
                $mysqli->real_connect($host, $user);
                $mysqli->select_db($db);

                if (!$res = $mysqli->query("SELECT 'mysqli.default_pw' AS 
testing"))
                        printf("[005] [%d] %s\n", $mysqli->errno, 
$mysqli->error);
                var_dump($res->fetch_assoc());
                $res->free_result();

                $mysqli->close();

        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[006] Usage of mysqli.default_pw failed\n");
        }

        ini_set('mysqli.default_user', $user);
        try {
                $mysqli = mysqli_init();
                $mysqli->real_connect($host);
                $mysqli->select_db($db);

                if (!$res = $mysqli->query("SELECT 'mysqli.default_user' AS 
testing"))
                        printf("[007] [%d] %s\n", $mysqli->errno, 
$mysqli->error);
                var_dump($res->fetch_assoc());
                $res->free_result();

                $mysqli->close();

        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[008] Usage of mysqli.default_user failed\n");
        }

        ini_set('mysqli.default_host', $host);
        try {
                $mysqli = mysqli_init();
                $mysqli->real_connect();
                $mysqli->select_db($db);

                if (!$res = $mysqli->query("SELECT 1"))
                        printf("[009] [%d] %s\n", $mysqli->errno, 
$mysqli->error);
                $res->free_result();

                if (!$res = $mysqli->query("SELECT 
SUBSTRING_INDEX(USER(),'@',1) AS username"))
                        printf("[010] [%d] %s\n", $mysqli->errno, 
$mysqli->error);

                $tmp = $res->fetch_assoc();
                $res->free_result();
                if ($tmp['username'] !== $user)
                        printf("[011] Expecting string/%s, got %s/%s\n", $user, 
gettype($tmp['username']), $tmp['username']);

                $mysqli->close();

        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[012] Usage of mysqli.default_host failed\n");
        }

        try {
                $link = mysqli_connect($host, $user, $passwd, null, 
ini_get('mysqli.default_port'));
                mysqli_select_db($link, $db);
                if (!$res = mysqli_query($link, "SELECT 'have been set' AS 
all_defaults"))
                        printf("[013] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_assoc($res));
                mysqli_free_result($res);
                mysqli_close($link);
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[014] Usage of mysqli_connect() has failed\n");
        }

        try {
                $link = mysqli_connect($host, $user, $passwd, null);
                mysqli_select_db($link, $db);
                if (!$res = mysqli_query($link, "SELECT 'have been set' AS 
all_defaults"))
                        printf("[015] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_assoc($res));
                mysqli_free_result($res);
                mysqli_close($link);
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[016] Usage of mysqli_connect() has failed\n");
        }


        print "done!";
?>
--EXPECTF--
array(1) {
  ["testing"]=>
  string(21) "mysqli.default_socket"
}
array(1) {
  ["testing"]=>
  string(19) "mysqli.default_port"
}
array(1) {
  ["testing"]=>
  string(17) "mysqli.default_pw"
}
array(1) {
  ["testing"]=>
  string(19) "mysqli.default_user"
}
array(1) {
  ["all_defaults"]=>
  string(13) "have been set"
}
array(1) {
  ["all_defaults"]=>
  string(13) "have been set"
}
done!
--UEXPECTF--
array(1) {
  [u"testing"]=>
  unicode(21) "mysqli.default_socket"
}
array(1) {
  [u"testing"]=>
  unicode(19) "mysqli.default_port"
}
array(1) {
  [u"testing"]=>
  unicode(17) "mysqli.default_pw"
}
array(1) {
  [u"testing"]=>
  unicode(19) "mysqli.default_user"
}
array(1) {
  [u"all_defaults"]=>
  unicode(13) "have been set"
}
array(1) {
  [u"all_defaults"]=>
  unicode(13) "have been set"
}
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_oo.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_oo.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_oo.phpt
--TEST--
new mysqli()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        $obj = new stdClass();

        if ($mysqli = new mysqli($host, $user . 'unknown_really', $passwd . 
'non_empty', $db, $port, $socket) && !mysqli_connect_errno())
                printf("[003] Can connect to the server using host=%s, user=%s, 
passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
                        $host, $user . 'unknown_really', $db, $port, $socket);

        if (false !== $mysqli)
                printf("[004] Expecting boolean/false, got %s/%s\n", 
gettype($mysqli), $mysqli);

        // Run the following tests without an anoynmous MySQL user and use a 
password for the test user!
        ini_set('mysqli.default_socket', $socket);
        if (!is_object($mysqli = new mysqli($host, $user, $passwd, $db, $port)) 
|| (0 !== mysqli_connect_errno())) {
                printf("[005] Usage of mysqli.default_socket failed\n") ;
        } else {
                $mysqli->close();
        }

        ini_set('mysqli.default_port', $port);
        if (!is_object($mysqli = new mysqli($host, $user, $passwd, $db)) || (0 
!== mysqli_connect_errno())) {
                printf("[006] Usage of mysqli.default_port failed\n") ;
        } else {
                $mysqli->close();
        }

        ini_set('mysqli.default_pw', $passwd);
        if (!is_object($mysqli = new mysqli($host, $user)) || (0 !== 
mysqli_connect_errno())) {
                printf("[007] Usage of mysqli.default_pw failed\n") ;
        } else {
                $mysqli->close();
        }

        ini_set('mysqli.default_user', $user);
        if (!is_object($mysqli = new mysqli($host)) || (0 !== 
mysqli_connect_errno())) {
                printf("[008] Usage of mysqli.default_user failed\n") ;
        } else {
                $mysqli->close();
        }

        ini_set('mysqli.default_host', $host);
        if (!is_object($mysqli = new mysqli()) || (0 !== 
mysqli_connect_errno())) {
                printf("[008] Usage of mysqli.default_host failed\n") ;
        } else {
                $mysqli->close();
        }

        if ($IS_MYSQLND) {
                ini_set('mysqli.default_host', 'p:' . $host);
                if (!is_object($mysqli = new mysqli()) || (0 !== 
mysqli_connect_errno())) {
                        printf("[008b] Usage of mysqli.default_host failed\n") ;
                } else {
                        $mysqli->close();
                }
        }

        print "... and now Exceptions\n";
        mysqli_report(MYSQLI_REPORT_OFF);
        mysqli_report(MYSQLI_REPORT_STRICT);

        try {
                $mysqli = new mysqli($host, $user . 'unknown_really', $passwd . 
'non_empty', $db, $port, $socket);
                printf("[016] Can connect to the server using host=%s, user=%s, 
passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
                        $host, $user . 'unknown_really', $db, $port, $socket);
                $mysqli->close();
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
        }

        ini_set('mysqli.default_socket', $socket);
        try {
                $mysqli = new mysqli($host, $user, $passwd, $db, $port);
                $mysqli->close();
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[017] Usage of mysqli.default_socket failed\n") ;
        }

        ini_set('mysqli.default_port', $port);
        try {
                $mysqli = new mysqli($host, $user, $passwd, $db);
                $mysqli->close();
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[018] Usage of mysqli.default_port failed\n") ;
        }

        ini_set('mysqli.default_pw', $passwd);
        try {
                $mysqli = new mysqli($host, $user);
                $mysqli->close();
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[019] Usage of mysqli.default_pw failed\n");
        }

        ini_set('mysqli.default_user', $user);
        try {
                $mysqli = new mysqli($host);
                $mysqli->close();
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[020] Usage of mysqli.default_user failed\n") ;
        }

        ini_set('mysqli.default_host', $host);
        try {
                /* NOTE that at this point one must use a different syntax! */
                $mysqli = mysqli_init();
                $mysqli->real_connect();
                assert(0 === mysqli_connect_errno());
                $mysqli->close();
                assert(0 === mysqli_connect_errno());
        } catch (mysqli_sql_exception $e) {
                printf("%s\n", $e->getMessage());
                printf("[021] Usage of mysqli.default_host failed\n");
        }

        print "done!";
?>
--EXPECTF--
Warning: mysqli::mysqli(): (%d/%d): Access denied for user 
'%sunknown_real'@'%s' (using password: %s) in %s on line %d

Warning: mysqli::close(): Couldn't fetch mysqli in %s on line %d.... and now 
Exceptions
Access denied for user '%s'@'%s' (using password: %s)
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_oo_warnings.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_oo_warnings.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_oo_warnings.phpt
--TEST--
new mysqli()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
<?php require_once('skipifnodefuser.inc');
if (stristr(mysqli_get_client_info(), 'mysqlnd'))
        die("skip: test for libmysql (different error output when using php 
streams");
?>
--FILE--
<?php
        include "connect.inc";

        $myhost = 'invalidhost';
        $link   = NULL;

        print "1) bail\n";
        if (!is_object($mysqli = new mysqli($myhost)) || ('mysqli' !== 
get_class($mysqli)))
                printf("[001] Expecting NULL, got %s/%s\n", gettype($mysqli), 
(is_object($mysqli)) ? var_export($mysqli, true) : $mysqli);

        print "2) be quiet\n";
        if (!is_object($mysqli = @new mysqli($myhost)) || ('mysqli' !== 
get_class($mysqli)))
                printf("[002] Expecting NULL, got %s/%s\n", gettype($mysqli), 
(is_object($mysqli)) ? var_export($mysqli, true) : $mysqli);
        var_dump(mysqli_connect_error());
        var_dump(mysqli_connect_errno());

        print "3) bail\n";
        if (false !== ($link = mysqli_connect($myhost))) {
                printf("[003] Expecting boolean/false, got %s/%s\n", 
gettype($link), $link);
        }

        print "4) be quiet\n";
        if (false !== ($link = @mysqli_connect($myhost))) {
                printf("[004] Expecting boolean/false, got %s/%s\n", 
gettype($link), $link);
        }
        var_dump(mysqli_connect_error());
        var_dump(mysqli_connect_errno());

        print "done!";
?>
--EXPECTF--
1) bail

Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host '%s' (1) in 
%s on line %d
2) be quiet
%s(%d) "Unknown MySQL server host '%s' (1)"
int(2005)
3) bail

Warning: mysqli_connect(): (HY000/2005): Unknown MySQL server host '%s' (1) in 
%s on line %d
4) be quiet
%s(%d) "Unknown MySQL server host '%s' (1)"
int(2005)
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect.phpt
--TEST--
mysqli_connect()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        /* we need to check, if the server allows anonymous login (empty user) 
*/
        $tmp = @mysqli_connect('localhost');
        $anon_allow = (gettype($tmp) == "object");

        $exptype = ($anon_allow) ? "mysqli_object" : "false";

        $obj = new stdClass();
        if (!is_null($tmp = @mysqli_connect($obj)))
                printf("[001] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);

        $tmp = @mysqli_connect($link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[002] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        $tmp = @mysqli_connect($link, $link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[003] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        $tmp = @mysqli_connect($link, $link, $link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[004] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        $tmp = @mysqli_connect($link, $link, $link, $link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[005] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        $tmp = @mysqli_connect($link, $link, $link, $link, $link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[006] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        $tmp = @mysqli_connect($link, $link, $link, $link, $link, $link);
        if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp 
!= false)) {
                printf("[007] Expecting %s, got %s/%s\n", $exptype, 
gettype($tmp), $tmp);
        }

        if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
                printf("[008] Cannot connect to the server using host=%s, 
user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
                        $host, $user, $db, $port, $socket);

        mysqli_close($link);

        if ($link = mysqli_connect($host, $user . 'unknown_really', $passwd . 
'non_empty', $db, $port, $socket))
                printf("[009] Can connect to the server using host=%s, user=%s, 
passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
                        $host, $user . 'unknown_really', $db, $port, $socket);

        if (false !== $link)
                printf("[010] 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!
        ini_set('mysqli.default_socket', $socket);
        if (!is_object($link = mysqli_connect($host, $user, $passwd, $db, 
$port))) {
                printf("[011] Usage of mysqli.default_socket failed\n") ;
        } else {
                if (!$res = mysqli_query($link, "SELECT 'mysqli.default_socket' 
AS 'testing'"))
                        printf("[012] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_assoc($res));
                mysqli_free_result($res);
                mysqli_close($link);
        }

        ini_set('mysqli.default_port', $port);
        if (!is_object($link = mysqli_connect($host, $user, $passwd, $db))) {
                printf("[013] Usage of mysqli.default_port failed\n") ;
        } else {
                if (!$res = mysqli_query($link, "SELECT 'mysqli.default_port' 
AS 'testing'"))
                        printf("[014] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_assoc($res));
                mysqli_free_result($res);
                mysqli_close($link);
        }

        ini_set('mysqli.default_pw', $passwd);
        if (!is_object($link = mysqli_connect($host, $user))) {
                printf("[015] Usage of mysqli.default_pw failed\n") ;
        } else {
                if (!$res = mysqli_query($link, "SELECT 'mysqli.default_pw' AS 
'testing'"))
                        printf("[016] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_assoc($res));
                mysqli_free_result($res);
                mysqli_close($link);
        }

        ini_set('mysqli.default_user', $user);
        if (!is_object($link = mysqli_connect($host))) {
                printf("[017] Usage of mysqli.default_user failed\n") ;
        } else {
                if (!$res = mysqli_query($link, "SELECT 'mysqli.default_user' 
AS 'testing'"))
                        printf("[018] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_array($res, MYSQLI_BOTH));
                mysqli_free_result($res);
                mysqli_close($link);
        }

        ini_set('mysqli.default_host', $host);
        if (!is_object($link = mysqli_connect())) {
                printf("[019] Usage of mysqli.default_host failed\n") ;
        } else {
                if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host' 
AS 'testing'"))
                        printf("[020] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                var_dump(mysqli_fetch_array($res, MYSQLI_NUM));
                mysqli_free_result($res);
                mysqli_close($link);
        }

        if ($IS_MYSQLND) {
                ini_set('mysqli.default_host', 'p:' . $host);
                        if (!is_object($link = mysqli_connect())) {
                                printf("[021] Usage of mysqli.default_host 
(persistent) failed\n") ;
                } else {
                        if (!$res = mysqli_query($link, "SELECT 
'mysqli.default_host (persistent)' AS 'testing'"))
                                printf("[022] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));
                        $tmp = mysqli_fetch_assoc($res);
                        if ($tmp['testing'] !== 'mysqli.default_host 
(persistent)') {
                                printf("[023] Result looks strange - check 
manually, [%d] %s\n",
                                        mysqli_errno($link), 
mysqli_error($link));
                                var_dump($tmp);
                        }
                        mysqli_free_result($res);
                        mysqli_close($link);
                }
        }

        print "done!";
?>
--EXPECTF--
Warning: mysqli_connect(): (%d/%d): Access denied for user '%s'@'%s' (using 
password: YES) in %s on line %d
array(1) {
  ["testing"]=>
  string(21) "mysqli.default_socket"
}
array(1) {
  ["testing"]=>
  string(19) "mysqli.default_port"
}
array(1) {
  ["testing"]=>
  string(17) "mysqli.default_pw"
}
array(2) {
  [0]=>
  string(19) "mysqli.default_user"
  ["testing"]=>
  string(19) "mysqli.default_user"
}
array(1) {
  [0]=>
  string(19) "mysqli.default_host"
}
done!
--UEXPECTF--
Warning: mysqli_connect(): (%d/%d): Access denied for user '%s'@'%s' (using 
password: YES) in %s on line %d
array(1) {
  [u"testing"]=>
  unicode(21) "mysqli.default_socket"
}
array(1) {
  [u"testing"]=>
  unicode(19) "mysqli.default_port"
}
array(1) {
  [u"testing"]=>
  unicode(17) "mysqli.default_pw"
}
array(2) {
  [0]=>
  unicode(19) "mysqli.default_user"
  [u"testing"]=>
  unicode(19) "mysqli.default_user"
}
array(1) {
  [0]=>
  unicode(19) "mysqli.default_host"
}
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_connect_twice.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_connect_twice.phpt
+++ php-src/ext/mysqli/tests/mysqli_connect_twice.phpt
--TEST--
Calling connect() on an open connection to create a new connection
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
        include "connect.inc";

        if (!$link = mysqli_connect($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 (!$thread_id = mysqli_thread_id($link))
                printf("[002] Cannot determine thread id, test will fail, [%d] 
%s\n", mysqli_errno($link), mysqli_error($link));

        if (true !== ($tmp = mysqli_real_connect($link, $host, $user, $passwd, 
$db, $port, $socket)))
                printf("[003] Expecting boolean/true got %s/%s\n", 
gettype($tmp), $tmp);

        if (!is_int($new_thread_id = mysqli_thread_id($link)) || 
($new_thread_id < 0))
                printf("[004] Expecting int/any got %s/%s\n", gettype($tmp), 
$tmp);

        if ($thread_id == $new_thread_id)
                printf("[005] Expecting new connection and new thread id. Old 
thread id %d, new thread id %d\n", $thread_id, $new_thread_id);

        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 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 (!$thread_id = $link->thread_id)
                printf("[008] Cannot determine thread id, test will fail, [%d] 
%s\n", mysqli_errno($link), mysqli_error($link));

        if (true !== ($tmp = $link->real_connect($host, $user, $passwd, $db, 
$port, $socket)))
                printf("[009] Expecting boolean/true got %s/%s\n", 
gettype($tmp), $tmp);

        if (!is_int($new_thread_id = $link->thread_id) || ($new_thread_id < 0))
                printf("[010] Expecting int/any got %s/%s\n", gettype($tmp), 
$tmp);

        if ($thread_id == $new_thread_id)
                printf("[011] Expecting new connection and new thread id. Old 
thread id %d, new thread id %d\n", $thread_id, $new_thread_id);

        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!";
?>
--EXPECTF--
array(1) {
  ["it_works"]=>
  string(2) "ok"
}
array(1) {
  ["syntax"]=>
  string(18) "works also with oo"
}
done!
--UEXPECTF--
array(1) {
  [u"it_works"]=>
  unicode(2) "ok"
}
array(1) {
  [u"syntax"]=>
  unicode(18) "works also with oo"
}
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_real_connect.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_real_connect.phpt
+++ php-src/ext/mysqli/tests/mysqli_real_connect.phpt
--TEST--
mysqli_real_connect()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--INI--
open_basedir=.
--FILE--
<?php
        include "connect.inc";

        $tmp    = NULL;
        $link   = NULL;

        if (NULL !== ($tmp = @mysqli_real_connect($link)))
                printf("[001a] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link)))
                printf("[001b] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link)))
                printf("[001c] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link)))
                printf("[001d] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, 
$link)))
                printf("[001e] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, 
$link, $link)))
                printf("[001f] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, 
$link, $link, $link)))
                printf("[001g] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        //  ( mysqli link [, string hostname [, string username [, string 
passwd [, string dbname [, int port [, string socket [, int flags]]]]]]]
        if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, 
$link, $link, $link, $link)))
                printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        if (!$link = mysqli_init())
                printf("[002] mysqli_init() failed\n");

        if (!mysqli_real_connect($link, $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);

        mysqli_close($link);
        if (!$link = mysqli_init())
                printf("[004] mysqli_init() failed\n");

        if (false !== ($tmp = mysqli_real_connect($link, $host, $user . 
'unknown_really', $passwd . 'non_empty', $db, $port, $socket)))
                printf("[005] Expecting boolean/false got %s/%s. Can connect to 
the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, 
socket=%s\n", gettype($tmp), $tmp, $host, $user . 'unknown_really', $db, $port, 
$socket);

        // Run the following tests without an anoynmous MySQL user and use a 
password for the test user!
        ini_set('mysqli.default_socket', $socket);
        if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port)) {
                printf("[006] Usage of mysqli.default_socket failed\n");
        } else {
                mysqli_close($link);
                if (!$link = mysqli_init())
                        printf("[007] mysqli_init() failed\n");
        }

        ini_set('mysqli.default_port', $port);
        if (!mysqli_real_connect($link, $host, $user, $passwd, $db)) {
                printf("[008] Usage of mysqli.default_port failed\n");
        } else {
                mysqli_close($link);
                if (!$link = mysqli_init())
                        printf("[009] mysqli_init() failed\n");
        }

        ini_set('mysqli.default_pw', $passwd);
        if (!mysqli_real_connect($link, $host, $user)) {
                printf("[010] Usage of mysqli.default_pw failed\n") ;
        } else {
                mysqli_close($link);
                if (!$link = mysqli_init())
                        printf("[011] mysqli_init() failed\n");
        }

        ini_set('mysqli.default_user', $user);
        if (!mysqli_real_connect($link, $host)) {
                printf("[012] Usage of mysqli.default_user failed\n") ;
        } else {
                mysqli_close($link);
                if (!$link = mysqli_init())
                        printf("[011] mysqli_init() failed\n");
        }

        ini_set('mysqli.default_host', $host);
        if (!mysqli_real_connect($link)) {
                printf("[014] Usage of mysqli.default_host failed\n") ;
        } else {
                mysqli_close($link);
                if (!$link = mysqli_init())
                        printf("[015] mysqli_init() failed\n");
        }

        // CLIENT_MULTI_STATEMENTS - should be disabled silently
        if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, 
$socket, 65536))
                printf("[016] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));

        if (mysqli_query($link, "SELECT 1 AS a; SELECT 2 AS b"))
                printf("[017] Should have failed. CLIENT_MULTI_STATEMENT should 
have been disabled.\n");

        mysqli_close($link);
        if (!$link = mysqli_init())
                printf("[018] mysqli_init() failed\n");

        if (ini_get('open_basedir')) {
                // CLIENT_LOCAL_FILES should be blocked - but how to test it ?!

                if (!mysqli_real_connect($link, $host, $user, $passwd, $db, 
$port, $socket, 128))
                        printf("[019] [%d] %s\n", mysqli_errno($link), 
mysqli_error($link));

                $filename = sys_get_temp_dir() . DIRECTORY_SEPERATOR . 
'mysqli_real_connect_phpt';
                if (!$fp = fopen($filename, 'w'))
                        printf("[020] Cannot open temporary file %s\n", 
$filename);

                fwrite($fp, '100;z');
                fclose($fp);

                // how do we test if gets forbidden because of a missing right 
or the flag, this test is partly bogus ?
                if (mysqli_query($link, "LOAD DATA LOCAL INFILE '$filename' 
INTO TABLE test FIELDS TERMINATED BY ';'"))
                        printf("[021] LOAD DATA INFILE should have been 
forbidden!\n");

                unlink($filename);
        }

        mysqli_close($link);

        if (NULL !== ($tmp = mysqli_real_connect($link, $host, $user, $passwd, 
$db, $port, $socket)))
                printf("[022] Expecting NULL, got %s/%s\n", gettype($tmp), 
$tmp);

        print "done!";
?>
--EXPECTF--
Warning: mysqli_real_connect(): (%d/%d): Access denied for user '%s'@'%s' 
(using password: YES) in %s on line %d
done!
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to