<?php $db _host = ' localhost:3306 '; $db _user = ' root '; $db _passwd = "; $db _name = ' Test ';
$conn = mysql_connect ($db _host, $db _user, $db _passwd); Mysql_set_charset (' UTF8 ');//Set Data font encoding if (! $conn) {die (' Could not connect: '. Mysql_error ()); } mysql_select_db ($db _name);//Select a connected datasheet
Query database functions function Select ($table, $where = ', $order = ', $limits = ', $field = ') {$field = ($field ==null)? ' * ': $field; $where = ($where ==null)? ': ' Where '. $where; $order = ($order ==null)? ': ' Order by '. $order; $limits = ($limits ==null)? ': ' LIMIT '. $limits; $sele = ' SELECT '. $field. ' From '. $table. $where. $order. $limits; return mysql_query ($sele); Mysql_close ($conn); Close Database Link
}
//Insert Database function, the second parameter must be an array function insert ($table, $columns) { foreach ($columns as $key = $values) { $addkey. = '. $key. ' ', '; if (Is_numeric ($values)) {//Judging is not for the number $addvalues. = $values. ', '; }else{ &NBSP ; $addvalues. = ' \ '. mysql_real_escape_string ($values). ' \‘,‘; Escape SQL statement characters } } &NBS P $addkey = RTrim ($addkey, ', '); Delete the specified character at the end of the string $addvalues = RTrim ($addvalues, ', '); &NB Sp $inse = ' INSERT into ' $table. ' ('. $addkey. ') VALUES ('. $addvalues. '); '; return mysql_query ($inse); &NBSP; Mysql_close ($conn); Close database links }
To update a database function, the second parameter must be an array function update ($table, $data, $where) {$where = ($where ==null)? ': ' Where '. $where; foreach ($data as $k = + $v) {if (Is_numeric ($v)) {$edit _data. = '. $k. '. ' = '. $v. ', '; }else{$edit _data. = ". $k. '. ' = '. ' ". Mysql_real_escape_string ($v). "',"; }} $edit _data = RTrim ($edit _data, ', '); $UPDA = ' UPDATE '. $table. ' SET '. $edit _data. $where; Var_dump ($UPDA); return mysql_query ($UPDA); Mysql_close ($conn); Close Database Link}
Delete database data functions function Delete ($table, $where) {$where = ($where ==null)? ': ' Where '. $where; $dele = ' DELETE from '. $table. $where; return mysql_query ($dele); Mysql_close ($conn); Close Database Link}
From for notes (Wiz)
MySQL additions and deletions to check changes