$config['db']['timeout']);
if($config['db']['persistent'])
$options[PDO::ATTR_PERSISTENT] = true;
return $pdo = new PDO($dsn, $config['db']['user'], $config['db']['password']);
} catch(PDOException $e) {
$message = $e->getMessage();
// Remove any sensitive information
$message = str_replace($config['db']['user'], 'hidden', $message);
$message = str_replace($config['db']['password'], 'hidden', $message);
// Print error
error('Database error: ' . $message);
}
}
function sql_close() {
global $pdo, $config;
if(!$config['db']['persistent'])
$pdo = NULL;
}
function prepare($query) {
global $pdo, $debug, $config;
if($config['debug']) {
$debug['sql'][] = $query;
}
sql_open();
return $pdo->prepare($query);
}
function query($query) {
global $pdo, $debug, $config;
if($config['debug']) {
$debug['sql'][] = $query;
}
sql_open();
return $pdo->query($query);
}
function db_error($PDOStatement=null) {
global $pdo;
if(isset($PDOStatement)) {
$err = $PDOStatement->errorInfo();
return $err[2];
} else {
$err = $pdo->errorInfo();
return $err[2];
}
}
?>