/ Published in: PHP
Just my simple db class i use
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /***************** SIMPLE DATABASE CLASS http://www.onitindustries.com ---------------------- HOW TO USE ---------------------- // Calling the class and connecting $DB = new db(); // start database class $DB->connect($c_db_username, $c_db_password, $c_db_database, $c_db_host); // connect to the database // Example Query - ARRAY $results = db::query("SELECT * FROM table", DB_GET_ARRAY); foreach($results as $result) { echo $result->column; } ******************/ // DEFINITIONS class db { private $username; private $password; private $database; private $host; private $status; private $con; public static $_query; function __construct() { } // connect to the database function connect($username, $password, $database, $host = 'localhost') { $this->username = $username; $this->password = $password; $this->database = $database; $this->host = $host; if(!$con) { $this->errors[] = 'Could not connect to the database'; } elseif(!$select) { $this->errors[] = 'Could not select the database'; } else { $this->con = $con; } return ; } // Close connection public function disconnect() { } public function showStatus() { if(!$this->status) { foreach($this->errors as $value) { echo $value.'<br>'; } } else { echo 'all good'; } } // process queries public static function query($sql, $queryType='') { switch($queryType) { case 'getRow': return self::getRow(db::$_query); break; case 'fetchArray': return self::fetchArray(db::$_query); break; case 'getCount': return self::fetchArray(db::$_query); break; default: ''; } return (self::$_query) ? true : false; } // get single row function getRow($query='') { if($query) { self::$_query = $query; } } // get array function fetchArray($query='') { if($query) { self::$_query = $query; } { $result[] = $row; } return $result; } // get last insert id public static function last_insert_id() { } } ?>
URL: http://www.onitindustries.com