MySQL time function Use the MySQL database operation class from a nice message book

Source: Internet
Author: User
Tags explode mysql query
From a good message to get the MySQL database operation class, beginners PHP friends can refer to the next

Copy the Code code as follows:


Class mysql{
var $querynum = 0;
Function Connect ($dbhost, $dbuser, $DBPW, $dbname = ', $dbcharset = ') {
if (! @mysql_connect ($dbhost, $dbuser, $DBPW)) {
$this->show (' Can not connect to MySQL server ');
return false;
}
if ($dbname) {
$this->select_db ($dbname);
}
if ($this->version () > ' 4.1 ' && $dbcharset) {
$this->query ("SET NAMES". $dbcharset. "");
}
return true;
}
function select_db ($dbname) {
Return mysql_select_db ($dbname);
}
function Fetch_array ($query, $result _type = Mysql_assoc) {
Return @mysql_fetch_array ($query, $result _type);
}
function query ($sql, $type = ") {
if (! ( $query = mysql_query ($sql))) $this->show (' MySQL query Error ', $sql);
$this->querynum++;
return $query;
}
function Affected_rows () {
return Mysql_affected_rows ();
}
function result ($query, $row) {
Return mysql_result ($query, $row);
}
function Num_rows ($query) {
Return @mysql_num_rows ($query);
}
function Num_fields ($query) {
Return Mysql_num_fields ($query);
}
function Free_result ($query) {
Return Mysql_free_result ($query);
}
function insert_id () {
return mysql_insert_id ();
}
function Fetch_row ($query) {
Return mysql_fetch_row ($query);
}
Function version () {
return Mysql_get_server_info ();
}
function Close () {
return Mysql_close ();
}
Function error () {
return Mysql_error ();
}
Function Show ($message = ', $sql = ') {
if (! $sql) echo $message;
else echo $message. '
'. $sql. '
'. $this->error ();
}
}
Class Page extends mysql{
function pagination ($sql, $maxnum, $page, $maxpages, $pagepre, $ext = ') {
Global $sum, $stail, $link, $lmid, $ltail, $curpage;//$ext = ' &class=3 '
$SELF = $_server[' php_self ');
$query = $this->query ($sql);
$rows = $this->fetch_array ($query, mysql_num);
$totalrows = $rows [0];
$totalpages = Ceil ($totalrows/$maxnum);
$startnum = ($page-1) * $MAXNUM;
$string = $sum. $totalrows. $stail. $sum. $page. " /". $totalpages. $stail;
if ($page! = 1) {
$string. = $link. $SELF. "? Page=1 ". $ext. $lmid." | ‹ ". $ltail;
$string. = $link. $SELF. '? Page= '. ($page-1). $ext. $lmid. " ‹‹ ". $ltail;
}
if ($maxpages >= $totalpages) {
$pgstart = 1; $pgend = $totalpages;
}
ElseIf (($page-$pagepre -1+ $maxpages) > $totalpages) {
$pgstart = $totalpages-$maxpages + 1;
$pgend = $totalpages;
}
else{
$pgstart = (($page <= $pagepre)? 1: ($page-$pagepre));
$pgend = (($pgstart ==1)? $maxpages:($pgstart + $maxpages-1));
}
for ($pg = $pgstart; $pg <= $pgend; $PG + +) {
if ($pg = = $page) {
$string. = $curpage. $SELF. "? Page= ". $pg. $ext. $lmid. $pg. $ltail;
}
else $string. = $link. $SELF. "? Page= ". $pg. $ext. $lmid. $pg. $ltail;
}
if ($page! = $totalpages) {
$string. = $link. $SELF. '? Page= '. ($page + 1). $ext. $lmid. " ›› ". $ltail;
$string. = $link. $SELF. '? Page= '. $totalpages. $ext. $lmid. " ›| ". $ltail;
}
return $string;
}
}
function html ($str, $allowhtml =0) {
$str = GET_MAGIC_QUOTES_GPC () $str: Addslashes ($STR);
if (! $allowhtml) {$str = Htmlspecialchars ($STR);}
return $str;
}
function dehtml ($str, $allowhtml =0) {
$str = Stripslashes ($STR);
if (! $allowhtml) {$str = NL2BR ($STR);}
return $str;
}
function Deip ($STR) {
$arr = Explode ('. ', $str);
$STR = $arr [0]. '. '. $arr [1]. '. '. $arr [2]. *';
return $str;
}
function setting ($login =false) {
Global $db, $mydbpre;
if ($login) $sql = "Select * FROM {$mydbpre}setting";
else $sql = "Select * FROM {$mydbpre}setting where keyword! = ' username ' and keyword! = ' password '";
$query = $db->query ($sql);
while ($row = $db->fetch_array ($query)) {
$arr [$row [' keyword ']] = $row [' Val '];
if ($row [' keyword '] = = ' name ') $arr [' title '] = $row [' Val ']. '-Powered by Phpfans ';
}
return $arr;
}
function Checkcontent ($content) {
Global $db, $mydbpre, $mearr;
$arrword = $arrip = Array ();
$sql = "Select * FROM {$mydbpre}ban where B_type! = 0";
$query = $db->query ($sql);
while ($row = $db->fetch_array ($query)) {
if ($row [' b_type '] = = 1) $arrword [] = $row [' B_val '];
ElseIf ($row [' b_type '] = = 2) $arrip [] = $row [' B_reval '];
}
foreach ($arrip as $value) {
$value = Preg_quote ($value, '/');
$value = Str_replace (' \* ', ' \d{1,3} ', $value);
if (Preg_match ('/^ ('. $value. ') $/', $_server[' remote_addr ')) {
ShowMessage ($mearr [8], ' index.php ');
}
}
foreach ($arrword as $val) {
$val = Preg_quote ($val, '/');
if (Preg_match ('/'. $val. '/', $content)) {
ShowMessage ($mearr [7], ' index.php ');
}
}
}
function Replaceword ($content) {
Global $db, $mydbpre;
$sql = "Select * FROM {$mydbpre}ban where b_type = 0";
$query = $db->query ($sql);
while ($row = $db->fetch_array ($query)) {
$content = Str_replace ($row [' B_val '], $row [' B_reval '], $content);
}
return $content;
}
function Showadmin ($message, $referer = ") {
$str = ";
if ($referer! = ") $str. = ' ';
$str. = '








Information Tips
'. $message;
if ($referer! = ") $str. = '



If your page does not jump, please click here ';
$str. = '
';
Echo $str;
Exit
}
function ShowMessage ($message, $referer = ") {
Global $setting, $db;
$start = GetTime ();
Echo <<



<title>PHP Lover's Guestbook _ Prompt information</title>

EOT;
if ($referer! = ") echo ' ';
Echo <<


EoT;
require_once (' header.html ');
Echo <<
PHP enthusiast Guestbook message
{$message}
EoT;
if ($referer! =) {
echo <<

If your browser does not automatically jump, click here

EoT;
}
require_once (' footer.html ');
Echo <<


EOT;
Exit;
}
Function gettime ()
{
$t = explode ("", Microtime ());
return $t [1] + $t [0];
}
Function Checklogin ($exit =true) {
if (!isset ($_cookie[' islogin ']) | | $_cookie[' islogin ']! = 1) {
If ($exit) {
echo "Please login first, thank you. ";
Exit;
}
}
Else Setcookie (' IsLogin ', 1,time () +60*20);
}
?>

The above describes the MySQL time function using the MySQL database operation class from a good message book, including the use of MySQL time function content, I hope to be interested in PHP tutorial friends helpful.

  • 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.