我已经搜索过,但没有发现任何东西对我的代码有帮助:
function getData($con, $table) {
$stmt = $con->query('SELECT * FROM ' . $table);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function getDataByUsername($con, $table, $username) {
$stmt = $con->query('SELECT * FROM ' . $table . ' WHERE `username` = "' . $username . '";');
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
getData 函数工作得很好,但是当我使用 getDataByUsername 时,我得到了这个错误:
Fatal error: Call to a member function fetchAll() on a non-object in /home/moe/www/status/inc/functions.php on line 12
第 12 行是这一行:
return $stmt->fetchAll(PDO::FETCH_ASSOC);
谢谢你的帮助,莫罗