2010-12-17 15:18:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function sql_open() {
|
|
|
|
global $pdo;
|
|
|
|
if($pdo) return true;
|
|
|
|
|
2010-12-17 16:24:27 +01:00
|
|
|
$dsn = DB_TYPE . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE;
|
2011-01-15 04:17:03 +01:00
|
|
|
if(!empty(DB_DSN))
|
2010-12-17 16:24:27 +01:00
|
|
|
$dsn .= ';' . DB_DSN;
|
2010-12-17 15:18:03 +01:00
|
|
|
try {
|
2010-12-17 16:24:27 +01:00
|
|
|
return $pdo = new PDO($dsn, DB_USER, DB_PASSWORD);
|
2010-12-17 15:18:03 +01:00
|
|
|
} catch(PDOException $e) {
|
2010-12-17 15:32:12 +01:00
|
|
|
$message = $e->getMessage();
|
|
|
|
|
|
|
|
// Remove any sensitive information
|
|
|
|
$message = str_replace(DB_USER, '<em>hidden</em>', $message);
|
|
|
|
$message = str_replace(DB_PASSWORD, '<em>hidden</em>', $message);
|
|
|
|
|
|
|
|
// Print error
|
|
|
|
error('Database error: ' . $message);
|
2010-12-17 15:18:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function sql_close() {
|
|
|
|
global $pdo;
|
|
|
|
$pdo = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepare($query) {
|
|
|
|
global $pdo;
|
|
|
|
return $pdo->prepare($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function query($query) {
|
|
|
|
global $pdo;
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|