Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

Enable PHP Error Reporting for engine/classes/mysql.php Troubleshooting

3 min read
10.12.2025

To enable PHP error reporting in the context of troubleshooting the engine/classes/mysql.php file, follow these steps.

PHP Error Reporting MySQL
Enable error reporting → reproduce → disable. Don't leave display_errors on prod.

For closely related PHP debug / runtime topics, see assert_quiet_eval in PHP — Explanation & Troubleshooting, vqmod::bootup — PHP domdocument, and How to Update PHP Memory Limit for Magento 2.

Enable Error Reporting Globally

Add the following code at the beginning of the mysql.php file, or preferably at the top of the script that includes mysql.php:

// Enable error reporting

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);

Log Errors to a File

Set Error Logging

Add the following code:

ini_set('log_errors', 1);

ini_set('error_log', '/path/to/error.log'); // Replace with the desired path

error_reporting(E_ALL);

Verify Log File Permissions

Ensure that the directory and file specified in /path/to/error.log are writable by the web server.

chmod 666 /path/to/error.log

Check the Log

Open the log file to review errors:

cat /path/to/error.log
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Debugging Specific to mysql.php

If you are debugging engine/classes/mysql.php, focus on the database connection and query execution.

Wrap Queries in Error Logging

Modify the query execution code in mysql.php to include error logging:

$result = mysqli_query($conn, $query);



if (!$result) {

    error_log("MySQL Query Error: " . mysqli_error($conn), 3, '/path/to/error.log');

    die("Error in SQL Query: " . mysqli_error($conn));

}

Log the Query

Ensure the query is logged for debugging:

error_log("Executing Query: " . $query, 3, '/path/to/error.log');

Use Try-Catch for Improved Error Handling

If your mysql.php file uses PDO for database interactions, you can implement try-catch blocks for better error handling:

try {

    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

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



    $stmt = $pdo->prepare($query);

    $stmt->execute();



    echo "Query executed successfully!";

} catch (PDOException $e) {

    error_log("PDO Error: " . $e->getMessage(), 3, '/path/to/error.log');

    die("Database Error: " . $e->getMessage());

}

Disable Error Reporting in Production

After resolving the issue, disable error reporting in production to avoid exposing sensitive information:

  1. Add this at the beginning of your scripts:
  2. ini_set('display_errors', 0);
    
    error_reporting(0);
  3. Keep logging enabled if necessary:
  4. ini_set('log_errors', 1);
    
    ini_set('error_log', '/path/to/error.log');
  • Enable error reporting with ini_set() to see all errors and warnings.
  • Use logging to capture errors without exposing sensitive information to users.
  • Add debugging code around the database connection and query execution in mysql.php.
  • Once resolved, disable error display in production for security.
Frequently asked questions
Drop a `.user.ini` next to mysql.php containing `display_errors = On` and `error_reporting = E_ALL`. Wait 5 minutes (PHP-FPM caches .user.ini for 300s by default), refresh the page. Errors show inline. When done, delete the .user.ini. Faster than editing master php.ini, doesn't affect other sites, doesn't need a restart.
PHP fatal error before display_errors took effect (e.g., syntax error in the same file). Check the web server error log directly: `tail -f /var/log/php_errors.log` or `/var/log/nginx/error.log`. Fatal parse errors don't respect display_errors because the script never starts. Also possible: ini_set('display_errors', 0) elsewhere in the code overrides your enable.
Only for non-fatal errors AND only after the line executes. For fatals during compile or before that ini_set runs, no effect. For your CMS debug toggles to be reliable, set them either in php.ini / .user.ini (before script execution) or via a request handler that runs first. ini_set is fine for runtime adjustment, not for catching pre-execution errors.
display_errors=Off, log_errors=On, error_log=/path/to/php_errors.log. Users see clean error pages (handled by CMS or 500 default). Admins read the log file. Never display errors on production — leaks paths, query structures, sometimes credentials. If you need to see a specific user's error, log per-request with a request ID and look it up in the log.
Related articles
MySQL error in file: /engine/classes/mysql.php at line 61
MySQL error in file: /engine/classes/mysql.php at line 52
Identifying Problematic Code in /engine/classes/mysql.php (Lines 52-53)