【问题标题】:Fatal error: Call to undefined function fetch_assoc() in php致命错误:在 php 中调用未定义函数 fetch_assoc()
【发布时间】:2015-06-23 12:50:54
【问题描述】:

我收到一个错误“致命错误:调用未定义的函数 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();

【问题讨论】:

  • 试试mysqli_result::fetch_assoc()

标签: php function mysqli undefined


【解决方案1】:

这一行:

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

应该是:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 2014-07-21
    • 2016-07-02
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    相关资源
    最近更新 更多