通过PHP连接到数据库时出错

I am trying to connect to my database via PHP but get blank page when I run through Safari(http://pushchat.local:11111/test/databasename.php)

I can see my datbasename.php file under http://pushchat.local:11111/test/ as shown below: enter image description here

Following is my PHP code:

try
{
    if (!defined('APPLICATION_ENV'))
        define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : ‘development’);

    require_once '../api_config.php';
    $config = $config[APPLICATION_ENV];

    $pdo = new PDO(
        'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], 
        $config['db']['username'], 
        $config['db']['password'],
        array());

    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->query('SET NAMES utf8');

    echo 'Database connection successful!';
}
catch (Exception $e)
{
    echo 'Could not connect to the database. Reason: ' . $e;
}

I even tried to put a stop sigh using codebug but I think it never stops.

Thanks for your help.

查看全部
douyan8413
douyan8413
2015/05/07 20:16
  • mamp
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复