PHP connection MySQL Step

Source: Internet
Author: User

11.Write a PHP program to complete the display of the user table2 Code3<?PHP4        //MySQL Extension library operation MySQL database steps are as follows5 //1. Getting a connection6       7        $conn=mysql_connect("127.0.0.1", "root", "root");8        if(!$conn){9                die("Connection failed.")Mysql_error());Ten        } One        A        //2. Select a database -        mysql_select_db("Test"); -        //3. Set the Operation code (recommended)!!! the        mysql_query("Set names UTF8");//ensure that our PHP program is operated according to UTF8 code. - //4. Send instruction SQL (DDL data definition statement, DML (Data Manipulation language update INSERT, delete), DQL (select), DTL data transaction statement rollback commit ...)  -        $sql= "SELECT * from User1"; -        //function + //$res represent the result set, you can simply understand it as a table. -        $res=mysql_query($sql,$conn); +        //Var_dump ($res);//mysql result resource type A        at //5. Receives the returned result and processes it. (show) - //Mysql_fecth_row takes the next row of data from the $res result set in turn, assigning it to $row - //$row is an array, style array (5) {[0]=> string (1) "1" [1]=> string (2) "ZS" [2]=> string "e10adc3949ba59a bbe56e057f20f883e "[3]=> string (one)" [email protected] "[4]=> string (2)"} - //mysql_fetch_assoc mysql_fetch_array -                while($row=Mysql_fetch_row($res)){ -               //The first way is the same $row [$i] in //echo "<br/> $row [0]--$row [1]--$row [2]"; - //echo "<br/>"; to //var_dump ($row); + //second type of extraction -               foreach($row  as $key=$val){ the                      Echo"--$val"; *               } $               Echo"<br/>";
Mysql_free_result ($res); Freeing memory
Mysql_close ($conn); can write not write
Panax Notoginseng}

PHP connection MySQL Step

Related Article

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.