我正在尝试创建一个登录/注册系统但是我一路上遇到了这个警告错误,我无法修复它。
警告:PDO :: __ construct()期望参数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();
?>
答案 0 :(得分:3)
<强>错字强>
Config::get('msql/username'),
应该是
Config::get('mysql/username'),
^
密码相同。有了这个错字,你得到一个无效的值,因此错误。
答案 1 :(得分:0)
改变这个:
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host').';'.
'dbname='.Config::get('mysql/db'),
Config::get('msql/username'),
Config::get('msql/password'));
到
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host').';'.
'dbname='.Config::get('mysql/db'),
Config::get('mysql/username'),
Config::get('mysql/password'));