Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Db
- {
- public function __construct($host,$user,$pass,$name)
- {
- try
- {
- $this->_connect($host,$user,$pass);
- }catch(Exception $e){
- die($e->getMessage());
- }
- try{
- $this->_select($name);
- }catch(Exception $e){
- die($e->getMessage());
- }
- }
- private function _connect($host,$user,$pass)
- {
- if(!mysql_connect($host,$user,$pass))
- {
- throw new Exception("Could not connect to database server");
- }else{
- mysql_connect($host,$user,$pass);
- }
- }
- private function _select($name)
- {
- if(!mysql_select_db($name))
- {
- throw new Exception("Could not select database");
- }else{
- mysql_select_db($name);
- }
- }
- public function query($query)
- {
- return mysql_query($query);
- }
- public function fetch($result)
- {
- return mysql_fetch_object($result);
- }
- public function escape($str)
- {
- return mysql_real_escape_string($str);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement