1. 添加首页index.php,最终郊果 如图:
1.1 编辑首页内容
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Joke Management System</title> </head> <body> <h1>Joke Management System</h1> <ul> <li><a href="jokes/">Manage Jokes</a></li> <li><a href="authors/">Manage Authors</a></li> <li><a href="categories/">Manage Joke Categories</a></li> </ul> </body> </html>
2. 搭建总体框架
3. 框架的前期准备
3.1 定义访问数据库操作
站点中经常访问数据库,我们可以把此段代码封装起来.
include_once $_SERVER[‘DOCUMENT_ROOT‘].‘/PHP_MySQL_Web/includes/db.inc.php‘;
db.inc.php文件实现,其中ijdb_user1是访问数据库的用户名,123456是密码.
<?php try { $dsn = ‘mysql:host=localhost;dbname=ijdb;‘; $username = ‘ijdb_user1‘; $passwd = ‘123456‘; $pdo = new PDO($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‘; }
时间: 2024-11-06 17:01:52