Hi, I'm running through the example code in the "PHP and MySQL from Novice to Ninja" book. I have a simple database connection test php file (index.php) that is supposed to call another page (output.html.php) with the include statement but it does not seem to work. I just have a blank page when I go to the url that has both files (those are the only two files in a subdirectory of /var/www/html). Below is the code for both files. Thank you.
$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser', 'mypassword');
$PDO->exec('SET NAMES "utf8");
catch (PDOException $e)
$output = 'Unable to connect to the database server.';
include = 'output.html.php';
$output = 'Database connection established.';
<meta charset="UTF-8" >
<?php echo $output; ?>
I just get blank page. Please help. Thank you.
problem fixed. Problem was with this line: $pdo->setAttribute(PDO::ALTER_ERRMODE, PDO::ERRMODE_EXCEPTION);
A blank page usually indicates an error.
To show error messages, you will need to enable them by placing this somewhere in your PHP code:
However, when your code is in a live production environment, to ensure to ensure the display of error messages is disabled, use this:
This topic is now closed. New replies are no longer allowed.