select query没有在php中返回结果

时间:2013-04-06 19:37:09

标签: php mysql select phpmyadmin

我正在执行以下简单的SQL查询:

SELECT people_picture, people_gender FROM people LIMIT 1在phpmyadmin中给出结果。

我的php代码如下:

    $query = "SELECT people_picture, people_gender FROM people LIMIT 1";
    $result = mysqli_query($con,$query);
    $row = mysql_fetch_assoc($result);
    $row1 = mysql_fetch_array($result);

    print_r($row1);
    print_r($row);

它没有给出错误,但它没有做任何事情。

2 个答案:

答案 0 :(得分:1)

你正在混合mysqli和mysql接口,这就是你被卡住的原因:

请试试这个:

$con = mysqli_connect($host, $user, $pass, $dbase);
if(!$con){
    echo 'Connection failed : '.mysqli_connect_error();
    exit(0);
}
$query = "SELECT people_picture, people_gender FROM people LIMIT 1";
$result = mysqli_query($con,$query);
if(!$result){
   echo 'Query failed : '.mysqli_error();
   exit(0);
} 
$row = mysqli_fetch_assoc($result);  //  mysql_fetch_assoc was the problem
print_r($row);

答案 1 :(得分:1)

使用mysqli_fetch_assoc代替