————————————————————————————————————————————————————————————————————————————
"Go" PHP Module class reference
<?php
Database Connection Classes
Class conndb{
var $dbtype;
var $host;
var $user;
var $pwd;
var $dbname;
Construction method
function Conndb ($dbtype, $host, $user, $pwd, $dbname) {
$this->dbtype= $dbtype;
$this->host= $host;
$this->user= $user;
$this->pwd= $pwd;
$this->dbname= $dbname;
}
Implementing a connection to a database and returning a connection object
function Getconnid () {
if ($this->dbtype== "MySQL" | | $this->dbtype== "MSSQL") {
$DSN = "$this->dbtype:host= $this->host;dbname= $this->dbname";
}else{
$DSN = "$this->dbtype:dbname= $this->dbname";
}
try {
$conn = new PDO ($DSN, $this->user, $this->pwd); Initializes a PDO object, which is the creation of a database connection object $pdo
$conn->query ("Set names UTF8");
return $conn;
} catch (Pdoexception $e) {
Die ("error!:". $e->getmessage (). "<br/>");
}
}
}
Database Management Classes
Class admindb{
function Execsql ($SQLSTR, $conn) {
$sqltype =strtolower (substr (Trim ($SQLSTR), 0,6));
$rs = $conn->prepare ($SQLSTR); Preparing query statements
$rs->execute (); Executes a query statement and returns a result set
if ($sqltype = = "Select") {
$array = $rs->fetchall (PDO::FETCH_ASSOC); Get all the data in the result set
if (count ($array) ==0 | | $rs ==false)
return false;
Else
return $array;
}elseif ($sqltype = = "Update" | | $sqltype = = "Insert" | | $sqltype = = "Delete") {
if ($RS)
return true;
Else
return false;
}
}
}
Pagination class
Class seppage{
var $rs;
var $pagesize;
var $nowpage;
var $array;
var $conn;
var $sqlstr;
function ShowData ($sqlstr, $conn, $pagesize, $nowpage) {//Definition method
if (!isset ($nowpage) | | $nowpage = = "")//determine if the value of the variable is empty
$this->nowpage=1; Define the Start Page per page
Else
$this->nowpage= $nowpage;
$this->pagesize= $pagesize; Define the number of records per page output
$this->conn= $conn; Identity returned by the connection database
$this->sqlstr= $sqlstr; The query statement executed
$offset = ($this->nowpage-1) * $this->pagesize;
$sql = $this->sqlstr. "Limit $offset, $this->pagesize";
$result = $this->conn->prepare ($sql); Preparing query statements
$result->execute (); Executes a query statement and returns a result set
$this->array= $result->fetchall (PDO::FETCH_ASSOC); Get all the data in the result set
if (count ($this->array) ==0 | | $this->array==false)
return false;
Else
return $this->array;
}
function ShowPage ($contentname, $utits, $anothersearchstr, $anothersearchstrs, $class) {
$str = "";
$res = $this->conn->prepare ($this->sqlstr); Preparing query statements
$res->execute (); Executes a query statement and returns a result set
$this->array= $res->fetchall (PDO::FETCH_ASSOC); Get all the data in the result set
$record =count ($this->array); Total Statistics Records
$pagecount =ceil ($record/$this->pagesize); Calculate a total of several pages
$str. = $contentname. " ". $record. " ". $utits. " per page ". $this->pagesize. " ". $utits. " section ". $this->nowpage. " page/Total ". $pagecount. " page ";
$str. = " ";
if ($this->nowpage!=1)
$str. = "<a href=". $_server[' Php_self ']. "? Page=1&page_type= ". $anothersearchstr." ¶meter2= ". $anothersearchstrs." Class= ". $class." > Home </a> ";
Else
$str. = "<font color= ' #555555 ' > Home </font>";
$str. = " ";
if ($this->nowpage!=1)
$str. = "<a href=". $_server[' Php_self ']. "? Page= ". ($this->nowpage-1). " &page_type= ". $anothersearchstr." ¶meter2= ". $anothersearchstrs." Class= ". $class." > Prev </a> ";
Else
$str. = "<font color= ' #555555 ' > Prev </font>";
$str. = " ";
if ($this->nowpage!= $pagecount)
$str. = "<a href=". $_server[' Php_self ']. "? Page= ". ($this->nowpage+1). " &page_type= ". $anothersearchstr." ¶meter2= ". $anothersearchstrs." Class= ". $class." > Next </a> ";
Else
$str. = "<font color= ' #555555 ' > Next </font>";
$str. = " ";
if ($this->nowpage!= $pagecount)
$str. = "<a href=". $_server[' Php_self ']. "? Page= ". $pagecount." &page_type= ". $anothersearchstr." ¶meter2= ". $anothersearchstrs." Class= ". $class." > End </a> ";
Else
$str. = "<font color= ' #555555 ' > Last </font>";
if (count ($this->array) ==0 | | $this->array==false)
Return "No data! ";
Else
return $str;
}
}
System common methods
Class usefun{
function unhtml ($text) {
$content = (NL2BR (htmlspecialchars ($text)));
$content =str_replace ("[Strong]", "<strong>", $content);
$content =str_replace ("[/strong]", "</strong>", $content);
$content =str_replace ("[em]", "<em>", $content);
$content =str_replace ("[/em]", "</em>", $content);
$content =str_replace ("[U]", "<u>", $content);
$content =str_replace ("[/U]", "</u>", $content);
$content =str_replace ("[Font color= #FF0000]", "<font color= #FF0000 >", $content);
$content =str_replace ("[Font color= #00FF00]", "<font color= #00FF00 >", $content);
$content =str_replace ("[Font color= #0000FF]", "<font color= #0000FF >", $content);
$content =str_replace ("[Font face= Italic _gb2312]", "<font face= italic _gb2312>", $content);
$content =str_replace ("[Font face= Arial]", "<font face= new Song >", $content);
$content =str_replace ("[Font face= official script]", "<font face= script >", $content);
$content =str_replace ("[/font]", "</font>", $content);
$content =str_replace (CHR), "", $content);
$content =str_replace ("[Font size=1]", "<font size=1>", $content);
$content =str_replace ("[Font size=2]", "<font size=2>", $content);
$content =str_replace ("[Font size=3]", "<font size=3>", $content);
$content =str_replace ("[Font size=4]", "<font size=4>", $content);
$content =str_replace ("[Font size=5]", "<font size=5>", $content);
$content =str_replace ("[Font size=6]", "<font size=6>", $content);
$content =str_replace ("[Fieldset][legend]", "<FIELDSET><LEGEND>", $content);
$content =str_replace ("[/legend]", "</LEGEND>", $content);
$content =str_replace ("[/fieldset]", "</FIELDSET>", $content);
return $content;
}
}
?>
————————————————————————————————————————————————————————————————————————————
Excerpt from: http://www.cnblogs.com/adstat/p/3832819.html