Skip to content

Instantly share code, notes, and snippets.

@anaelleltd
Created March 17, 2019 11:55
Show Gist options
  • Save anaelleltd/a8f6238d6a2bb9a6ebe919c011eccf4a to your computer and use it in GitHub Desktop.
Save anaelleltd/a8f6238d6a2bb9a6ebe919c011eccf4a to your computer and use it in GitHub Desktop.
Admin page
Task:
Use PDO to establish a connection to a MySQL server
Catch an exception with a try-catch statement
Use the exit function
Configure PDO for exception by calling the PDO object’s setAttribute method - p103 of text
Configure character encoding utf8
Set the output to say 'Unable to connect to the database server.' If cannot connect. And include the error message.
Set the output to say 'Database connection established.'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My PHP Admin</title>
<link rel="stylesheet" type="text/css" href="css/myphpadminstyle.css">
</head>
<body>
<div class="container">
<?php include"template/template_contents_myphpadmin.php"
?>
<?php
echo $header;
?>
<?php
echo $nav;
?>
<main>
<a name="maincontent"></a>
<aside> <div id="aside1">
<h2> PHP </h2>
<p> This is a controller page for My PHP Admin. This page should link with MySQL database called "mycompany". </p>
<img src="images/mysql.jpg" alt="MY SQL logo" width="300" height="230">
<p> Let's explore how to use PHP Data Object (PDO) with PHP and HTML! -_- </p></div>
</aside>
<section>
<h2> My PHP Admin </h2>
<h3> This is where the connection occurs.</h3>
<p> <?php include"dbmycompanyconnection.php"
?> </p>
</section>
</main>
<?php
echo $footer;
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment