Search code examples
phpmysqlmysql-connect

PHP mysql_connect with false variable


.Hello, I'm reading through some code and am not sure if I'm understanding this fully. This is supposed to connect to a mysql database:

if (!$dblink[$dblinkname] = mysql_connect($dbhost, $dbuser, $dbpass, true)) {
        //Throw error message
    }

Is this saying that if the dblink's name is empty then attempt to mysql_connect()? If I'm wrong on this any pointers would be appreciated! Thanks!


Solution

  • The statement is first assigning whatever value is returned by mysql_connect function to $dblink[$dblinkname] variable.

    Now, if the connection is made, it will return the link resource and the condition will not be false hence it will not throw error.

    But if connection is not made, the returned value would be false, which will make the condition(!$dblink[$dblinkname]) true, hence it will execute error handling code.