<?php
$db _host = "localhost:3306";
Database name
$db _name = "HX";
Database username
$db _user = "root";
Database Password
$db _pass = "";
$connect = mysql_connect ($db _host, $db _user, $db _pass, $db _name);
Mysql_set_charset (' UTF8 ');
Var_dump ($connect);
if (! $connect)
{
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ($db _name, $connect);
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 ($connect);
}
Insert, two parameters are required, after an array
function Insert ($table, $columns)
{
foreach ($columns as $key = $values)
{
$addkey. = '. $key. ' ', ';
if (Is_numeric ($values))
{
$addvalues. = $values. ', ';
}
Else
{
$values =mysql_real_escape_string ($values);
$addvalues. = ' \ '. $values. ' \‘,‘;
}
}
$addkey =rtrim ($addkey, ', ');
$addvalues =rtrim ($addvalues, ', ');
$inse = ' INSERT into ' $table. ' ('. $addkey. ') VALUES ('. $addvalues. '); ';
return mysql_query ($inse);
}
Update, three parameters are required
function Update ($table, $data, $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 ". $where;
return mysql_query ($UPDA);
}
Delete
function Delete ($table, $where)
{
$dele = "DELETE from". $table. " WHERE ". $where;
return mysql_query ($dele);
}
MySQL additions and deletions to check changes