前端一直使用PHP5,的确使用起来特别的爽,现在为了能在俺的虚拟主机上跑,不得不改成PHP4的。这几个库类我以前发在PHPCHIAN,地址是http://www.phpchina.com/bbs/viewthread.php?tid=5687&highlight=。(前几天在网上搜索了下,发现很多转载我的这几篇文章都没有说明出处,而且把我的版权都删除了,气晕了。)
昨天改写了数据库操作类,恰好在我简化zend Framework也能用到。
代码如下:
/**
* filename: DB_Mysql.class.php
* @package:phpbean
* @author :feifengxlq
* @copyright :Copyright 2006 feifengxlq
* @license:version 1.2
* create:2006-5-30
* modify:2006-10-19 by feifengxlq
* description:the interface of mysql.
*
* example:
* ////////////Select action (First mode)//////////////////////////////
$mysql=new DB_Mysql("localhost","root","root","root");
$rs=$mysql->query("select * from test");
for($i=0;$inum_rows($rs);$i++)
$record[$i]=$mysql->seek($i);
print_r($record);
$mysql->close();
* ////////////Select action (Second mode)//////////////////////////////
$mysql=new DB_Mysql("localhost","root","root","root");
$rs=$mysql->execute("select * from test");
print_r($rs);
$mysql->close();
* /////////////insert action////////////////////////////
$mysql=new DB_Mysql("localhost","root","root","root");
$mysql->query("insert into test(username) values('test from my DB_mysql')");
printf("%s",$mysql->insert_id());
$mysql->close();
*/
class mysql{
/* private: connection parameters */
var $host="localhost";
var $database="";
var $user="root";
var $password="";
/* private: configuration parameters */
var $pconnect=false;
var $debug=false;
/* private: result array and current row number */
var $link_id=0;
var $query_id=0;
var $record=array();
/**
* construct
*
* @param string $host
* @param string $user
* @param string $password
* @param string $database
*/
function __construct($host="localhost",$user="root",$password="",$database="")
{
$this->set("host",$host);
$this->set("user",$user);
$this->set("password",$password);
$this->set("database",$database);
$this->connect();
}
/**
* set the value for the param of this class
*
* @param string $var
* @param string $value
*/
function set($var,$value)
{
$this->$var=$value;
}
/**
* connect to a mysql server,and choose the database.
*
* @param string $database
* @param string $host
* @param string $user
* @param string $password
* @return link_id
*/
function connect($database="",$host="",$user="",$password="")
{
if(!empty($database))$this->set("database",$database);
if(!empty($host))$this->set("host",$host);
if(!empty($user))$this->set("user",$user);
if(!empty($password))$this->set("password",$password);
if($this->link_id==0)
{
if($this->pconnect)
$this->link_id=@mysql_pconnect($this->host,$this->user,$this->password);
else
$this->link_id=@mysql_connect($this->host,$this->user,$this->password);
if(!$this->link_id)
die("Mysql Connect Error in ".__FUNCTION__."():".mysql_errno().":".mysql_error());
if(!@mysql_select_db($this->database,$this->link_id))
die("Mysql Select database Error in ".__FUNCTION__."():".mysql_errno().":".mysql_error());
}
return $this->link_id;
}
/**
* query a sql into the database
*
* @param string $strsql
* @return query_id
*/
function query($strsql="")
{
if(empty($strsql)) die("Mysql Error:".__FUNCTION__."() strsql is empty!");
if($this->link_id==0) $this->connect();
if($this->debug) printf("Debug query sql:%s",$strsql);
$this->query_id=@mysql_query($strsql,$this->link_id);
if(!$this->query_id) die("Mysql query fail,Invalid sql:".$strsql.".");
return $this->query_id;
}
/**
* query a sql into the database,while it is differernt from the query() method,
* this method will return a record(array);
*
* @param string $strsql
* @param string $style
* @return $record is a array()
*/
function Execute($strsql,$style="array")
{
$this->query($strsql);
if(!empty($this->record))$this->record=array();
$i=0;
if($style=="array"){
while ($temp=@mysql_fetch_array($this->query_id)) {
$this->record[$i]=$temp;
$i++;
}
}else{
while ($temp=@mysql_fetch_object($this->query_id)) {
$this->record[$i]=$temp;
$i++;
}
}
unset($i);
unset($temp);
return $this->record;
}
/**
* seek,but not equal to mysql_data_seek. this methord will return a list.
*
* @param int $pos
* @param string $style
* @return record
*/
function seek($pos=0,$style="array")
{
if(!@mysql_data_seek($this->query_id,$pos))
die("Error in".__FUNCTION__."():can not seek to row ".$pos."!");
$result=@($style=="array")?mysql_fetch_array($this->query_id):mysql_fetch_object($this->query_id);
if(!$result) die("Error in ".__FUNCTION__."():can not fetch data!");
return $result;
}
/**
* free the result of query
*
*/
function free()
{
if(($this->query_id)&($this->query_id!=0))@mysql_free_result($this->query_id);
}
/**
* evaluate the result (size, width)
*
* @return num
*/
function affected_rows()
{
return @mysql_affected_rows($this->link_id);
}
function num_rows()
{
return @mysql_num_rows($this->query_id);
}
function num_fields()
{
return @mysql_num_fields($this->query_id);
}
function insert_id()
{
return @mysql_insert_id($this->link_id);
}
function close()
{
$this->free();
if($this->link_id!=0)@mysql_close($this->link_id);
if(mysql_errno()!=0) die("Mysql Error:".mysql_errno().":".mysql_error());
}
function select($strsql,$number,$offset)
{
if(empty($number)){
return $this->Execute($strsql);
}else{
return $this->Execute($strsql.' limit '.$offset.','.$number);
}
}
function __destruct()
{
$this->close();
$this->set("user","");
$this->set("host","");
$this->set("password","");
$this->set("database","");
}
}
?>
在此基础上,我顺便封装SIDU(select,insert,update,delete)四种基本操作,作为简化的zend Framework的module。代码如下(这个没写注释了,懒的写。。):
class module{
var $mysql;
var $tbname;
var $debug=false;
function __construct($tbname){
if(!is_string($tbname))die('Module need a args of tablename');
$this->tbname=$tbname;
$this->mysql=phpbean::registry('db');
}
function _setDebug($debug=true){
$this->debug=$debug;
}
function add($row){
if(!is_array($row))die('module error:row should be an array');
$strsql='insert into `'.$this->tbname.'`';
$keys='';
$values='';
foreach($row as $key=>$value){
$keys.='`'.$key.'`,';
$values.='\''.$value.'\'';
}
$keys=rtrim($keys,',');
$values=rtrim($values,',');
$strsql.=' ('.$keys.') values ('.$values.')';
if($this->debug)echo '
'.$strsql.'
';
$this->mysql->query($strsql);
return $this->mysql->insert_id();
}
function query($strsql){
return $this->mysql->Execute($strsql);
}
function count($where=''){
$strsql='select count(*) as num from `'.$this->tbname.'` ';
if(!empty($where))$strsql.=$where;
$rs=$this->mysql->Execute($strsql);
return $rs[0]['num'];
}
function select($where=''){
$strsql='select * from `'.$this->tbname.'` ';
if(!empty($where))$strsql.=$where;
return $this->mysql->Execute($strsql);
}
function delete($where=''){
if(empty($where))die('Error:the delete method need a condition!');
return $this->mysql->query('delete from `'.$this->tbname.'` '.$where);
}
function update($set,$where){
if(empty($where))die('Error:the update method need a condition!');
if(!is_array($set))die('Error:Set must be an array!');
$strsql='update `'.$this->tbname.'` ';
//get a string of set
$strsql.='set ';
foreach($set as $key=>$value){
$strsql.='`'.$key.'`=\''.$value.'\',';
}
$strsql=rtrim($strsql,',');
return $this->mysql->query($strsql.' '.$where);
}
function detail($where){
if(empty($where))die('Error:where should not empty!');
$rs=$this->mysql->query('select * from `'.$this->tbname.'` '.$where);
return $this->mysql->seek(0);
}
}
?>

