SQL language (add and revise)

Source: Internet
Author: User

As a front end must understand some basic database language, here I introduce a little simple SQL language.

The first is to increase:

1$mysql=new mysqli ("localhost", "root", "" "," H5class ");2$mysql -Query ("Setnames UTF8 ");3$sql="INSERT  intoHtml5class (Name,age)VALUES('Li Ming',' -')";4$result=$mysql -query ($sql);5 if($result) {6 echo "Success";7}Else{8 echo "Failure";9}

This code is the first to create a new Mysqli object, the parameters are the server's address, database user name, password, database name. There is another way to do this:

< ? PHP // Assume database user name: root, Password:123456, database: Runoob $con=mysqli_connect ("localhost", "root" , "123456", "Runoob");? >

This is localhost because we use a local server, the default user name is generally root. For the INSERT into database table name (field 1, Field 2, ...) VALUES (' Value 1 ', ' Value 2 ', ...)

Delete:

1$mysql=new mysqli ("localhost", "root", "" "," H5class ");2$mysql -Query ("Setnames UTF8 ");3$sql="DELETE  fromHtml5classWHEREName= 'Male Excellent'";4$result=$mysql -query ($sql);5 if($result) {6 echo "Delete succeeded";7}Else{8 echo "Delete failed";9}

Here is the DELETE from database table name where (condition).

Change:

1$mysql=new mysqli ("localhost", "root", "" "," H5class ");2$mysql -Query ("Setnames UTF8 ");3$sql="UPDATEHtml5classSETName= 'Male Excellent' WHEREAge=  - ";4$result=$mysql -query ($sql);5 if($result) {6 echo "Success";7}Else{8 echo "Failure";9}

This is where the UPDATE database table name SET is to be modified where the Where condition (that is, the row to modify/filter).

Inquire:

1$mysql=new mysqli ("localhost", "root", "" "," H5class ");2$mysql -Query ("Setnames UTF8 ");3$sql="SELECT *  fromHtml5classWHEREName= ' Millet'";4$result=$mysql -query ($sql);5 if($result) {6 echo "Query to";7}Else{8 echo "not queried";9}

Here is the SELECT * from database table name where condition. * Indicates all data, this can also be part of the data, such as:

SELECT  from WHERE  = "Millet";

These are basic database operations that can be built with these basic web sites.

SQL language (add and revise)

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.