<?php
/* Exception types */
class ConnectException extends Exception { }
class SelectConnectException extends ConnectException { }
class QueryException extends Exception { }
class CloseException extends Exception { }
/* SQL functions */
function connect($user, $pass, $host, $db)
{
$connect = @mysql_connect($host, $user, $pass);
if (!$connect) throw new ConnectException('Failed to connect to DB');
$select = @mysql_select_db($db, $connect);
if (!$select) throw new SelectConnectException('Failed to select DB');
return $connect;
}
function sql_query($query, $connect_id)
{
$result = @mysql_query($query, $connect_id);
if (!$result) throw new QueryException('Failed to query DB');
return $result;
}
function sql_fetch_array($query_id)
{
return @mysql_fetch_array($query_id, MYSQL_ASSOC);
}
function sql_close($connect_id)
{
$close = @mysql_close($connect_id);
if (!$close) throw new CloseException('Failed to close DB');
}
?>