/ Published in: PHP
This class operates a range of mysql functions base on arrays.
Example:
Name:
Description:
Example:
Name:
Description:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Database class * * @version: 2.2 * @author: Emil T. Kampp <[email protected]> * @revised: 27 may 2007 * **/ class Database { var $host; var $name; var $user; var $pass; var $prefix; var $linkId; function Database($mysql) { foreach($mysql as $k => $v){ $this->$k = $v; } $this->prefix = $prefix; } function getLastID() { return $id[0]; } function getPossibleValues($tableA, $whereA) { $table = ""; foreach($tableA as $t) { $table .= $this->prefix.$t.", "; } } else $table = $this->prefix.$tableA; } foreach($whereA as $where) { } else { } $i = 1; foreach($vals as $val) { $return[$arr['Field']][$i++] = $val; } $return[$arr['Field']]['default'] = $arr['Default']; if($arr['Null'] != "NO") $return[$arr['Field']][0] = NULL; } } return $return; } function connect() { if(!$this->linkId) { return false; } return false; } function runSelect($tables, $where = "1", $fieldsA = "*", $order = false, $limit = false, $offset = false, $group = false) { $table = ""; foreach($tables as $t) { $table .= $this->prefix.$t.", "; } } else $table = $this->prefix.$tables; $fields = ""; if($keys[0] != '0') { foreach($keys as $key) { $fields .= $key.' AS '.$fieldsA[$key].', '; } } else { foreach($fieldsA as $field) { $fields .= $field.', '; } } } else $fields = $fieldsA; $query = "SELECT ".$fields." FROM ".$table." WHERE ".$where. ($order!== false?" ORDER BY ".$order:($group!==false ? " GROUP BY ".$group : "")). ($limit !== false?" LIMIT ".$limit:""). ($offset !== false?" OFFSET ".$offset:""); } function runUpdate($table, $valuesA, $where = "1") { $fields = ""; $values = ""; foreach($keys as $key) { if($valuesA[$key] !== NULL) else $values .= $key."=NULL,"; } } else $values = $valuesA; $query = "UPDATE ".$this->prefix.$table." SET ".$values." WHERE ".$where; $this->linkId)) return false; } function runDelete($table, $where = "1") { return false; } function runInsert($table, $valuesA, $onDuplicate = NULL) { $fields = ""; $values = ""; foreach($keys as $key) { $fields .= "`".$key."`, "; } } $onDup = ""; if($onDuplicate != NULL) { $onDup = " ON DUPLICATE KEY UPDATE "; foreach($keys as $key) { $onDup .= '`'.$key.'`='.($onDuplicate[$key]===NULL?"NULL,":"'".str_replace("'", '\'', $onDuplicate[$key])."', "); } } else $onDup .= $onDuplicate; } $query = "INSERT INTO ".$this->prefix.$table.($fields!==NULL?"(".$fields.")":""). " VALUES (".$values.")".$onDup; return false; } function getCells($table){ $query = "SHOW COLUMNS FROM `".$table."`"; return $fields; } function translateCellName($cellName){ $sql = $this->runSelect("mysql_cell_translation","mysql_name = '".$cellName."'"); return $row['human_name']?$row['human_name']:'<span class="faded">['.$cellName.']</span>'; } function getError() { } function close() { } } ?>
URL: http://kampp-productions.dk/functions/examples/database.php