PHP uses MySQL, from connection, creation, to display of results
1<?PHP2 //Connect MySQL test3 $db=mysql_connect("localhost", "root", "Wenwen");4 if(!$db)5 {6 die(' Could not connect: '.Mysql_error());7 }8 Else9 {Ten Echo"Connect success!"; One } A - //Create a database - if(!mysql_query("CREATE DATABASE my_db",$db)) the { - Echo"Error Creating Database:".Mysql_error(); - } - + //Select Database - mysql_select_db("my_db",$db); + A //Create a table at $sql= "CREATE TABLE Persons - ( - FirstName varchar (), - LastName varchar (), - Age int -)"; in mysql_query($sql,$db); - to //Inserting Data + mysql_query("INSERT into Persons (FirstName, LastName, age) -VALUES (' Jordan ', ' Michael ', ' 51 ')); the mysql_query("INSERT into Persons (FirstName, LastName, age) *VALUES (' Bryant ', ' Kobe ', ' 36 ')); $ Panax Notoginseng //Create a result set - $sql= "SELECT * FROM Persons"; the $result=mysql_query($sql); + A //displaying results in an HTML table the Echo"<table border= ' 1 ' > + <tr> - <th>FirstName</th> $ <th>LastName</th> $ <th>Age</th> -</tr> "; - the while($rs=Mysql_fetch_array($result)) - {Wuyi Echo"<tr>"; the Echo"<td>".$rs[' FirstName ']. "</td>"; - Echo"<td>".$rs[' LastName ']. "</td>"; Wu Echo"<td>".$rs[' Age ']. "</td>"; - Echo"</tr>"; About } $ Echo"</table>"; - - //Close Connection - Mysql_close($db); A?>
Run effect
Changes in the DB