I am new to MySQL and PHP. One thing I'm unable to understand that when we check a given condition in if/else statement. Is the opposite of that condition runs automatically ?
I mean:
<?php
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
?>
Here mysqli_connect is a function and to connect we have to run the function. So the misconception here is that how it is connecting to the server. Since i havn't run the mysqli_function separately. I mean there should be a separate line for that.
OR the opposite of a given condition runs automatically ?
I have declared mysqli_connect in a variable.
No, you haven't.
You have called mysqli_connect
and assigned its return value to a variable.
The manual says:
Returns an object which represents the connection to a MySQL Server.
If the connection fails, that that will be a falsey value (which the if
statement checks, so it will only do some things if the connection was successful).