PHP uses the MySQL database, from the establishment connection to the display of the results.
The complete code is as follows:
<?PHP//Connect to MySQL$db=mysql_connect("localhost", "root", "root");if(!$db) { die(' Could not connect: '.Mysql_error()); }//Create a databaseif(!mysql_query("CREATE DATABASE my_db",$db)) { Echo"Error Creating Database:".Mysql_error(); }//Select Databasemysql_select_db("my_db",$db);//Create a table$sql= "CREATE TABLE Persons (FirstName varchar (), LastName varchar (), age int)";mysql_query($sql,$db);//Inserting Datamysql_query("INSERT into Persons (FirstName, LastName, age) VALUES (' Peter ', ' Griffin ', ' + ')");mysql_query("INSERT into Persons (FirstName, LastName, age) VALUES (' Glenn ', ' Quagmire ', ' $ ')");//Create a result set$sql= "SELECT * FROM Persons";$result=mysql_query($sql); //displaying results in an HTML tableEcho"<table border= ' 1 ' ><tr><th>firstname</th><th>lastname</th><th>age </th></tr>"; while($rs=Mysql_fetch_array($result)) { Echo"<tr>"; Echo"<td>".$rs[' FirstName ']. "</td>"; Echo"<td>".$rs[' LastName ']. "</td>"; Echo"<td>".$rs[' Age ']. "</td>"; Echo"</tr>"; }Echo"</table>";//Close ConnectionMysql_close($db);?>
Note: Creating a database and building a table will only be done the first time.
Effect