Create dynamic web content
To demonstrate how easily we can create dynamic web pages that will connect to the database using PHP from the Nginx server, we will create a new PHP page in /var/www/html
. So fire up your favorite editor, and we will create the page within the document root, /var/www/html/db.php
:
<h2>Databases</h2> <?php $dbh=mysqli_connect("localhost","root","Password1"); $result=mysqli_query($dbh, "SHOW DATABASES"); while ($row = mysqli_fetch_assoc($result)) { echo $row['Database'] . "<BR>"; } ?>
The code again is kept as simple as possible, and ideally we would include the connection credentials stored within another file that was not accessible to the web server, allowing access only from the PHP process; however, keeping the code to a minimum does aide the learning process at this early stage.
In this PHP file, you can see that we mix a little HTML code with the PHP code, starting with heading tags before entering into...