]> granicus.if.org Git - php/commitdiff
Double check if line is sill usable and connected to last successfully selected db.
authorUlf Wendel <uw@php.net>
Tue, 26 Jul 2011 16:14:59 +0000 (16:14 +0000)
committerUlf Wendel <uw@php.net>
Tue, 26 Jul 2011 16:14:59 +0000 (16:14 +0000)
ext/mysqli/tests/mysqli_select_db.phpt

index b44487b24eef02198838773630fdff646178ce86..7527a1313b5063f83b581c8d051b9a0c79426e2e 100644 (file)
@@ -9,6 +9,7 @@ require_once('skipifconnectfailure.inc');
 --FILE--
 <?php
        require_once("connect.inc");
+       require_once("table.inc");
 
        $tmp    = NULL;
        $link   = NULL;
@@ -55,11 +56,14 @@ require_once('skipifconnectfailure.inc');
                mysqli_free_result($res);
        }
 
+       if (!$link->select_db($db))
+               printf("[012] Failed to set '%s' as current DB; [%d] %s\n", $link->errno, $link->error);
+
        if (!$res = mysqli_query($link, "SELECT DATABASE() AS dbname"))
-               printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+               printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
        if (!$row = mysqli_fetch_assoc($res))
-               printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+               printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
        $current_db = $row['dbname'];
 
@@ -69,14 +73,20 @@ require_once('skipifconnectfailure.inc');
        mysqli_select_db($link, 'I can not imagine that this database exists');
 
        if (!$res = mysqli_query($link, "SELECT DATABASE() AS dbname"))
-               printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+               printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
        if (!$row = mysqli_fetch_assoc($res))
-               printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+               printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
        if (strtolower($row['dbname']) != strtolower($current_db))
-               printf("[016] Current DB should not change if set fails\n");
+               printf("[017] Current DB should not change if set fails\n");
+
+       
+       if (!$res = $link->query("SELECT id FROM test WHERE id = 1"))
+               printf("[018] [%d] %s\n");
 
+       $row = $res->fetch_assoc();
+       $res->free();
 
        mysqli_close($link);
 
@@ -85,6 +95,8 @@ require_once('skipifconnectfailure.inc');
 
        print "done!\n";
 ?>
+--CLEAN--
+<?php require_once("clean_table.inc"); ?>
 --EXPECTF--
 Warning: mysqli_select_db(): (%d/%d): Unknown database '%s' in %s on line %d