PHP script database functions (3)

Source: Internet
Author: User
(Author: Wang Kaibo)
Accelerate PHP database development with classes
There are many database access functions. Improper use may reduce efficiency and even lead to errors. PHP itself is open and extensible, and many people develop the source code of various features for it. Every PHP programmer should be good at inheriting others' achievements and saving time and energy. Standing on the shoulders of giants can see farther. Of course, you can also share your code to realize the sense of accomplishment brought by your work being recognized and created.
The use of database classes allows us to focus on program development without having to consider specific database types.
Among the many development kits, PHPLib has stable performance and complete functions. PHPLib can be obtained in http://phplib.netuse.de. It contains database support classes. Take MySQL database as an example. PHPLib comes with a class named DB_ SQL. It encapsulates functions such as database connection, query, result fetch, and database table traversal.
The use of database classes allows us to focus on program development without having to consider specific database types. The program code does not need to be changed even if the database system type is changed. At the same time, the database class provides a complete and robust database access method, which may be the biggest advantage of using the class packaging.
Next, we will use the database class provided by PHPLib to access the database we just created and display the content.
<〈?
Require "db_mysql.php ";
// Generate a file containing the database class
$ Db = new DB_ SQL;
// Declare a database instance
$ Db-> connect ("ResumeDB", "localhost", "root ","");
// Connect to the database server
// The following parameters are provided: database name, host name, user name, and user password.
If ($ db-> Link_ID)
// Determine whether the connection is established correctly
{
$ Db-> query ("select ID, Name, Intro FROM Resume ");
// Query
If ($ db-> nf ())
// Determine whether the result set is null
{
While ($ db-> next_record ())
// Obtain the value of the next record until the record set content is obtained
{
Echo "ID:", $ db-> f ("ID"); // The f () function returns the value of a subsegment of the current record.
Echo "<br> 〉";
Echo "name :";
$ Db-> p ("Name ");
// The p () function directly prints the value of a sub-segment
// Equivalent to echo $ db-> f ("name ")
Echo "<br> 〉";
Echo "Introduction :";

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.