1. Add the homepage index.php, the final suburb fruit:
1.1 Edit Homepage Content
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Joke Management System</title></Head><Body> <H1>Joke Management System</H1> <ul> <Li><ahref= "jokes/">Manage Jokes</a></Li> <Li><ahref= "authors/">Manage Authors</a></Li> <Li><ahref= "categories/">Manage Joke Categories</a></Li> </ul></Body></HTML>
2. Building the overall framework
3. Pre-preparation of the framework
3.1 Defining Access database operations
The site frequently accesses the database, we can encapsulate this piece of code.
include_once $_server [' Document_root ']. ' /php_mysql_web/includes/db.inc.php ';
db.inc.php file implementation, where Ijdb_user1 is the user name that accesses the database, and 123456 is the password.
<?PHPTry { $dsn= ' mysql:host=localhost;dbname=ijdb; '; $username= ' Ijdb_user1 '; $passwd= ' 123456 '; $pdo=NewPDO ($dsn,$username,$passwd); $pdo->setattribute (Pdo::attr_errmode, PDO::errmode_exception); $statement= ' SET NAMES ' UTF8 "'; $pdo-exec($statement); } Catch(pdoexception$e) { $error= ' Connect to database failed ... '.$e-GetMessage (); include' Error.html.php '; }
PHP and MySQL Web development from novice to expert, 4th day-Build basic framework