I'm following a tutorial that teaches how to use PDO to connect to mySQL db via php and I'm trying to figure out if my connection is good. This is the code I have, but I can't tell how to check if I'm connected.
How can I update the following code so it returns a "connected" vs "no connected" message?
<?php
class Database
{
private static $dbName = 'benrud_carsData' ;
private static $dbHost = 'localhost' ;
private static $dbUsername = 'benrud_read5th';
private static $dbUserPassword = 'XXXXXXX';
private static $cont = null;
public function __construct() {
die('Init function is not allowed');
}
public static function connect()
{
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}
?>