]> granicus.if.org Git - php/commitdiff
Check what happens if switching DB via API fails. Expected: no change of current...
authorUlf Wendel <uw@php.net>
Tue, 26 Jul 2011 15:37:59 +0000 (15:37 +0000)
committerUlf Wendel <uw@php.net>
Tue, 26 Jul 2011 15:37:59 +0000 (15:37 +0000)
ext/mysqli/tests/mysqli_select_db.phpt

index d700a2b557bdca81e2e90f223236f0d69d82d11b..b44487b24eef02198838773630fdff646178ce86 100644 (file)
@@ -55,15 +55,33 @@ require_once('skipifconnectfailure.inc');
                mysqli_free_result($res);
        }
 
-       mysqli_report(MYSQLI_REPORT_OFF);
+       if (!$res = mysqli_query($link, "SELECT DATABASE() AS dbname"))
+               printf("[012] [%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));
+
+       $current_db = $row['dbname'];
+
+       mysqli_report(MYSQLI_REPORT_OFF);         
        mysqli_select_db($link, 'I can not imagine that this database exists');
        mysqli_report(MYSQLI_REPORT_ERROR);
        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));
+
+       if (!$row = mysqli_fetch_assoc($res))
+               printf("[015] [%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");
+
+
        mysqli_close($link);
 
        if (NULL !== ($tmp = mysqli_select_db($link, $db)))
-               printf("[012] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+               printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
        print "done!\n";
 ?>