--TEST-- mysqli_select_db() --EXTENSIONS-- mysqli --SKIPIF-- --FILE-- 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("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); if (!$row = mysqli_fetch_assoc($res)) printf("[014] [%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); ob_start(); mysqli_select_db($link, 'I can not imagine that this database exists'); $output = ob_get_contents(); ob_end_clean(); if (!stristr($output, "1049") && !stristr($output, "1044") && !stristr($output, "1045")) { /* Error: 1049 SQLSTATE: 42000 (ER_BAD_DB_ERROR) Message: Unknown database '%s' */ /* Error: 1044 SQLSTATE: 42000 (ER_DBACCESS_DENIED_ERROR) Message: Access denied for user '%s'@'%s' to database '%s' */ /* Error: 1045 SQLSTATE: 28000 (ER_ACCESS_DENIED_ERROR) Message: Access denied for user '%s'@'%s' (using password: %s) */ echo $output; } if (!$res = mysqli_query($link, "SELECT DATABASE() AS dbname")) printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); if (!$row = mysqli_fetch_assoc($res)) printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); if (strtolower($row['dbname']) != strtolower($current_db)) 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); try { mysqli_select_db($link, $db); } catch (Error $exception) { echo $exception->getMessage() . "\n"; } print "done!\n"; ?> --CLEAN-- --EXPECT-- mysqli object is already closed done!