欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

很好用的PHP數(shù)據(jù)庫類

 更新時間:2009年05月27日 17:34:30   作者:  
很好用的PHP數(shù)據(jù)庫類,三、四句代碼搞定一個表的操作,無論這個表字段有多復雜。
復制代碼 代碼如下:

<?
//很好用的PHP數(shù)據(jù)庫類,三、四句代碼搞定一個表的操作,無論這個表字段有多復雜。
//此類多次大量用在大型網(wǎng)站程序的開發(fā)上,效果特別的好。
//作者:快刀浪子++ 
define(\"_PHP_RECORD_\",\"exists\");
class TRecord
{
var $db;
var $rc;
var $name;
var $value;
var $num;
var $buffer;   //查詢結(jié)果 調(diào)用方法 $buffer[$i][\"fields\"];
var $seekstr;   //保存查詢條件用
function TRecord($host=\"localhost\",$user=\"root\",$passwd=\"\")
{global $HTTP_POST_VARS;
$this->num=0;
$this->host=$host;
$this->user=$user;
$this->passwd=$passwd;
if(($this->db=mysql_connect($host,$user,$passwd))==false)
exit(\"聯(lián)結(jié)數(shù)據(jù)庫出錯!\");
  while(list($this->name[$this->num],$this->value[$this->num])=each($HTTP_POST_VARS))
{$this->num++;
}
//////////////
for($i=0;$i<$this->num;$i++)
{$this->value[$i]=$this->SafeString($this->value[$i]);
}
//
}
function SafeString($message)
{$message=str_replace(\" \",\" \",$message);
$message=str_replace(\"<\",\"<\",$message);
$message=str_replace(\">\",\">\",$message);
//$message=str_replace(\"|\",\"|\",$message);
//$message=str_replace(\"\\"\",\""\",$message);
//$message=nl2br($message);
return $message;
}
//////
function reset()
{$this->num=0;
$this->name=array();
   $this->value=array();
}
function add($name,$values)
{$this->name[$this->num]=$name;
   $this->value[$this->num]=$values;
$this->num++;
}
function unadd($name)
{$j=0;
for($i=0;$i<$this->num;$i++)
{if($this->name[$i]!=$name)
{$aaa[$j]=$this->name[$i];
$bbb[$j]=$this->value[$i];
$j++;
}
}
$this->name=$aaa;
$this->value=$bbb;
$this->num=$j;
}
function InsertRecord($database,$table)
{mysql_select_db($database);
if($this->num==0)
exit(\"沒有定義變量!\");
$field=implode(\",\",$this->name);
for($i=0;$i<$this->num;$i++)
{if(is_string($this->value[$i]))
$ls[$i]=\"\'\".$this->value[$i].\"\'\";
 else
$ls[$i]=$this->value[$i];
     $value=implode(\",\",$ls);  
}
$sql=sprintf(\"insert into %s(%s) values(%s)\",$table,$field,$value);
if(mysql_query($sql,$this->db)==false)
{echo \"寫數(shù)據(jù)到數(shù)據(jù)庫時出錯:\".$sql;
exit();
}
}
function SelectRecord($database,$table) //返回記錄數(shù),結(jié)果在緩沖區(qū)中
{mysql_select_db($database);
    if($this->num==0)
$sql=sprintf(\"select * from %s\",$table);
 else
{
for($i=0;$i<$this->num;$i++)
{if(is_string($this->value[$i]))
$ls[$i]=\"\'\".$this->value[$i].\"\'\";
   else
$ls[$i]=$this->value[$i];
$str[$i]=sprintf(\"%s=%s\",$this->name[$i],$ls[$i]);
}
$string=implode(\" and \",$str);
$this->seekstr=$string;
$sql=sprintf(\"select * from %s where %s\",$table,$string);
}
if(($rc=mysql_query($sql,$this->db))==false)
{echo \"查詢數(shù)據(jù)庫時出錯:\".$sql;
exit();
}
$i=0;
while($this->buffer[$i]=mysql_fetch_array($rc))
{
$i++;
}
mysql_free_result($rc);
return $i;
}
function UpdateRecord($database,$table,$limitstr)
{mysql_select_db($database);
if($this->num==0)
exit(\"沒有定義變量!\");
for($i=0;$i<$this->num;$i++)
{if(is_string($this->value[$i]))
$ls[$i]=\"\'\".$this->value[$i].\"\'\";
 else
$ls[$i]=$this->value[$i];
$upstr[$i]=$this->name[$i].\"=\".$ls[$i];
}
    $str=implode(\",\",$upstr);
$sql=sprintf(\"update %s set %s where %s\",$table,$str,$limitstr);
if(mysql_query($sql,$this->db)==false)
{echo \"修改數(shù)據(jù)時出錯:\".$sql;
exit();
}
}
function addtip($database,$table,$fileds,$limitstr=\"\")
{//必須為整型字段 
mysql_select_db($database);
if($limitstr!=\"\")
$sql=sprintf(\"update %s set %s=%s+1 where %s\",$table,$fileds,$fileds,$limitstr);
 else
$sql=sprintf(\"update %s set %s=%s+1\",$table,$fileds,$fileds);
if(mysql_query($sql,$this->db)==false)
{echo \"修改數(shù)據(jù)時出錯:\".$sql;
exit();
}
}
function unaddtip($database,$table,$fileds,$limitstr=\"\")
{
mysql_select_db($database);
if($limitstr!=\"\")
$sql=sprintf(\"update %s set %s=%s-1 where %s\",$table,$fileds,$fileds,$limitstr);
 else
$sql=sprintf(\"update %s set %s=%s-1\",$table,$fileds,$fileds);
if(mysql_query($sql,$this->db)==false)
{echo \"修改數(shù)據(jù)時出錯:\".$sql;
exit();
}
}
function isempty($var,$china)
{if(trim($var)==\"\")
{
$reason=\"沒有錄入“\".$china.\"”!\";
exit($reason);
}
}
function GetResult()
{return $this->buffer;
}
function close()
{
mysql_close($this->db);
}
}
?>

相關(guān)文章

  • 提交表單后 PHP獲取提交內(nèi)容的實現(xiàn)方法

    提交表單后 PHP獲取提交內(nèi)容的實現(xiàn)方法

    下面小編就為大家?guī)硪黄峤槐韱魏?PHP獲取提交內(nèi)容的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05
  • PHP命令空間namespace及use的用法小結(jié)

    PHP命令空間namespace及use的用法小結(jié)

    命名空間一個最明確的目的就是解決重名問題,PHP中不允許兩個函數(shù)或者類出現(xiàn)相同的名字,否則會產(chǎn)生一個致命的錯誤。這篇文章主要介紹了PHP命令空間namespace及use的用法實踐總結(jié),需要的朋友可以參考下
    2017-11-11
  • 淺析php適配器模式(Adapter)

    淺析php適配器模式(Adapter)

    本文講解的是php設(shè)計模式的結(jié)構(gòu)性模式的概念以及機構(gòu)性模式的七種類中的適配器模式,需要的朋友可以參考下
    2014-11-11
  • LotusPhp筆記之:基于ObjectUtil組件的使用分析

    LotusPhp筆記之:基于ObjectUtil組件的使用分析

    學習要先易后難,好吧,我剛開始學習LotusPhp的時候,就是從最容易的Logger和ObjectUtil開始的,這2個組件基本沒有什么難度。一看就會
    2013-05-05
  • thinkPHP中_initialize方法實例分析

    thinkPHP中_initialize方法實例分析

    這篇文章主要介紹了thinkPHP中_initialize方法,結(jié)合實例形式分析了子類調(diào)用父類_initialize方法的原理與相關(guān)操作技巧,需要的朋友可以參考下
    2016-12-12
  • Yii視圖CGridView列表用法實例分析

    Yii視圖CGridView列表用法實例分析

    這篇文章主要介紹了Yii視圖CGridView列表用法,結(jié)合實例形式分析了CGridView列表的視圖及功能實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • TP5框架實現(xiàn)的數(shù)據(jù)庫備份功能示例

    TP5框架實現(xiàn)的數(shù)據(jù)庫備份功能示例

    這篇文章主要介紹了TP5框架實現(xiàn)的數(shù)據(jù)庫備份功能,結(jié)合實例形式分析了TP5數(shù)據(jù)庫備份功能相關(guān)原理及實現(xiàn)方法,需要的朋友可以參考下
    2020-04-04
  • PHP兩種去掉數(shù)組重復值的方法比較

    PHP兩種去掉數(shù)組重復值的方法比較

    這篇文章主要介紹了PHP兩種去掉數(shù)組重復值的方法比較,分別是foreach方法和array_unique方法,需要的朋友可以參考下
    2014-06-06
  • PHP函數(shù)in_array()使用詳解

    PHP函數(shù)in_array()使用詳解

    這篇文章主要介紹了PHP函數(shù)in_array()使用詳解,分別對普通使用、使用第三個參數(shù)、克隆對象、多維數(shù)組等給出了例子,需要的朋友可以參考下
    2014-08-08
  • 詳解PHP中的null合并運算符

    詳解PHP中的null合并運算符

    這篇文章主要介紹了PHP中的null合并運算符的相關(guān)資料,需要的朋友可以參考下
    2015-12-12

最新評論