How can I modify this class to catch exception where MySQL Server Goes Away, and reconnect?
<?php
class DBConn
{
private $conn;
public function __construct( $persistent = false )
{
try
{
$this->conn = new PDO( "mysql:host=localhost;dbname=test", 'test', "hoollaahaoo" );
$this->conn->exec( "SET CHARACTER SET utf8" );
$this->conn->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC );
if ( $persistent )
$this->conn->setAttribute( PDO::ATTR_PERSISTENT, true );
}
catch( PDOException $e )
{
return $e->getMessage();
}
}
public function getConn()
{
return $this->conn;
}
}
See Question&Answers more detail:os