我试图创建一个日志/注册系统,但我得到了这个警告错误,我无法修复它。__construct()期望参数2是字符串
警告:PDO :: __结构()预计参数2为字符串
这里是我到目前为止的代码
db.php中
<?php
class DB {
private static $_instance = null;
private $_pdo,
$_query = null,
$_error = false,
$_results,
$_count = 0;
private function __construct() {
try {
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host').';'.
'dbname='.Config::get('mysql/db'),
Config::get('msql/username'),
Config::get('msql/password'));
} catch(PDOExeption $e) {
die($e->getMessage());
}
}
public static function getInstance() {
if (!isset(self::$_instance)){
self::$_instance = new DB();
}
return self::$_instance;
}
}
的init.php
<?php
session_start();
$GLOBALS['config'] = array (
'mysql' => array(
'host' => '127.0.01',
'username' => 'root',
'password' => '',
'db' => 'lr'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
spl_autoload_register(function($class){
require_once 'classes/' . $class . '.php';
});
require_once 'functions/sanitize.php';
?>
index.php
<?php
require 'core/init.php';
DB::getInstance();
?>
检查'Config'对象。它没有返回一个字符串。 – 2014-08-28 05:08:45
您是否使用了一些框架,否则您的** Config **类会出现意想不到的情况。 – anwerj 2014-08-28 05:10:57
什么是'Config'以及它的get()方法是如何工作的?很可能,它会为关键失误返回一个非字符串值。 – Phil 2014-08-28 05:26:40