PHP Base--mysql Database

Source: Internet
Author: User

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

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.