Ch.4 Connect to DB showing blank page result

I am attempting to complete ch.4 of PHP & MYSQL 5th ed. I have gone over the code repeatedly and can find no errors. When I attempt to view in browser I receive only a blank page. lol This code seems awful simple to be having an issue with. :smile: Help is GREATLY appreciated.

index.php

<?php
try
{
  $pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser','password');
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $pdo->exec('SET NAMES "utf-8"');
}
catch (PDOException $e)
{ 
  $output = 'Unable to connect to database server:' . $e->getMessage();
  include 'output.html.php';
  exit()
}

$output = 'Database connection established,';
include 'output.html.php';

_________________________________________________________________
output.html.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Script Output</title>
  </head>
  <body>
    <p>
      <?php echo $output; ?>
    </p>
  </body>
</html>

An obvious question, but are you running this locally on WAMP or XAMP or similar, or on a hosted server? That is, can you run other php code and get a result?

If you change output.html.php to this (added h1 tag, changed echo to var_dump) is the page still blank?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Script Output</title>
  </head>
  <body>
    <h1>Script Output</h1>
    <p>
      <?php var_dump($output); ?>
    </p>
  </body>
</html>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.