我正在使用PDO语句从DB中获取详细信息,以下是我正在使用的pdo
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 's_ao');
define('DB_USER', 'sd');
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;
}
}
现在我使用
$sid = $_GET['pmdfe23'];
$sql = "SELECT * FROM checks WHERE id = '".$sid."'";
//echo $sql;
$data = DB::prepare($sql)->execute()->fetchAll();
我收到Call to undefined method DB::prepare()
错误。请帮助解决这个问题,因为它在本地工作没有任何问题,当我上传到实时服务器,然后我收到这些错误。
答案 0 :(得分:0)
__callStatic
包装器的用途是什么?您已经有一个工厂设置来返回一个数据库对象,该对象已经为您提供了具体的方法,从而产生如下调用:
$data = DB::instance()->prepare($sql)->execute()->fetchAll();