计数行警告预期给出1布尔值

时间:2014-04-01 13:18:40

标签: php sql

$query = "SELECT * FROM tbl_usuarios WHERE email = 'teste@teste.com' and senha = '123456'";
$res=mysql_query($query);
$number=mysql_num_rows($res);

警告:mysql_num_rows期望参数1是给定的资源布尔值 我没有想到为什么它给我错误

1 个答案:

答案 0 :(得分:1)

可能是连接错误

<?php
$con = mysqli_connect('localhost', 'username', 'password','database');
$query= "SELECT * FROM tbl_usuarios WHERE email = 'teste@teste.com' and senha = '123456'";
$res = mysqli_query($con, $query) or die(mysqli_error($con));
while($return_row = mysqli_fetch_array($res, MYSQLI_ASSOC)){
        $name = $return_row['name'];    
}

?>