table ! table is one string without spaces $columns is a string in that you can insert the strings of the columns, when more than 1 separated with ','. Spaces optional. Default is '*'. $request is a string, in that you can specific a request. Syntax: "column='value', [optional next]" separated with ','. $ordered is one string without spaces that specificate the column with taht the order will be executed. no default! $values in a string like $columns, the differenca is only that you insert instead columns the values that should become put in the belonging place, ever in ''! ex.: $columns->column1, column2; $values->'value1', 'value2'. get_error(); < for put out an error, if it exists > get_data($columns = "*"); < for get data from a table > get_spec_data($request, $columns = "*"); < for get specific data($request) from a table > get_spec_data_ordered($request, $ordered, $columns = "*"); < for get specific data from a table ordered by a specific column($ordered) and directed by a specific direction $this->direction. default="DESC"(descend) (else ASC ascend). You can only order colums that become too put out! > put($columns, $values); < for put data($values) in a table(spec $columns) > if_value_exists($request); < with this function you can ask the database if existing a specific value in a specific column declared in $request. You can only define 1 request!! > if_column_exists($requested_column); < you can ask the database if exists a specific column in table > if_table_exists(); < you can ask the database if exists a specific table in table > list_columns(); < you get the array of the list of columns in table > list_tables(); < you get the array of the list of tables of a database > number_columns(); < you can ask how many columns a table in table have > number_rows(); < you can ask how many rows a table in table have > after working with the database you should to stop the connection: stop(); */ // class database class database { var $name, $server, $user, $password; var $table, $conn, $result, $request; var $direction, $ordered, $rows_number; function database () { $this->name = "sciclubgardena_info"; $this->server = "localhost"; $this->user = "sciclub"; $this->password = "Hd_83Kdsh_shd"; $this->conn = $this->start(); $this->direction = "ASC"; } function start () { // connecting... $conn = @mysql_connect($this->server, $this->user, $this->password) or die ("Sorry, can't connect to database! Retry later ..."); @mysql_select_db($this->name, $conn) or die ("Cant' select database!"); return $conn; } function get_error () { if ($this->conn) return mysql_error($this->conn); } function cmd ($cmd) { $this->result = @mysql_query($cmd, $this->conn); return $this->result; } function put ($columns, $values) { $sql = "INSERT INTO $this->table ($columns) "; $sql .= "VALUES ($values)"; $this->result = @mysql_query($sql, $this->conn); return $this->result; } function get ($columns = "*") { $sql = "SELECT $columns FROM ".$this->table; $this->result = @mysql_query($sql, $this->conn); return $this->result; } function get_data_from_result () { if ($this->result) { $column_list = $this->list_columns_from_result(); $q = @mysql_num_rows($this->result); $data = array(); for ($x = 0; $row = @mysql_fetch_array($this->result, MYSQL_ASSOC); $x++) { for ($i = 0; $i < count($column_list); $i++) { $data[($column_list[$i])][$x] = $row[($column_list[$i])]; } } return $data; } return false; } function get_data ($columns = "*") { $this->result = $this->get($columns); if ($this->result) { if ($columns == "*") { $column_list = $this->list_columns(); } else { $columns = eregi_replace(" ", "", $columns); $column_list = explode(",", $columns); } $q = @mysql_num_rows($this->result); $data = array(); for ($x = 0; $row = @mysql_fetch_array($this->result, MYSQL_ASSOC); $x++) { for ($i = 0; $i < count($column_list); $i++) { $data[($column_list[$i])][$x] = $row[($column_list[$i])]; } } return $data; } return false; } function get_spec_data ($request, $columns = "*") { $sql = "SELECT ".$columns." FROM ".$this->table." WHERE ".$request; $this->result = $this->cmd($sql); return $this->get_data_from_result(); } function get_spec_data_ordered ($request, $ordered, $columns = "*") { $sql = "SELECT ".$columns." FROM ".$this->table." WHERE ".$request." ORDER BY ".$ordered." ".$this->direction; $this->result = $this->cmd($sql); return $this->get_data_from_result(); } function get_data_ordered ($ordered, $columns = "*") { $sql = "SELECT ".$columns." FROM ".$this->table." ORDER BY ".$ordered." ".$this->direction; $this->result = $this->cmd($sql); return $this->get_data_from_result(); } function if_value_exists ($request) { $sql = "SELECT * FROM ".$this->table." WHERE ".$request; $this->result = $this->cmd($sql); $value = $this->get_data_from_result(); $column = explode("=", $request); $column = trim($column[0]); if (count($value[$column]) > 0) { return true; } else { return false; } } function if_table_exists () { $table_list = $this->list_tables(); for ($a = 0; !empty($table_list[$a]); $a++) { if ($this->table == $table_list[$a]) return true; } return false; } function if_column_exists ($requested_column) { $list = $this->list_columns(); for ($i = 0; $i <= count($list); $i++) { if (trim($requested_column) == $list[$i]) { return true; } } return false; } function list_columns () { $sql = "SELECT * FROM ".$this->table; $this->result = @mysql_query($sql, $this->conn); if ($this->result) { $fields_q = @mysql_num_fields($this->result); $list = array(); for ($i = 0; $i < $fields_q; $i++) { $list[$i] = @mysql_field_name($this->result, $i); } return $list; } return false; } function list_columns_from_result () { if ($this->result) { $fields_q = @mysql_num_fields($this->result); $list = array(); for ($i = 0; $i < $fields_q; $i++) { $list[$i] = @mysql_field_name($this->result, $i); } return $list; } return false; } function list_tables () { $list = @mysql_list_tables($this->name); $tables_number = @mysql_num_rows($list); for ($i = 0; $i < $tables_number; $i++) { $list_ts[$i] = @mysql_tablename($list, $i); } return $list_ts; } function number_columns() { $this->number_columns = @mysql_num_fields($this->result); return $this->number_columns; } function number_rows() { if ($this->result) { $this->rows_number = @mysql_num_rows($this->result); return $this->rows_number; } return false; } function stop () { @mysql_free_result($this->result); // ... disconnecting @mysql_close($this->conn); } // FUNCTIONS FOR ADMINISTRATION function create_database () { $this->result = @mysql_create_db($this->name, $this->conn); return $this->result; } function add_column ($column) { $sql = "ALTER TABLE ".$this->table." ADD COLUMN ".$column; $this->result = $this->cmd($sql); return $this->result; } function change_column ($column, $new_column) { $sql = "ALTER TABLE ".$this->table." CHANGE ".$column." ".$new_column; $this->result = $this->cmd($sql); return $this->result; } function change_column_type ($column, $new_type) { $sql = "ALTER TABLE ".$this->table." MODIFY ".$column." ".$new_type; $this->result = $this->cmd($sql); return $this->result; } function delete_column ($column) { $sql = "ALTER TABLE ".$this->table." DROP ".$column; $this->result = $this->cmd($sql); return $this->result; } function delete_database () { $sql = "DROP DATABASE IF EXISTS $this->name"; $this->result = @mysql_query($sql, $this->conn); return $this->result; } function create_table ($table) { $sql = "CREATE TABLE ".$table; $this->result = @mysql_query($sql, $this->conn); return $this->result; } function rename_table ($table, $new_table) { $sql = "ALTER TABLE ".$table." RENAME AS ".$new_table; $this->result = $this->cmd($sql); return $this->result; } function delete_table ($table) { $sql = "DROP TABLE IF EXISTS ".$table; $this->result = @mysql_query($sql, $this->conn); return $this->result; } function list_databases () { $list = @mysql_listdbs($this->conn); $row_number = @mysql_num_rows($list); for ($i = 0; $i < $row_number; $i++) { $list_dbs[$i] = @mysql_tablename ($list, $i); } return $list_dbs; } function show_dbases($between = "
") { $list = list_dbases(); for ($i = 0; !empty($list[$i]); $i++) { echo $list[$i].$between; } } function if_dbase_exists ($dbase) { $dbase_list = $this->list_dbases(); for ($a = 0; !empty($dbase_list[$a]); $a++) { if ($dbase == $dbase_list[$a]) return true; } return false; } function show_tables ($between = "
") { $list = $this->list_tables(); for ($i = 0; !empty($list[$i]); $i++) { echo $list[$i].$between; } } function show_table_data () { $data = $this->get(); $this->show_table_data_from_result(); } function show_table_data_from_result () { if ($this->result) { $rows_number = @mysql_num_rows($this->result); $fields_number = @mysql_num_fields($this->result); echo "

Es sind $rows_number Datensätze gelesen worden, pro Reihe $fields_number Feld(er)!\n"; echo ""; for ($i = 0; $row_data = mysql_fetch_array($this->result, MYSQL_ASSOC); $i++) { echo ""; } echo "
"; echo @implode("",$row_data); echo "
"; $this->show_table_info(); return true; } return false; } function show_table_info () { $this->result = $this->get(); if ($this->result) { $fields_number = @mysql_num_fields($this->result); $rows_number = @mysql_num_rows($this->result); echo "

Die Tabelle '".$this->table."' hat ".$fields_number." Feld(er) und ".$rows_number." Datensa/ätz(e)
"; echo "Die Tabelle hat folgende Felder:
"; for ($i = 0; $i < $fields_number; $i++) { $type = @mysql_field_type($this->result, $i); $name = @mysql_field_name($this->result, $i); $len = @mysql_field_len($this->result, $i); $flags = @mysql_field_flags($this->result, $i); echo "[$type] $name ($len) $flags
"; } return true; } return false; } } ?>