<?php
Connecting to a database
Function connects ($host, $username, $password, $databaseName) {
$conn =mysql_connect ($host, $username, $password) or Die (' connection database failed ');
mysql_select_db ($databaseName);
mysql_query (' Set names UTF8 ');
return $conn;
}
Inquire
function Select_tb ($tables, $fields = ' * ', $where =1, $limits =0, $limite =1) {
$sql = "Select {$fields} from {$tables} where {$where} limit $limits, $limite";
$result =mysql_query ($sql);
$arr =array ();
while ($row =mysql_fetch_array ($result, Mysql_assoc)) {
$arr []= $row;
}
return $arr;
}
Get a piece of data
function GetOne ($tables, $fields = ' * ', $where =1) {
$sql = "Select {$fields} from {$tables} where {$where}";
$result = mysql_query ($sql) or Die (' Error executing SQL statement ');
return mysql_fetch_array ($result);
}
Delete
function Deletes ($tables, $where) {
$sql = "Delete from {$tables} where {$where}";
$result =mysql_query ($sql);
if ($result)
return true;
Else
return false;
}
Add to
function Insert ($tables, $keys, $values) {
$sql = "INSERT INTO {$tables} ({$keys}) VALUES ({$values})";
$result = mysql_query ($sql);
if ($result)
return true;
Else
return false;
}
Modify
function Updates ($tables, $where =null) {
$fields =rtrim ($fields, ', '); Remove the last comma in SQL
$where = $where ==null? ': ' Where '. $where;
$sql = "Update {$tables} set {$fields} {$where}";
$result =mysql_query ($sql);
if ($result)
return Mysql_affected_rows ();
Else
return false;
}
?>
SQL Add, delete, change, seal loading function