PHP and MySQL Web development from novice to expert, 4th day-Build basic framework

Source: Internet
Author: User
Tags dsn php and mysql

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.