0

我不知道 PHP 脚本。我是一名 iPhone 开发人员。我想为我的 iPhone 应用启用 Apple 推送通知。我正在关注教程http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2。从终端运行 push.php 文件时,我的 push_development.log 文件中出现以下错误,

终端命令:

unknownc42c032e8297:~ creagx$ cd /Users/creagx/Desktop/PushChatServer
unknownc42c032e8297:PushChatServer creagx$ php push/push.php development

push_development.log 文件中的错误消息:

2012-05-14T10:17:14+05:30 Push script started (development mode)
2012-05-14T10:17:14+05:30 Exiting with fatal error: exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Users/gopi/Desktop/PushChatServer/push/push.php:82
Stack trace:
#0 /Users/gopi/Desktop/PushChatServer/push/push.php(82): PDO->__construct('mysql:host=loca...', 'gopipush', 'uH4q9xQGNAuFW...', Array)
#1 /Users/gopi/Desktop/PushChatServer/push/push.php(36): APNS_Push->__construct(Array)
#2 {main}

我想知道通过这个命令传递的值是什么?

// Create a connection to the database.
        $this->pdo = new PDO(
            'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], 
            $config['db']['username'], 
            $config['db']['password'],
            array());

        writeToLog('PDO Value: ' . $this->pdo);

我尝试使用 打印日志文件中的 PDO 值writeToLog('PDO Value: ' . $this->pdo);。谁能告诉我如何知道 pdo 值?提前致谢。

编辑:

// Create a connection to the database.
        $this->pdo = new PDO(
            'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], 
            $config['db']['username'], 
            $config['db']['password'],
            array());

        writeToLog('Host: ' . $config['db']['host']);
        writeToLog('DataBase: ' . $config['db']['dbname']);
        writeToLog('Username: ' . $config['db']['username']);
        writeToLog('Password: ' . $config['db']['password']);

再次在日志文件中收到相同的错误消息。我认为writeToLog('Host: ' . $config['db']['host']); 行将不会编译,直到行中的错误修复$this->pdo。这是对的吗?请帮我。提前致谢。

4

1 回答 1

0

PDO 是一个类...您可以使用 var_dump 来检查它的成员变量。var_dump 直接输出,因此您可以使用输出缓冲来捕获它,如下所示:

ob_start();
var_dump($this->PDO);
writeToLog('PDO state: ' . ob_get_contents());
ob_end_clean();

老实说,这可能很容易做到:

writeToLog('Host: ' . $config['db']['host']);
writeToLog('DB: ' . $config['db']['dbname']);
writeToLog('username: ' .  $config['db']['password']);
writeToLog('Password: ' . $config['db']['password']);

这一切都假设这writeToLog是您创建的工作功能。如果没有,那就echo取而代之。

于 2012-05-14T05:24:19.797 回答