benshepherd icon

DB Class

benshepherd | PRO | 06/06/13 01:59:04 PM UTC | 0 ⭐ | 315 👁️ | Never ⏰ | []
PHP |

650 B

|

None

|

0 👍

/

0 👎

<?php
    class DB
    {
        private $instance;
        
        function __construct() {
            $this->instance = new MySQLi("localhost","root","password","database");
            if($this->instance->connect_errno) {
                die("MySQL Error: " . $this->instance->connect_error . "<br />");   
            }
        }
        
        public function Query($q) {
            return $this->instance->query($q);  
        }
        
        public function TableExists($table) {
            $res = $this->Query("SHOW TABLES LIKE '$table'");
            return $res->num_rows > 0;
        }
        
        public function LastError() {
            return $this->instance->error;  
        }
        
        public function Escape($v) {
            return $this->instance->real_escape_string($v); 
        }
    }
?>

Comments