PHP Script Database features detailed (3)

Source: Internet
Author: User
Tags contains ini mysql php database php script query access mysql database
Script | data | database | Detailed (author: Wang Kaibo)





use class to speed up PHP database development


database has more access functions, and improper use can reduce efficiency and even lead to errors. and PHP itself is open and extensible, many people for it to develop a variety of functional source code. Every PHP programmer should be good at inheriting the results of others and saving time and effort. Standing on the shoulders of giants to see farther. Of course, you can also share your code and experience the sense of accomplishment of your work being recognized and created value.





use of database classes allows us to focus on the development of a program without having to consider the specific database type at all.





a large number of development kits, Phplib is a more stable performance, the function of a more perfect one. Phplib can be obtained in http://phplib.netuse.de/. It contains the support classes for the database. Take the MySQL database as an example, Phplib with a class named Db_sql. It wraps the database connection, query, fetch result, database table traversal and so on function.





uses database classes, which allow us to focus on the development of the program without having to consider the specific database type at all. The program code does not have to change even if the database system type is changed. At the same time, database classes provide a complete and robust database access method, which may be the biggest advantage of using class wrappers.


below, we use the database class provided by Phplib to access the database we just created and display the content.





  〈?





require "db_mysql.php";





//contains build files for database classes





$db =new Db_sql;





//Declaring instances of a database class





$db-〉connect ("resumedb", "localhost", "root", "");





Connecting to the database server





//supplied parameters in order: Database name, host name, username, user password





if ($db-〉link_id)





//Determine if connection is properly established





  {





$db-〉query ("Select Id,name,intro from Resume");





//Query





if ($db-〉nf ())





//Determine whether the result set is empty





   {





while ($db-〉next_record ())





//Gets the next line of record value until the recordset content is finished





   {





echo "ID:", $db-〉f ("id"); The f () function returns the value of a child segment of the current record





echo "〈br〉";





echo "Name:";





$db-〉p ("Name");




The
//p () function prints the value of a child segment directly





//equivalent to echo $db-〉f ("name")





echo "〈br〉";





echo "Introduction:";





Echo $db-〉f ("Intro");





echo "〈br〉";





echo "〈a href= \ download.php?id=". $db-〉f ("ID"). " \ "View Word document 〈/a〉";





echo "〈br〉〈hr〉";





   }





   }





$db-〉free ();





//Free resources





  }





  ?〉





from the above process, we can see that the method of accessing the database by class is basically the same as that of accessing the database directly. The difference is that the method we call here is the method of the class, not the function specific to some kind of database. Because of the separation of the code and the specific database type, we do not need to change the program code when the database system changes, as long as we change the implementation method of the base class.





If you use the Phplib template to design, you can realize the separation between the program and the display. It will also make the structure of the program clear, Web page art design easy to make.





simple usage, reasonable task assignment, and thinking object packaging will make the website development efficiency greatly improved.





: Code test Platform


above program code all in the following platform test pass





RedHat Linux 6.1+apache1.3.12+





php4.0+mysql3.22.32




The installation configuration process for the
database is:





cd/usr/local/src/mysql*





./configure--refix=/usr/local/mysql





make





make install




The
Apache installation configuration process is:





cd/usr/local/src/apache*





./configure--prefix=/usr/local/apache--enable-shared=max





make





make install





PHP Installation configuration process is:





cd/usr/local/src/php*





./configure--with-apxs=/usr/local/apache/bin/apxs \





--with-config-file-path=/usr/local/





apache/conf \





--with-mysql=/usr/local/mysql \





--enable-debug=no \





--enable-track-vars




The
php.ini configuration process is:





copy php.ini-dist to/usr/local/





Apache/conf/php.ini





Edit httpd.conf and remove the comments from the two lines below





addtype application/x-httpd-php. php. PhP3





AddType application/x-httpd-php-source. Phps





<< Full finished >>








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.