致命错误:在php中调用未定义的函数fetch_assoc()

时间:2015-04-16 21:18:26

标签: function undefined

我收到错误"致命错误:调用未定义的函数fetch_assoc()"。你能告诉我应该如何继续吗?

代码如下所述

$servername = "localhost";

$username = "s";

$password = "j";

$conn = new mysqli($servername, $username, $password);


if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

echo "Connected successfully";

$sql = "select idnew_table, new_tablecol from new_schema.new_table;";

$result = $conn->query($sql);

$r = count($result);


if ($result['num_rows'] != 10) {


    while($row = $result[fetch_assoc()]){
        echo "id: " . $row["idnew_table"]. " - Name: " .             $row["new_tablecol"];
        }

} else {
    echo "0 results";
}

$conn->close();

1 个答案:

答案 0 :(得分:1)

这一行:

while($row = $result[fetch_assoc()]){

应该是:

while($row = $result -> fetch_assoc()){