这是我当前的数据库类:
class Database {
private $db;
function Connect() {
$db_host = "localhost";
$db_name = "database1";
$db_user = "root";
$db_pass = "root";
try {
$this->db = new PDO("mysql:host=" . $db_host . ";dbname=" . $db_name, $db_user, $db_pass);
} catch(PDOException $e) {
die($e);
}
}
public function getColumn($tableName, $unknownColumnName, $columnOneName, $columnOneValue, $columnTwoName = "1", $columnTwoValue = "1") {
$stmt = $this->db->query("SELECT $tableName FROM $unknownColumnName WHERE $columnOneName='$columnOneValue' AND $columnTwoName='$columnTwoValue'");
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results[0][$unknownColumnName];
}
}
我正在尝试使用以下代码运行它:
$db = new Database();
$db->Connect();
echo $db->getColumn("Sessions", "token", "uid", 1);
我收到以下错误:
PHP 致命错误:在第 19 行的 /Users/RETRACTED/RETRACTED/root/includes/Database.php 中的非对象上调用成员函数 fetchAll()
知道怎么了?谢谢