Is there any problem in checking PHP PDO connection this manner?
Is this way reliable?
function pdo_mysql()
{
$mysql_string = "xxxxxxxxxxx";
$mysql_user = "xxxxxxxxxxx";
$mysql_pass = "xxxxxxxxxxx";
try
{
$pdo_mysql = new PDO( $mysql_string, $mysql_user, $mysql_pass );
$pdo_mysql->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$pdo_mysql->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
return true;
}
catch( PDOException $ex )
{
log_action( "pdo_mysql", $ex->getCode() . ": " . $ex->getMessage() );
return false;
}
return false;
}
and then checking the return like this:
if( $pdo_mysql = pdo_mysql() )