benshepherd icon

DB Static class

benshepherd | PRO | 06/06/13 02:01:34 PM UTC | 0 ⭐ | 333 👁️ | Never ⏰ | []
PHP |

650 B

|

None

|

0 👍

/

0 👎

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

Comments