search

Home  >  Q&A  >  body text

How does the return value of mysqli_connect() relate to the Boolean value true?

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

}

书包屁孩书包屁孩2228 days ago1641

reply all(3)I'll reply

  • 虔

    2018-11-13 00:17:40

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


    reply
    0
  • 神沐

    神沐2018-11-09 11:14:33

    1541732977(1).jpg

    You should be able to understand this very intuitively

    reply
    0
  • 胤彬-

    胤彬-2018-11-08 15:49:55

    微信截图_20181108154929.png

    reply
    0
  • Cancelreply