MySQL additions and deletions to check changes

Source: Internet
Author: User
Tags rtrim

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

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.