/ Published in: PHP
A very simple class that quickly gets you interacting with a database, as long as you know sql :P.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Database connection class. * $db = new db(array(host, user, password, database)); * $db->connect(); * $clean = $db->clean($dirty); * $db->query(""); * $db->disconnect(); */ class db { private $connection; $this->db['server'] = $args['server']; $this->db['username'] = $args['username']; $this->db['password'] = $args['password']; $this->db['database'] = $args['database']; } public function connect() { $this->connection = mysqli_connect($this->db["server"], $this->db["username"], $this->db["password"]); $this->select_db(); } public function disconnect() { $this->connection = null; } public function select_db() { public function query($sql) { public function is_connected() { return ($this->connection) ? true : false; } public function clean($dirty) { return $clean; }; foreach ($dirty as $p=>$data) { $clean[$p] = $data; }; return $clean; } }