简体   繁体   English

Debian - Apache MySQL Z92A19290E06D1C230E74A9C83C4796 日志都是空的

[英]Debian - Apache MySQL PDO issue but all logs are empty

I'm trying to get a project set up and working but I have some issues with my PDO connection.我正在尝试建立一个项目并开始工作,但我的 PDO 连接存在一些问题。 No big deal, however, it doesn't matter what logs I'm trying to find - they are all empty.没什么大不了的,但是,我试图找到什么日志并不重要——它们都是空的。

  • within the php file itself, I have ini_set('error_log', '/tmp/php_error.php');在 php 文件本身中,我有ini_set('error_log', '/tmp/php_error.php'); . .

  • within my sites-enabled config I have the error log defined under ${APACHE_LOG_DIR}/error-domain.logsites-enabled配置中,我在${APACHE_LOG_DIR}/error-domain.log下定义了错误日志

both files are empty and don't track any errors.这两个文件都是空的,不跟踪任何错误。

I'm not a debian specialist by any means, what am I missing here?无论如何,我都不是 debian 专家,我在这里缺少什么? are there any other log directories to check?还有其他日志目录要检查吗? what could cause the system to not write any error messages.什么可能导致系统不写入任何错误消息。

Make sure PDO is configured to throw errors, otherwise SQL queries may fail silently and you'll see nothing in your logs.确保 PDO 配置为抛出错误,否则 SQL 查询可能会静默失败,您将在日志中看不到任何内容。

Add this to your code just after you create the connection (in this example $conn is a variable created from the PDO constructor (eg $conn = new PDO(... etc.).在您创建连接后将其添加到您的代码中(在此示例中, $conn是从 PDO 构造函数创建的变量(例如$conn = new PDO(...等)。

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Once this is configured, SQL errors resulting from a PDO command will be thrown as PHP exceptions.配置完成后,由 PDO 命令导致的 SQL 错误将作为 PHP 异常抛出。 If PHP's normal error logging is configured correctly, these errors will then appear in your PHP error_log file.如果 PHP 的正常错误日志配置正确,这些错误将出现在您的 PHP error_log 文件中。

Documentation: https://www.php.net/manual/en/pdo.error-handling.php文档: https://www.php.net/manual/en/pdo.error-handling.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM