pdo将问题连接到mysql

时间:2014-04-25 08:51:29

标签: php mysql pdo

我连接到mysql有问题,我没有错误(至少我认为我不会),它只是给我一个空白页,无论连接是否发生。我有这四个短文件:

的init.php:

    <?php
session_start();

$GLOBALS['config'] = array(
    'mysql'         => array(
        'host'          => 'localhost',
        'username'      => 'root',
        'password'      => 'pass',
        'db'            => 'ooplr'
        ),
    'remenber'      => 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');
?>

的config.php:

<?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;
        }
        return false;
    }
}
?>

db.php中:

<?php
class DB {
    private static $_instance = null;
    private $_pdo,
            $_query,
            $_error = false,
            $_results,
            $_count = 0;

    public 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'));
        } catch (PDOException $e) {
            die($e->getMessage());
        }
        echo ('connected');
    }
    public static function getInstance() {
        if(!isset(self::$_instance)) {
            self::$_instance = new DB();
        }
        return self::$_instance;
    }
}
?>

的index.php:

<?php
require_once('core/init.php');

DB::getInstance();
?>

0 个答案:

没有答案