我设计了以下课程
<?php
class DB {
private static $objInstance;
/*
* Class Constructor - Create a new database connection if one doesn't exist
* Set to private so no-one can create a new instance via ' = new DB();'
*/
private function __construct() {}
/*
* Like the constructor, we make __clone private so nobody can clone the instance
*/
private function __clone() {}
/*
* Returns DB instance or create initial connection
* @param
* @return $objInstance;
*/
public static function getInstance( ) {
if(!self::$objInstance){
$ini_array = parse_ini_file("db.ini");
$dbInfo['server'] = $ini_array['server'];
$dbInfo['database'] = $ini_array['database'];
$dbInfo['username'] = $ini_array['username'];
$dbInfo['password'] = $ini_array['password'];
$dsn = 'mysql:host='.$dbInfo['server'].';dbname='.$dbInfo['database'].'';
self::$objInstance = new PDO(DB_DSN, $dbInfo['username'], $dbInfo['password']);
self::$objInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return self::$objInstance;
} # end method
/*
* Passes on any static calls to this class onto the singleton PDO instance
* @param $chrMethod, $arrArguments
* @return $mix
*/
final public static function __callStatic( $chrMethod, $arrArguments ) {
$objInstance = self::getInstance();
return call_user_func_array(array($objInstance, $chrMethod), $arrArguments);
} # end method
}
?>
我的问题是当我想执行查询时出现以下错误:
致命错误:调用未定义的方法 DB::query()
foreach(DB::query("SELECT * FROM content_type_video") as $row){
print_r($row);
}
任何想法为什么以及如何解决这个问题?