使用windowshello中,找不到支持的摄像头,常见的原因是使用的摄像头不支持人脸识别、摄像头驱动安装不正确导致的,那么接下来让我们一起去看一下怎么去设置。windowshello找不到支持的摄像头教程:原因一:摄像头驱动安装不对1、一般来说Win10系统可以自动为大部分摄像头安装驱动程序,如下,插上摄像头之后会有通知;2、这时我们打开设备管理器看看,摄像头驱动是否安装好,没有的话就需要手动操作一下。WIN+X,然后选择设备管理器;3、设备管理器窗口中,展开照相机选项,会显示摄像头的驱动型号

PyCharm社区版支持的插件足够吗?需要具体代码示例随着Python语言在软件开发领域的应用越来越广泛,PyCharm作为一款专业的Python集成开发环境(IDE),备受开发者青睐。PyCharm分为专业版和社区版两个版本,其中社区版是免费提供的,但其插件支持相对专业版有所限制。那么问题来了,PyCharm社区版支持的插件足够吗?本文将通过具体的代码示例

华硕tufz790plus支持内存频率华硕TUFZ790-PLUS主板是一款高性能主板,支持双通道DDR4内存,最大支持64GB内存。它的内存频率非常强大,最高可达4800MHz。具体支持的内存频率包括2133MHz、2400MHz、2666MHz、2800MHz、3000MHz、3200MHz、3600MHz、3733MHz、3866MHz、4000MHz、4133MHz、4266MHz、4400MHz、4533MHz、4600MHz、4733MHz和4800MHz。无论是日常使用还是高性能需

