MySQL additions and deletions to check the basic statement

Source: Internet
Author: User

database links and selection and coding
$link =mysql_connect ("localhost", "root", "123456") or Die ("Database connection Failed". Mysql_error ()); Connecting to a database
$sel =mysql_select_db ("login", $link) or Die ("Database selection failed". Mysql_error ()); Select Database
mysql_query ("Set names ' UTF8 '"); Set Database encoding

Add Data
$link =mysql_connect ("localhost", "root", "123456") or Die ("Database connection Failed". Mysql_error ());
$sel =mysql_select_db ("login", $link) or Die ("Database selection failed". Mysql_error ());
mysql_query ("Set names ' UTF8 '", $sel);
$add = "INSERT INTO title" VALUES (' $title ', ' $content ', ' $username ', $time) ";
$query =mysql_query ($add);
if ($query) {
echo "Add sucess";
echo "<meta http-equiv=\" refresh\ "content=\" 1; Url=show_message.php\ "/>";
}
else echo "add false";

Delete Data
$link =mysql_connect ("localhost", "root", "123456") or Die ("Database connection Failed". Mysql_error ());
$sel =mysql_select_db ("login", $link) or Die ("Database selection failed". Mysql_error ());
mysql_query ("Set names ' UTF8 '");
$id =$_get[' id '];
$delete = "Delete from title where id= ' $id '";
$query =mysql_query ($delete);
if ($query) {
echo "Delete sucess!";
echo "<meta http-equiv=\" refresh\ "content=\" 1; Url=show_message.php\ "/>";
}
else echo "Delete false";

Change Data
$link =mysql_connect ("localhost", "root", "123456") or Die ("Database connection Failed". Mysql_error ());
$sel =mysql_select_db ("login", $link) or Die ("Database selection failed". Mysql_error ());
mysql_query ("Set names ' UTF8 '", $sel);
$update = "Update title set Title= '". $title. "', content= '". $content. "'
where id= ' $id ';
$query =mysql_query ($update);
if ($query) {
echo "Reset sucess!";
echo "<meta http-equiv=\" refresh\ "content=\" 1; Url=show_message.php\ "/>";
}
else echo "Reset false";

Check Data
$link =mysql_connect ("localhost", "root", "123456") or Die ("Database connection Failed". Mysql_error ());
$sel =mysql_select_db ("login", $link) or Die ("Database selection failed". Mysql_error ());
mysql_query ("Set names ' UTF8 '", $sel);
$sql = "SELECT * FROM table name: Limit 10";
$result =mysql_query ($sql);
while ($arr =mysql_fetch_array ($result, Mysql_assoc)) {
$rs [] = $arr; Put all the data in a two-bit array
or $arr = Mysql_fetch_array (); Take a bar


1. Select Query statements and conditional statements
Selectquery Fields fromTable namewhereconditions
Query fields: Wildcard characters can be used*, field name, field alias (Field nameAs ..)
Table Name: Database.table name, table name
Common conditions:=equals,<>not equal to,inch(value, value) contains, not in(value, value) does not contain, likeMatch
Betweenin the range,Not betweennot in range,<,>
Conditional budget: and,or, ()

2. Selectquery Fields fromTable namewhereconditions
(Group byfield grouping)
(Order byfields, FieldsAsc/descsort)
(Limitinitial value, end value pointer query)

3. SelectCalculation fromTable namewhereconditions
Count(*) Statistical Functions
Max(*) The maximum value function
Min(*) Minimum value function
Avg(*) Average
Sum(*) Accumulated value function

4. Fuzzy query (% represents 0 or more characters, _ represents 1 characters.) Like compare time, try to use less)

Like usage:
SELECT * FROM table name WHERE username like "$username%";
SELECT * FROM table name WHERE username like "% $username%";

In usage:
SELECT * FROM table name WHERE ID in (1, 2, 5, 9);

MySQL additions and deletions to check the basic statement

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.