0
美好的一天!我有這個問題:php中的PDO類
final class Db
{
/*
@ var object of PDO
*/
private static $connection = FALSE;
/*
@ database settings
*/
private static $data = [];
private function __construct()
{
self::$data['host'] = 'localhost';
self::$data['user'] = 'root';
self::$data['pass'] = '';
self::$data['db'] = '123';
}
/*
@ method connect to PDO
*/
private static function connect()
{
if(!isset(self::$connection))
{
try
{
self::$connection = new \PDO('mysql:host='.self::$data['host'].';dbname='.self::$data['db'], self::$data['user'], self::$data['pass']);
self::$connection -> setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
self::$connection -> exec('SET NAMES utf8');
}
catch (PDOException $e)
{
die('Ошибка подключения к БД');
}
}
}
//HERE
/*
@ method SQL query in database + return array
@ param (string) $sql SQL query
@ param (array) $param Values for execute
@ param (const) $const PDO Constants for tipization
@ return (array)
*/
public function queryFetch($sql, $params = [], $const = PDO::FETCH_ASSOC)
{
self::connect();
return self::$connection -> prepare($sql)-> execute($params) -> fetch($const);
}
}
$array = Db::queryFetch('SELECT * FROM `user` WHERE id = ?', ['1']);
var_dump($array);
致命錯誤:調用一個成員函數上布爾製備()在C:\ OpenServer的\ OpenServer的\域\ test1.ru \的index.php上線68
請如果你知道我必須做的,幫助我,這對我來說非常重要