dougua4836 2014-08-28 05:05
浏览 46
已采纳

__construct()期望参数2为字符串

I'm trying to create a loging/registration system but I got this warning error along the way and I couldn't fix it.

Warning: PDO::__construct() expects parameter 2 to be string

Here's my code so far

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();
?>
  • 写回答

2条回答 默认 最新

  • dongtang6775 2014-08-28 05:17
    关注

    Typo

    Config::get('msql/username'), 
    

    Should be

    Config::get('mysql/username'), 
                  ^
    

    Same for password. With that typo you are getting an invalid value, hence the error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面