MySQL additions and deletions to check changes

Source: Internet
Author: User
Tags rtrim

<?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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.