Why I am getting error when getting booking from database?

Why I am getting error when getting booking from database?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why I am getting error when getting booking from database?

When a script works flawlessly on your local machine but throws an error the moment you deploy it to a live server, the culprit is almost never the logic inside your while loop or your HTML structure. In the scenario described, where a PHP script successfully connects to a local database and fetches data from the confirms table, the transition to a production environment typically exposes issues related to configuration security, resource constraints, or path resolution that were masked by loose settings in development.

The code snippet provided uses the native mysqli extension to query a database named thelibr1_fyp. On your personal computer, you likely have the PHP CLI and Apache/Nginx running with default error reporting enabled (display_errors = On). This setting allows you to see exactly what is happening when a script fails. However, live hosting environments almost universally have this setting disabled or configured to log errors to a file rather than printing them directly to the browser. Consequently, if an exception occurs—such as a connection timeout, a SQL syntax error, or a permissions issue—you will see nothing but a blank page or a generic "500 Internal Server Error" without any clues on what went wrong.

The most immediate thing to investigate is the mysqli connection itself. The code uses hardcoded credentials:

$servername = "localhost";
$username = "*********";
$password = "*********";
$dbname = "thelibr1_fyp";

On a local machine, localhost usually resolves to the same machine via the loopback interface. On a live server, localhost might point to a different database service instance (like MySQL running on port 3306 vs MariaDB), or the specific user permissions for that database might differ between environments. A common pitfall is assuming that database credentials stored in a .env file on your computer are identical to those required by the production server. If the live server uses a different database schema or if the thelibr1_fyp database does not exist on the remote host, the connection will fail silently unless you have adjusted the error reporting mode.

To debug this effectively without relying on server-side logs immediately, you can temporarily enable error reporting in your script to see the specific fatal error:

error_reporting(E_ALL);
ini_set('display_errors', 1);

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection and capture the specific error message
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

If you implement this change and the error persists, check the connect_error string. Does it say "Access denied"? This points to a credential mismatch or missing user privileges on the live server. Does it say "Unknown database 'thelibr1_fyp'"? This indicates that the database migration or setup was not replicated correctly during deployment.

Another frequent issue in shared hosting environments involves mysqli resource limits or maximum execution time settings. If the query to fetch bookings is complex and the server has a low max_execution_time, the script might terminate before outputting the HTML table, resulting in an incomplete response that looks like an error. You can verify this by checking the max_execution_time directive in your .htaccess file or via phpinfo().

Finally, ensure that the mysqli extension is actually enabled on the live server. While rare nowadays given how widespread PHP is, some minimal Docker images or stripped-down shared hosting packages might not include the mysqli extension by default, causing a fatal "Class 'mysqli' not found" error before your connection logic even runs.

For robust application development, consider migrating from raw mysqli queries to an ORM or framework like Laravel. This approach abstracts database connections, manages environment variables securely via the .env file, and provides built-in exception handling that makes debugging deployment issues significantly easier.

Our network