Description: This essay is the first time to learn PHP, simply make a note
1. Link database:
// connecting to a database $link mysql_connect ($host$user$pass); // sets the character encoding used by the current link mysql_query ("Set names ' UTF8 '");
2. Close the database link:
// Close the database link in $link above Mysql_close ($link);
3. PHP execution MySQL Query
// Select Database mysql_select_db ("Database name"// write MySQL query statement $res = mysql_query (' query statement '// for a query statement returns a resource handle, which is output in the form of an associative array and an indexed array
Mysql_fetch_array ($res// output var_dump($row// If there are multiple links, You can specify the link from which to query the $resmysql_query(' query statement ', the variable name of a connection);
4. Give a small example (link database, query all the data)
Database information:
Implementation code:
<?PHPHeader("Content-type:text/html;charset=utf-8"); /** There is a 20170222 database in the local database with a table named UserInfo **/ //Link Database $link=mysql_connect(' localhost ', ' root ', '); //to set the encoding that is currently in use mysql_query("Set names ' UTF8 '"); //Select Database mysql_select_db(' 20170222 '); //executes the first data in the MySQL statement//query table $sql= "SELECT * from UserInfo"; $res=mysql_query($sql); //output as an associative array and an indexed array $row=Mysql_fetch_array($res); //Output Var_dump($row); //Close Database Link Mysql_close($link);?>
Query Result:
This document is not perfect, such as found a bug, welcome message.
PHP Base--mysql Database