Test PHP page
This commit is contained in:
30
var/www/phptest.php
Normal file
30
var/www/phptest.php
Normal 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>
|
||||||
Reference in New Issue
Block a user