dqwcdqs358367
2015-10-25 05:42
浏览 122
已采纳

错误:PDO :: __ construct()期望参数2为字符串

db.php

class db {
    private static $_instance = null;
    private $_pdo, private
    function __construct() {
        try {
            $this - > _pdo = new PDO('mysql:host='.config::get('mysql/host').
                '; dbname='.config::get('mysql/db'), config::get('mysql/username'), config::get('mysql/password'));
            echo 'hello ';
        } catch (PDOException $e) {
            die($e - > getMessage());
        }
    }
    public static
    function getInstance() {
        if (!isset(self::$_instance)) {
            self::$_instance = new db();
        }
        return self::$_instance;
    }
}

config.php

         class config {

public static function get($path=null) {
    if($path) {

        $config = $GLOBALS['config'] ;
        $path = explode('/',$path) ;


    foreach ($path as $bit) {
        if(isset($config[$bit])) { 
             $config = $config[$bit];
           }
       }

       return $config ;
    }

     } 
  }  

initialize.php

   session_start() ;

     $GLOBALS['config'] = array(
    'mysql' => array (
    'host' => '127.0.0.1',
    'user' => 'root' ,
    'password' => '',
    'db' => 'login' 
    ) ) ;

all three files added Error:

in main db::getInstance() call error shown Error: PDO::__construct() expects parameter 2 to be string .

add more details for submitting. what lines i add to in it submit question .

1条回答 默认 最新

相关推荐 更多相似问题