开源软件的利与弊:了解开源项目的优劣势,需要具体代码示例在当今数字化时代,开源软件越来越受到关注和推崇。作为一种基于合作和分享精神的软件开发模式,开源软件在不同领域都有着广泛的应用。然而,尽管开源软件具有诸多优势,但也存在一些挑战和限制。本文将深入探讨开源软件的利与弊,并通过具体的代码示例展示开源项目的优劣势。一、开源软件的优势1.1开放性和透明性开源软件

如何使用Flask-Babel实现多语言支持引言:随着互联网的不断发展,多语言支持成为了大多数网站和应用的一个必要功能。Flask-Babel是一个方便易用的Flask扩展,它提供了基于Babel库的多语言支持。本文将介绍如何使用Flask-Babel来实现多语言支持,并附上代码示例。一、安装Flask-Babel在开始之前,我们需要先安装Flask-Bab

有一些用户使用xp系统,想要将他们的显卡升级为gtx960,但不确定gtx960是否支持xp系统。实际上,gtx960是支持xp系统的。我们只需在官网下载适用于xp系统的驱动程序,就可以使用gtx960了。下面让我们一起来看看具体的步骤吧。gtx960支持xp系统吗:GTX960可以与XP系统兼容。只需要下载并安装驱动程序,你就可以开始使用了。首先,我们需要打开NVIDIA官网并导航到主页。然后,我们需要在页面上方找到一个标签或按钮,它可能会被标记为“驱动程序”。一旦找到了这个选项,我们需要点击

大家都知道,要安装win11系统,需要确保电脑支持TPM2.0并开启安全启动。如果你的电脑安装win11失败,可能是因为安全启动未开启。以下是一些品牌电脑开启安全启动的教程,希望对你有所帮助。升级win11提示必须支持安全启动怎么办?一、华硕主板1、首先我们切换中文,然后根据提示按键盘的F7打开高级设置。3、然后选择其中的密钥管理。二、联想电脑1、2020年前的联想电脑型号,需要使用F2进入bios设置,然后在上方选中security。2、在security选项卡下降secureboot更改为E

如何使用Hyperf框架进行国际化支持随着全球化的快速发展,很多应用都需要具备多语言支持的功能,以满足不同国家和地区用户的需求。Hyperf框架作为一款轻量级的高性能框架,提供了国际化支持的功能,能够帮助开发者快速实现多语言应用的开发。本文将介绍如何在Hyperf框架中使用国际化功能,并提供相应的代码示例。一、配置多语言支持首先,需要在Hyperf的配置文件


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)