How to connect database basic statements in PHP

Source: Internet
Author: User

Just back-end modify the page, do not need to display the front end can delete the original code only input <?php start writing language can, later? > Can omit

Build a connection
$connect = @mysql_connect("localhost", "root", "123");//The statement is the simplest made connection statement, too old for PHP5, will remind the statement will be eliminated, so need to suppress the reminder

Select the database to manipulate
mysql_select_db ("Ren", $connect);

Write SQL statements
$sql = "select * from course"; Read all the contents of the course table

Execute SQL statement, return result set
$result = mysql_query($sql);

Reading data from the result set
while ($attr = Mysql_fetch_row($result))//row is read in indexed array format, assoc is read in associative array format, and array is read in two array formats
{
Var_dump ($ATTR);
}

Chinese garbled solution: cause the encoding format is inconsistent
1. When creating a database, the character set selection Utf-8
2. Modify the MySQL configuration and add the Character_set_srever=utf8 below the [mysqld] Module
3. The encoding format of the modified page is Utf-8,header ("Content-type:text/html;charset=utf-8");

Add data
Build a connection
/* $connect = @mysql_connect ("localhost", "root", "123");

Select the database to manipulate
mysql_select_db ("HR", $connect);

Write SQL statements
$sql = "insert into nation values (' n006 ', ' Tibetan ')"; The added data must be added in a regular manner

Execute SQL statement, return result set
$result = mysql_query ($sql);

Reading data from the result set
Var_dump ($result); */result is ture, add success, if False, add failed

How to connect database basic statements in PHP

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.