Integration of the previous PHP database connection class ~ ~ made a page-like!_php Foundation

Source: Internet
Author: User
Tags learn php php database php database connection class prev
I do not know whether to learn PHP has a future ~ hey more write more boring

<?php
The start of Class Createdb//Classes
{
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; Execution of MySQL
var $row; Result set Find data
function Createconn ()//The class method is to start a conn connection and then start selecting the database
{
$this->conn = mysql_connect ($this->db, $this->dbname, $this->dbpwd);
mysql_select_db ($this->dbtable, $this->conn);
}
function Getresule ()//This is to get 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);
}
End of the}//class to begin invoking the class to read MySQL database data.
Debugging the code for the database connection! not needed.
/* $BB = new Createdb; Class instantiation
$BB->createconn ();//Call the connection of the class
$BB->mysql= "SELECT * from friends_conf";
$BB->getresule (); The calling class gets the result set
while ($bb->getrow ()) {//Call class creation pointer read the data forward and iterate,
Echo ($bb->row["Confname"]);
Echo ($bb->row["Confvalue"]);
}*/
?>
Pagination Class ~ Inherits the above method
<?php
Class Pagefy extends createdb{
var $nametatol; Total number of records
var $namemust = 1; The number of records you want to display on each page
var $pageall;
var $i = 1;
var $m;
var $p = 8; The page number that needs to be displayed;
var $a;
function Gettatol ()//Total number of records method
{//Connect to the database first
$this->nametatol = $this->row[0]; Total number of records
}
function GetPage ()//Total 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 ("<a href= ' pagefy.php?n= $this->i ' > $this->i</a>");
Echo (""); Want to show what style to add yourself
$this->i++;
$this->pageall = $this->pageall-1;
}
}
function Get_num_pl ()//Limit previous argument (start row number)
{
$this->m = $_get["n"] * $this->namemust-$this->namemust;
}
function showpage ()//display pagination content
{
$this->createconn ();
$this->mysql= "SELECT * from friends_conf limit $this->m, $this->namemust";
$this->getresule ();
while ($this->getrow ())
{
Echo ($this->row["Confname"]); You want to read out the fields and add yourself
Echo ($this->row["Confvalue"]);
}
}
function FirstPage ()//home
{
Echo ("<a href= ' pagefy.php?n=1 ' > Home <a>");
}
function Backpage ()//prev
{
if ($this->i = $_get["n"]-1)
{
Echo ("<a href= ' pagefy.php?n= $this->i ' > Prev <a>");
}
}
function nextpage ()//Next page
{
$this->i = $_get["n"] + 1;
if ($this->i <= $this->a)
{
Echo ("<a href= ' pagefy.php?n= $this->i ' > next page <a>");
}
}
function footpage ()//Last page
{
Echo ("<a href= ' pagefy.php?n= $this->a ' > Last page <a>");
}
}
?>
<?php//debug Section
$mm = new Pagefy;
$MM->createconn ();
$MM->mysql= "SELECT COUNT (*) from friends_conf";
$MM->getresule ();
$MM->closedatabase ();
$MM->getrow ();
$MM->gettatol ();
$MM->getpage ();
$MM-&GT;NUM_PL ();
$MM-&GT;GET_NUM_PL ();
$MM->showpage ();
$MM->closedatabase ();
$MM->firstpage ();
$MM->backpage ();
$MM->nextpage ();
$MM->footpage ();
?>
This class has been debugged! It's very easy to use ~~~~~~~~~~~~~~~~
The class is your knife ~ not in advance, difficult to wait until the fight time to refine AH!~ early dead ~ ~
All I'm free! Just write one aspect of the functional class ~~~~~~
I should say this kind of ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ not understand the question ~
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.