mysqli_connect executing for every host input

97 Views Asked by At
<?php
/* die/exit  operation*/
mysqli_connect('localhost','root','') or die ('The connection is lost');
echo 'connected';
?>

mysqli_connect or die functions working together fine in case of the both correct and incorrect host names.But no matter what username I am using,it is always showing 'connected'.Can anyone please tell me why it is happening?

1

There are 1 best solutions below

0
Henry On

I don't think your die statement will ever be reached. mysql_connect is the alias for mysqli::connect and the object will be made.

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

To get a connection failure:

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}