2006-11-23

MYSQL的操作类(已封装)

来源: CSDN 作者:熊毅 评论 0 条
 

//根据当前字段的类型生成相应的新值

if($this->sValue!="#@!")

$this->sValue.=",";

else

$this->sValue="";

$ftype=@mysql_field_type($this->nResult,$i);

//echo($ftype.",".$this->aNew[$i].",".$i.":".$sValue."<br>");

switch($ftype)

{

case "string":

case "date":

case "datetime":

$this->sValue.=""".$this->aNew[$tmpIn].""";

$this->sEdit=""".$this->aNew[$tmpIn].""";

break;

case "int":

case "unknown":

$this->sValue.=$this->aNew[$tmpIn];

$this->sEdit=$this->aNew[$tmpIn];

break;

default:

$this->nErr=1;

$this->sErr="Update:字段名为".$this->aFName[$tmpIn]."的".$ftype."类型目前版本不支持,请用别的方法添加数据!";

return;

}

if($this->NewEdit==2)

$this->sName.="=".$this->sEdit;

}

function Update() //存储新值到数据库

{

$strSQL="";

if($this->NewEdit==0)

{

$this->nErr=1;

$this->sErr="Update:请先执行AddNew()或者Edit(),再用SetValue()添加值!";

return;

}

if(empty($this->sValue))

{

$this->nErr=1;

$this->sErr="Update:在数据为空的情况下,不能添加或修改数据!";

return;

}

switch($this->NewEdit)

{

case 1: //添加

$strSQL="insert into ";

$strSQL.=$this->sTName;

$strSQL.=" (".$this->sName.") ";

$strSQL.="values (".$this->sValue.")";

break;

case 2: //修改

$strSQL="update ";

$strSQL.=$this->sTName;

$strSQL.=" set ";

$strSQL.=$this->sName;

if(!empty($this->sEditCon))

$strSQL.=" where ".$this->sEditCon;

break;

default:

$this->nErr=1;

$this->sErr="Update:Update()生成SQL语句出错,请检查!";

return;

}

$this->sSQL=$strSQL;

if(!$this->nResult=mysql_query($strSQL))

{

$this->nErr=1;

$this->sErr="Update:SQL语句:".$strSQL."<br><br>MySql错误:".mysql_error();

return;

}

//echo($this->sSQL."<br>");

//作清理工作

$this->NewEdit=0;

unset($this->aNew);

mysql_query("commit");

}

}


共5页: 上一页 [1] [2] [3] [4] 5 下一页
(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:程序员的灯下黑:坚持和良好心态近乎道  
下一篇:SQL SERVER日志清除的两种方法
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号