/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Db { private $link; // Constructor method. // ------------------------------------------------- function Db($host, $username, $password, $database) { $this->connect($host, $username, $password, $database); } function connect($host, $username, $password, $database) { $this->dbprefix = $dbprefix; } // Delete method. // ------------------------------------------------- function delete($table, $id) { $sql = "DELETE FROM `" . $table . "` WHERE `id` = '" . Db::escape($id) . "'"; } // Select method. // ------------------------------------------------- function select($table, $id=null) { // No $id given, thus select all rows. $sql = "SELECT * FROM `" . $table . "` ORDER BY `id`"; } // grabs rows matching where clauses given $sql = "SELECT * FROM `" . $table . "` WHERE "; $first=true; foreach($id as $col=>$val) { if($first) $first=false; else $sql.=" AND "; $sql .= "`".Db::escape($col)."` = '" . Db::escape($val) . "'"; } // Grabs the row associated with the given $id. } else { $sql = "SELECT * FROM `" . $table . "` WHERE `id` = '" . Db::escape($id) . "'"; } } // Update method. // ------------------------------------------------- function update($table, $id) { $column = $column->name; Utils::manipulateValues($column); // Manipulate certain values before inserting them into db. // This will be built up-on in the future. } } } // Insert method. // ------------------------------------------------- function insert($table) { $column = $column->name; Utils::manipulateValues($column); // Manipulate certain values before inserting them into db. // This will be built up-on in the future. } } $sql = "INSERT INTO `" . $table . "` (`" . implode("`, `", array_keys($fields)) . "`) VALUES (" . implode(", ", $fields) . ")"; } // Normal query for custom needs. // NOTICE: When using this method, it is your job to assure user submitted-data is secure. // ------------------------------------------------- function query($sql) { } function num_fields($result) { } function fetch_field($result) { } function fetch_row($result) { } function num_rows($result) { } function fetch_array($result) { } function fetch_assoc($result) { } function escape($string) { } // Check for tables existance. function table_exists($sector) { if ($sector == $table[0]) { return true; } } } function show_columns($table, $column) { } } $Db = new Db($settings['database']['databaseHost'], $settings['database']['databaseUsername'], $settings['database']['databasePassword'], $settings['database']['databaseName']);