如何在 apns 的日志文件中获取 $this->pdo 值


How to get $this->pdo values in log file for apns?

我不知道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);

我尝试使用 writeToLog('PDO Value: ' . $this->pdo); 在日志文件中打印 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']["主机"]);行不会编译,直到$this->pdo行中的错误修复。正确吗?请帮助我。 提前谢谢。

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