I often see the following code and am confused. First, mysqli_connect() returns an object after a successful connection, which contains many key:values. Does it fail to connect? What is returned? ? ? ? ?
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
if (!$ link) {
/*It’s this big brother. What is this? It’s very strange. The if() brackets need to be judged as true or false. $link is an object. If you add a logical NOT operation in front, $link will become a bool value? Or fake? Then can I understand that $link was true before? That is to say, the return value of mysqli_connect() after a connection error is true? So !$link is false? The relationship between this is unclear, does anyone know why?*/
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
mysqli_connect() return value--》The resource handle is returned. You must add two conditional judgments! !
You should be able to understand this very intuitively