Integrated the PHP database connection class ~~ Create a paging class! _ PHP Tutorial

Source: Internet
Author: User
Tags php database connection class
Integrated the PHP database connection class ~~ Create a paging class !. I don't know if I want to learn PHP ~ Why is the write harder? The beginning of the phpClasscreatedb class {var $ dblocalhost; database address; var $ dbnameroot; user name; var $ dbpwd; password; var $ do not know whether PHP learning is promising ~ The more you write, the less boring you are.

Class createdb // Class start
{
Var $ db = "localhost"; // database address;
Var $ dbname = "root"; // user name;
Var $ dbpwd = ""; // password;
Var $ dbtable = "mysql"; // database used
Var $ conn; // database connection;
Var $ result; // result set
Var $ mysql; // The executed mysql
Var $ row; // Find data in the result set
Function createconn () // This class method is to start a conn connection, and then start to select a database
{
$ This-> conn = mysql_connect ($ this-> db, $ this-> dbname, $ this-> dbpwd );
Mysql_select_db ($ this-> dbtable, $ this-> conn );
}
Function getresule () // This is a result set.
{
$ This-> result = mysql_query ($ this-> mysql, $ this-> conn );
}
Function getrow () // create a forward result set pointer
{
$ This-> row = mysql_fetch_array ($ this-> result );
Return $ this-> row;
}
Function closedatabase ()
{
Mysql_close ($ this-> conn );
}
} // When the class ends, the class is called to read mysql database data.
// Debug the database connection code! Not required.
/* $ Bb = new createdb; // class instantiation
$ Bb-> createconn (); // call the connection of the class
$ Bb-> mysql = "select * from friends_conf ";
$ Bb-> getresule (); // call the class to obtain the result set.
While ($ bb-> getrow () {// call the class to create a pointer to read data in a forward read loop,
Echo ($ bb-> row ["confname"]);
Echo ($ bb-> row ["confvalue"]);
}*/
?>
// Paging class ~ Inherits the above method
Class pagefy extends createdb {
Var $ nametatol; // The total number of records
Var $ namemust = 1; // number of records to be displayed on each page
Var $ pageall;
Var $ I = 1;
Var $ m;
Var $ p = 8; // The page number to be displayed;
Var $;
Function gettatol () // method for retrieving the total number of records
{// Connect to the database first
$ This-> nametatol = $ this-> row [0]; // The total number of records
}
Function getpage () // Retrieve the total number of pages
{
$ This-> pageall = $ this-> nametatol % $ this-> namemust;
If ($ this-> pageall)
{
$ This-> pageall = (int) ($ this-> nametatol/$ this-> namemust) + 1;
Return $ this-> a = $ this-> pageall;
}
Else
{
Return $ this-> a = $ this-> pageall = (int) ($ this-> nametatol/$ this-> namemust );
}
}
Function num_pl () // page number display
{
$ This-> pageall = $ this-> pageall-($ this-> pageall-$ this-> p );
While ($ this-> pageall)
{
Echo ("I '> $ this-> I ");
Echo (""); // you can add the desired style
$ This-> I ++;
$ This-> pageall = $ this-> pageall-1;
}
}
Function get_num_pl () // The previous parameter of the LIMIT (start ROW number)
{
$ This-> m = $ _ GET ["n"] * $ this-> namemust-$ this-> namemust;
}
Function showpage () // display the page content
{
$ This-> createconn ();
$ This-> mysql = "select * from friends_conf limit $ this-> m, $ this-> namemust ";
$ This-> getresule ();
While ($ this-> getrow ())
{
Echo ($ this-> row ["confname"]); // add the field you want to read
Echo ($ this-> row ["confvalue"]);
}
}
Function firstpage () // home page
{
Echo ("homepage ");
}
Function backpage () // Previous Page
{
If ($ this-> I =$ _ GET ["n"]-1)
{
Echo ("I '> Previous Page ");
}
}
Function nextpage () // Next page
{
$ This-> I =$ _ GET ["n"] + 1;
If ($ this-> I <= $ this->)
{
Echo ("I '> Next Page ");
}
}
Function footpage () // The Last Page
{
Echo ("a'> last page ");
}
}
?>
$ Mm = new pagefy;
$ Mm-> createconn ();
$ Mm-> mysql = "select count (*) from friends_conf ";
$ Mm-> getresule ();
$ Mm-> closedatabase ();
$ Mm-> getrow ();
$ Mm-> gettatol ();
$ Mm-> getpage ();
$ Mm-> num_pl ();
$ Mm-> get_num_pl ();
$ Mm-> showpage ();
$ Mm-> closedatabase ();
$ Mm-> firstpage ();
$ Mm-> backpage ();
$ Mm-> nextpage ();
$ Mm-> footpage ();
?>
This class has been debugged! Very easy to use ~~~~~~~~~~~~~~~~
Class is your knife ~ It's hard to wait until the fight starts !~ Dead ~~
I'm free! Write a functional class ~~~~~~
It should be said that my class ~~ Relatively simple ~~~ Questions you cannot understand ~

Bytes ~ Why is the write harder? Php Classcreatedb // class start {var $ db = "localhost"; // database address; var $ dbname = "root"; // user name; var $ dbpwd = ""; // password; var $...

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.