include_once KERNEL_DIR BaseException php Generic DB exception Nothing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
include_once(KERNEL_DIR . 'BaseException.php');
// Generic DB exception. Nothing to change, except class name ;)
class DbException extends BaseException {}
// DB Query exception.
class DbQueryException extends DbException
{
function __construct($mysql_link, $sql = '-')
{
$this->message = "SQL: '" . $sql . "' ";
$this->message .= "Error: [" . mysql_errno($mysql_link) . "] '" . mysql_error($mysql_link) . "' ";
}
}
class Db
{
private $mysql_link;
private $db_link;
public function __construct($db_host, $db_user, $db_password, $db_name)
{
$this->mysql_link = @mysql_connect($db_host, $db_user, $db_password, $db_name);
if(!$this->mysql_link) throw new DbException('Could not connect to database');
$this->db_link = @mysql_select_db($db_name, $this->mysql_link);
if(!$this->db_link) throw new DbException('Could not select database');
}
}