Доброго времени суток!
Имеется
класс для работы с PDO<?php
/**
* @author col.shrapnel@gmail.com
* @license Apache license 2.0
*
* The best PDO wrapper
*
* https://github.com/colshrapnel/thebestpdowrapper
*
**/
namespace app\vendor\DB;
use \PDO;
define('DB_HOST', 'localhost');
define('DB_NAME', 'name');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_CHAR', 'utf8');
class DB
{
protected static $instance = null;
final private function __construct() {}
final private function __clone() {}
public static function instance()
{
if (self::$instance === null)
{
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => TRUE,
PDO::ATTR_STATEMENT_CLASS => array('myPDOStatement'),
);
$dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset='.DB_CHAR;
self::$instance = new PDO($dsn, DB_USER, DB_PASS, $opt);
}
return self::$instance;
}
public static function __callStatic($method, $args) {
return call_user_func_array(array(self::instance(), $method), $args);
}
}
class myPDOStatement extends \PDOStatement
{
function execute($data = array())
{
parent::execute($data);
return $this;
}
}
и класс
<?php
namespace app\controllers;
use app\core\Controller;
use app\vendor\DB\DB;
class PostController extends Controller
{
/**
*
*/
public function indexAction($id)
{
debug($id);
$sql = "SELECT * FROM user WHERE id = ?";
$user = DB::prepare($sql)->execute([$id])->fetch();
// test
echo "id: " . $user['id'] . "<br>";
echo "Login: " . $user['user_name'] . "<br>";
echo "Password: " . $user['user_pass'] . "<br>";
echo "Email: " . $user['user_email'] . "<br>";
echo "Date" . $user['user_date'];
}
}
При запросе к БД код выдает ошибку:
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); the classname must be a string specifying an existing class in D:\OSPanel\domains\new.loc\www\app\vendor\DB\DB.php:37
Stack trace:
#0 D:\OSPanel\domains\new.loc\www\app\vendor\DB\DB.php(37): PDO->__construct('mysql:host=loca...', 'root', '', Array)
#1 D:\OSPanel\domains\new.loc\www\app\vendor\DB\DB.php(42): app\vendor\DB\DB::instance()
#2 D:\OSPanel\domains\new.loc\www\app\controllers\PostController.php(24): app\vendor\DB\DB::__callStatic('prepare', Array)
#3 D:\OSPanel\domains\new.loc\www\index.php(21): app\controllers\PostController->indexAction('1')
#4 {main}
thrown in D:\OSPanel\domains\new.loc\www\app\vendor\DB\DB.php on line 37
Подскажите в чем проблема, спасибо!