Basic knowledge of PHP Operational database
1: Set the header to UTF-8 encoding to prevent garbled.
Header ("Content-type:text/html;charset=utf-8");
2: There are several steps to connecting a database
1: First step, connect to MySQL server
$conn =mysql_connect ("localhost", "root", "12345"); If the [email protected] symbol is in front, the error message is ignored.
You can also use Die () to display the connection failure information.
@mysql_connect ("localhost", "root", "12345") or Die (' Database connection failed '. Mysql_error ());
2: The second step, when we use the mysql_connect () function to connect to the database successfully, we need to select the db of the database
mysql_select_db (database name);
mysql_select_db (school) or Die (' This database not found '. Mysql_error ());
mysql_query ("Set names UTF8"); Set the character set of the database
3: The third step, select the table from the connected database, and get the table data, that is, prepare the statement
$query = "SELECT * Form Class";
$result =mysql_query ($query);
4: Fourth step, display the data in the recordset
Mysql_fetch_array ($result);
5: The last step, close the database
Mysql_close ($conn)
3:php MySQL additions and deletions to the search
Prepare database statements: $query =insert into Class (Name,age,sex) VALUES (' Cary ', ' 29 ', ' Male ');
Execute database mysql_query ($query);
Change: $query = "Update class set age=40 where Name= ' Cary '";
mysql_query ($query);
Delete: $query = "Delete from class where name= ' Cary '";
mysql_query ($query);
Query: $query = "Select Name,age,sex from Class";
$result =mysql_query ($query);
while ($row =mysql_fetch_array ($result)) {
echo $row [' name ']
}
In this way, we store the queried statements in the variable $result result set.
Some of the functions commonly used in 4:php
Mysql_fetch_array ()----Get data
This article is from the "Cary_qin blog" blog, make sure to keep this source http://xpqinqun.blog.51cto.com/2136/1605353
PHP basic methods of manipulating MySQL