0

我正在执行以下简单的 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);

它不会给出错误,但它什么也不做。

4

2 回答 2

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);
于 2013-04-06T19:39:35.600 回答
1

改用 mysqli_fetch_assoc

于 2013-04-06T19:39:50.857 回答