Php Framework Development 4 (DAO layer)

Source: Internet
Author: User
Php Framework Development 4 (DAO layer) website development inevitably needs to store some data, but the methods for storing the data in various languages are basically: first open the connection, then execute the SQL statement to get the final result and close the connection. So what methods does PHP use to operate databases? & Lt ;? Php $ connectmysql_connect ($ host, $ user, $ pass); mysql_select_db ($ db php Framework Development 4 (DAO layer)

Website development inevitably needs to store some data, but the methods for storing the data in various languages are basically: first open the connection, then execute the SQL statement, get the result, and close the connection.

So what methods does PHP use to operate databases?

 

You can use the preceding operations to operate databases. This is enough for the industry that embeds PHP scripts in HTML, but when we want to add, delete, modify, and query a large number of requests, we must reuse the preceding scripts multiple times. This mode will appear.

DAO http://blog.csdn.net/tomyjohn/article/details/7675770

The above pattern is implemented as the DAO layer for the moment, but the real significance lies in our MVC framework, which can be used to operate. Next we will create a new controller

  Title = 'title'; $ art-> content = 'content'; $ art-> save (); echo $ art-> id; view: show('index.htm ');}}


Create a new table named "si_article" in the database ",

DROP TABLE IF EXISTS `si_article`;CREATE TABLE `si_article` (  `id` int(8) NOT NULL AUTO_INCREMENT,  `title` varchar(255) DEFAULT NULL,  `content` text,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;


Create an "article. php" in the "modules" folder"

  

When we execute the controller above, we can see the ID of the newly inserted data.

In this way, we can easily implement an online message function.

Now, almost all MVC has been described. you can use it for development. of course, it is a complete but not rich MVC. There are still many things to consider. For example, paging, cache, and security. But this does not affect my love for this wheel.

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.