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