I am a student.
I'm trying to deliberately induce an error in
$db_connect->select_db($db_name);
to check the error handling, but it won't give out an error?
The actual database name is 'cart', but i am using 'cartxx' to try and induce an error, but nothing happens, it runs as if there is no error. I don't have a database named 'cartxx'.
<?php
session_start();
$host = 'localhost'; // connects to the host server
$db_name = 'cartxx'; // name of the database we are connecting to
$db_username = 'root'; // username for database
$db_password = ''; // password for database
$db_connect = new mysqli($host, $db_username, $db_password); // connect to mysql
// If error
if (mysqli_connect_errno()) {
echo('Connection to database failed: ' . mysqli_connect_error());
exit();
}
// Select database
$db_connect->select_db($db_name);
// If error
if (mysqli_connect_errno()) {
echo 'Connection to database {$db_name} has failed: ' . mysqli_connect_error();
exit();
}
Thanks.