【问题标题】:Fatal error: Call to undefined method mysqli_stmt::query()致命错误:调用未定义的方法 mysqli_stmt::query()
【发布时间】:2011-01-08 18:54:38
【问题描述】:

为什么会出现以下错误?

致命错误:调用未定义的方法 mysqli_stmt::query()

$mysqli = new mysqli("localhost", "***", "***", "***") or die($mysqli->connect_error);

function checklogin($username, $password)
{
    global $mysqli;

    $result = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
    $result->bind_param("s", $username);
    $result->query();
}

【问题讨论】:

    标签: php mysqli prepared-statement


    【解决方案1】:

    调用$mysqli->prepare() 将返回MySQLi_STMT 的实例,但MySQLi_STMT 类没有query() 方法。也许你的意思是execute()

    【讨论】:

    • 那么 mysqli 手册页上的内容是什么? if ($result = $mysqli->query($query)) { while ($row = $result->fetch_row()) { printf("%s (%s,%s)\n", $row[0 ], $row[1], $row[2]); } /* 免费结果集 */ $result->close(); }
    • 这是在 MySQLi 连接上调用 query(),而不是在准备好的语句上。
    猜你喜欢
    • 2014-01-09
    • 2013-06-02
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    相关资源
    最近更新 更多