How does the return value of mysqli_connect() relate to the Boolean value true?
书包屁孩
书包屁孩 2018-11-07 22:53:49
0
3
1629

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());

}

书包屁孩
书包屁孩

reply all(3)
虔

mysqli_connect() return value--》The resource handle is returned. You must add two conditional judgments! !


神沐

1541732977(1).jpg

You should be able to understand this very intuitively

胤彬-

微信截图_20181108154929.png

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template