pdo connection status turned into a variable to echo elsewhere.

Associate
Joined
11 Oct 2008
Posts
268
Hey guys,

I am currently using the following code to connect to my database and to display custom messages for if it has connected to the database or not.

I would quite like to display these messages in my footer.

I was wondering if its possible to turn the messages into a variable to echo them in the footer? Thanks for any tips.

PHP:
$hostname = 'localhost';
    $database = '';
    $username = '';
    $password = '';
      try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
      echo 'Connected to database'; }
      catch(PDOException $e) {
      echo 'error connecting to database.'; }
      error_reporting(0);
 
Back
Top Bottom