Test PHP page

This commit is contained in:
WilliamMiceli
2019-11-21 19:05:47 -05:00
parent fc37a58fb5
commit 102b847e48

30
var/www/phptest.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
//Step1
$db = mysqli_connect('localhost','root','','database_name')
or die('Error connecting to MySQL server.');
?>
<html>
<head>
</head>
<body>
<h1>PHP connect to MySQL</h1>
<?php
//Step2
$query = "SELECT * FROM contacts";
mysqli_query($db, $query) or die('Error querying database.');
//Step3
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['first_name'] . ' ' . $row['last_name'] . ': ' . $row['email'] . ' ' . $row['city'] .'<br />';
}
//Step 4
mysqli_close($db);
?>
</body>
</html>