PHP-----Simple Operations Database

Source: Internet
Author: User

PHP Operations Database

Querying data

First step: Build a connection

Variable name = @mysql_connect ("Server", "User name", "password");//@: Mask suppression hint

$a = mysql_connect ("Locslhost", "Root", "");

Step two: Select the database you want to manipulate

mysql_select_db ("Database name", connection);

mysql_select_db ("Ren", $a);

Step three: Write SQL statements

Variable name = "SELECT * from table name";

$b = "SELECT * from Daihao";

Fourth step: Execute SQL statement, return result set

Variable name = mysql_query (SQL statement);

$c = mysql_query ($b);

Fifth step: Reading data from the result set

while ($d = Mysql_fetch_row ($c))

{

Var_dump ($d);

}

Mysql_fetch_array () ———— indexed by column name

MYSQL_FETCH_ASSOC () ———— returns an associative array

Mysql_fetch_object () ———— return object

Mysql_fetch_row () ———— returns an indexed array

Delete and change data

First step: Build a connection

Variable name = @mysql_connect ("Server", "User name", "password");//@: Mask suppression hint

$a = mysql_connect ("Locslhost", "Root", "");

Step two: Select the database you want to manipulate

mysql_select_db ("Database name", connection);

mysql_select_db ("Ren", $a);

Step three: Write SQL statements

Variable name = "INSERT into table name values (' Value ', ' value ')";

$b = "INSERT into Daihao values (' n008 ', ' Dai ')";

Fourth step: Execute SQL statement, return result set

Variable name = mysql_query (SQL statement);

$c = mysql_query ($b);

Fifth step: Reading data from the result set

Var_dump ($c);

Example:

1. Add Data

Build a submission page first

Build another processing page (because it is a processing page, you can only have PHP code)

Show Results:

2. The following pull mode query display data

Show Results:

3. Delete data in list mode

Build a list page first

Build a Process page again

Show Results:

PHP-----Simple Operations Database

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.