这是调用sql数据库的正确方法吗?

时间:2013-11-12 01:02:11

标签: php sql

嘿,我想知道我的ip_address是否为0,我想检查所有具有0 ip_address的表,然后执行该功能。所以类似这样的代码:

    mysql_connect(db_server, db_user, db_pass);
$ipzerouseroffline = mysql_db_query(db_name,"SELECT ip_address = '0' FROM user"); 

if ( $ipzerouseroffline == 0 ) {
         //THEN CODE GOES HERE
    }

这是正确的写作方式吗?如果ip_address为零,则代码通过。

1 个答案:

答案 0 :(得分:1)

我认为这就是你想要的:

$con = mysqli_connect(db_server, db_user, db_pass, db_name);
$result = mysqli_query($con,"SELECT * FROM user WHERE ip_address = '0'");
while($row = mysqli_fetch_array($result)){
 //CODE
}
mysqli_close($con);