我已经创建了一个Database.php类来管理我的SQL:
<?php
$db = new Database();
$db->prepare("INSERT INTO fity_users(user_email, user_password,
user_firstname, user_lastname, user_pseudo, user_sexe, user_rank,
account_isadmin, account_isban, account_date) VALUES(?, ?, ?, ?, ?, ?, ?, ?,
? , ?)",
['test@test.fr', 'sdfsfds', 'mat', 'mag', 'matieufit', 'h', 100, 0, 0,
'20/02/2000']);
class Database {
private $tokenAuth;
private $pdo;
/**
* Constructeur de la class de gestion de la base de données!
*/
public function __construct() {
$this->tokenAuth = array(
'bdname' => 'fitaryadb',
'host' => '127.0.0.1',
'user' => 'admin',
'password' => 'admin',
);
}
// Fonction privé pour récupérer la connection à la SQL!
private function getPDO() {
if ($this->pdo === null) {
$pdo = new PDO('mysql:dbname=' . $this->tokenAuth['bdname'] . ';host='. $this->tokenAuth['host'], $this->tokenAuth['user'], $this->tokenAuth['password']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo = $pdo;
}
return $pdo;
}
// Effectuer au requête 'query' à la SQL!
public function query($statement) {
$request = $this->getPDO()->query($statement);
$result = $request->fetchAll(PDO::FETCH_OBJ);
return $result;
}
// Effectuer une requête 'préparée' à la SQL!
public function prepare($statement, $values) {
$request = $this->getPDO()->prepare($statement);
$request->execute($values);
$request->setFetchMode(PDO::FETCH_OBJ);
$result = $request->fetchAll();
print($result->user_id);
return $request;
}
}
?>
当我做准备时,它会添加到我的桌子上,这没问题,但是我的获取出错:
Fatal error:
Uncaught PDOException: SQLSTATE[HY000]:
General error in C:\xampp\htdocs\Fitarya\Administration\src\Database.php:47
Stack trace: #0 C:\xampp\htdocs\Fitarya\Administration\src\Database.php(47):
PDOStatement->fetchAll() #1 C:\xampp\htdocs\Fitarya\Administration\src\Database.php(5):
Database->prepare('INSERT INTO fit...', Array) #2 {main} thrown in C:\xampp\htdocs\Fitarya\Administration\src\Database.php on line 47
我已尝试删除提取行,这是非常好的工作,但我需要进行提取,与setFetchMode相同,他不起作用! (对不起,我的英语)
感谢帮助!