douyi1982
2015-02-20 20:06
浏览 41
已采纳

PHP mysql_connect与false变量

.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!

图片转代码服务由CSDN问答提供 功能建议

。你好,我正在阅读一些代码,我不确定我是否完全理解这一点。 这 应该连接到mysql数据库:

  if(!$ dblink [$ dblinkname] = mysql_connect($ dbhost,$ dbuser,$ dbpass,true)){
  //抛出错误消息
} 
   
 
 

这是说如果dblink的名称为空,那么尝试mysql_connect()? 如果我错在这个任何指针将不胜感激! 谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongshi1424 2015-02-20 20:14
    已采纳

    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.

    点赞 评论
  • dou91855 2015-02-20 20:14

    The following code do the same thing as the one in your question

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

    In your case, the result of the mysql_connect command is stored in your array and then the content of your array is evaluated to see if you have a connection or not.

    点赞 评论

相关推荐 更多相似问题