位置: 编程技术 - 正文

mysql仿asp的数据库操作类(asp连接mysql数据库)

编辑:rootadmin
CODE:[复制到剪切板]<?php class MySQLDB { //MYSQL数据库操作类 //作者:熊毅 //版本:2.0(发行版) //可以自由转载,修改请通知我scxy@yeah.net //转载请保留以上声明 //上进行操作,当然也可以每次指定特殊的表进行操作 //nErr指示是否操作出错,sErr记录最后一次出错的错误代码,记录了明确的有哪个函数引起的错误 //错误之处请指正 //欢迎来信与我交流编程经验:scxy@yeah.net //我的CSDN:用户号:scxy;呢称:小熊,请多关照 //可以自由转载,修改请通知我scxy@yeah.net //转载请保留以上声明 var $host="localhost"; //主机名 var $user="boot"; //用户名 var $password="oaserver"; //用户密码 var $linkid; //连接值 var $dbid; //数据库选择的结果值 var $sTName; //指定当前操作的数据库表 var $sErr; //错误代码 var $nErr; //指示是否有错误存在,0无错误,1有错误 var $nResult; //查询结果值 var $aFName; //保存FieldsName的数组 var $nRows; //查询结果中的行数 var $nCols; //查询结果中的列数 var $aNew; //添加在AddNew函数后的数据,以数组形式保存 var $NewEdit; //判断当前是否在进行添加操作,0表示没有,1表示在进行添加,2表示编辑 var $sEditCon; //指定编辑记录的条件 var $nOffset; //记录偏移量 var $EOF; //标记是否到记录集尾 var $sSQL; //最后一条执行的SQL语句 //执行Update所要用到的全局变量 var $sName; //字段名 var $sValue; //字段值AddNew时用 var $sEdit; //字段值Edit时用 function Initialize() { $this->nErr=0; $this->NewEdit=0; $this->nResult=-1; $this->nCols=0; $this->nRows=0; $this->nOffset=0; $this->EOF=true; $this->sName=""; $this->sValue="#@!"; $this->sEdit="#@!"; unset($this->aFName); unset($this->aNew); } function MySqlDB($TableName="",$database="slt") //构造函数 { $this->Initialize(); $this->sTName=$TableName; $this->linkid=mysql_connect($host,$user,$password); if(!$this->linkid) { $this->nErr=1; $this->sErr="MySqlDB:数据库连接出错,请启动服务!"; return; } $this->dbid=mysql_select_db($database); if(!$this->dbid) { $this->nErr=1; $this->sErr="MySqlDB:选择的数据库".$database."不存在!"; return; } } function IsEmpty($Value) { if(is_string($Value)&&empty($Value)) return true; return false; } function Destroy() //数据清除处理 { mysql_query("commit"); mysql_close(); } function PrintErr() { if($this->nErr==1) { echo($this->sErr."<br><br>"); } else { echo("没有错误<br><br>"); } } function Execute($SQL) //直接执行SQL语句 { if(empty($SQL)) { $this->nErr=1; $this->sErr="Execute:执行语句不能为空!"; return false; } $this->sSQL=$SQL; if(!mysql_query($SQL)) { $this->nErr=1; $this->sErr="Execute:SQL语句:".$SQL."<br>MySql错误:".mysql_error(); return false; } return true; } function Query($TableName="",$SQL="*",$Condition="",$Order="",$Sequenc="") //在数据库里执行查询 { $this->Initialize(); if(!empty($TableName)) $this->sTName=$TableName; $strSQL="select ".$SQL." from ".$this->sTName; if(!empty($Condition)) $strSQL=$strSQL." where ".$Condition; if(!empty($Order)) $strSQL=$strSQL." order by ".$Order; if(!empty($Sequenc)) $strSQL=$strSQL." ".$Sequenc; $this->sSQL=$strSQL; if(!$this->nResult=mysql_query($strSQL)) { $this->nErr=1; $this->sErr="Query:SQL语句:".$strSQL."<br>MySql错误:".mysql_error()."<br>"; return; } $this->nOffset=0; $this->nRows=mysql_num_rows($this->nResult); $this->nCols=mysql_num_fields($this->nResult); if($this->nRows>0) $this->EOF=false; else $this->EOF=true; unset($this->aFName); $this->aFName=array(); for($i=0;$i<$this->nCols;$i++) $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i)); } function MoveNext() { if($this->EOF) { $this->nErr=1; $this->sErr="MoveNext:已经移到记录集末尾!"; return; } $this->nOffset++; if($this->nOffset>=$this->nRows) $this->EOF=true; } function MoveTo($Offset) { if(empty($Offset)) { $this->nErr=1; $this->sErr="MoveTo:必须指定偏移量! "; return; } if(!$this->nResult) { $this->nErr=1; $this->sErr="MoveTo:请先执行查询:Query"; return; } $this->nOffset=$Offset; } //得到指定行的指定列的值,返回字符串 //如果不指定Offset将取得下一行的值 //如果不指定nFields将取得该行的值,并已数组形式返回 function GetValue($nFields=-1,$Offset=-1) { if($this->nResult==-1) { $this->nErr=1; $this->sErr="GetValue:请先执行Query()函数!"; return; } if($Offset>-1) { $this->nOffset=$Offset; if($this->nOffset>=$this->nRows) { $this->nErr=1; $this->sErr="GetValue:所要求的偏移量太大,无法达到!"; return; } } if(!@mysql_data_seek($this->nResult,$this->nOffset)) { $this->nErr=1; $this->sErr="GetValue:请求不存在的记录!"; return; } $aResult=mysql_fetch_row($this->nResult); if(is_int($nFields)&&$nFields>-1) { if($nFileds>$this->nCols) { $this->nErr=1; $this->sErr="GetValue:所请求的列值大于实际的列值!"; return; } return $aResult[$nFields]; } if(is_string($nFields)) { $nFields=strtolower($nFields); for($i=0;$i<$this->nCols;$i++) { if($this->aFName[$i]==$nFields) break; } if($i==$this->nCols) { $this->nErr=1; $this->sErr="GetValue:所请求的列不存在,请仔细检查!"; return; } return $aResult[$i]; } return $aResult; } function AddNew($TableName="") //标志开始添加数据 { $this->Initialize(); if(!empty($TableName)) $this->sTName=$TableName; if($this->NewEdit>0) { $this->nErr=1; $this->sErr="AddNew:你正在对数据库进行添加或更新操作!"; return; } if(empty($this->sTName)) { $this->nErr=1; $this->sErr="AddNew:想要添加的数据库表为空,可以在构造时指定,也可在AddNew()时指定!"; return; } unset($this->aNew); $this->aNew=array(); $this->NewEdit=1; $strSQL="select * from ".$this->sTName; $this->sSQL=$strSQL; if(!$this->nResult=mysql_query($strSQL)) { $this->nErr=1; $this->sErr="AddNew:SQL语句:".strSQL."<br><br>MySql错误:".mysql_error(); return; } $this->nCols=mysql_num_fields($this->nResult); unset($this->aFName); $this->aFName=array(); for($i=0;$i<$this->nCols;$i++) $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i)); } function Edit($Condition="",$TableName="") //对指定数据库表进行编辑 { $this->Initialize(); if(!empty($TableName)) $this->sTName=$TableName; $this->sEditCon=$Condition; if(empty($this->sTName)) { $this->nErr=1; $this->sErr="Edit:在编辑前请先指定数据库表!"; return; } unset($this->aNew); $this->aNew=array(); $this->NewEdit=2; $strSQL="select * from ".$this->sTName; $this->sSQL=$strSQL; if(!$this->nResult=mysql_query($strSQL)) { $this->nErr=1; $this->sErr="Edit:SQL语句:".strSQL."<br><br>MySql错误:".mysql_error(); return; } $this->nCols=mysql_num_fields($this->nResult); unset($this->aFName); $this->aFName=array(); for($i=0;$i<$this->nCols;$i++) $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i)); } function SetValue($Index,$Value) //指定数据,跟在AddNew后执行; { if($this->NewEdit==0) { $this->nErr=1; $this->sErr="SetValue:请先执行AddNew()或者Edit()!"; return; } if(is_int($Index)) { if($Index<0||$Index>$this->nCols) { $this->nErr=1; $this->sErr="SetValue:插入不存在的列值!"; return; } $this->aNew[$Index]=$Value; $tmpIn=$Index; } elseif(is_string($Index)) { $Index=strtolower($Index); for($i=0;$i<$this->nCols;$i++) { if($this->aFName[$i]==$Index) break; } if($i==$this->nCols) { $this->nErr=1; $this->sErr="SetValue:插入不存在的列值!"; return; } $this->aNew[$i]=$Value; $tmpIn=$i; } if(!empty($this->sName)) $this->sName.=","; $this->sName.=$this->aFName[$tmpIn]; //根据当前字段的类型生成相应的新值 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"); } } ?>

推荐整理分享mysql仿asp的数据库操作类(asp连接mysql数据库),希望有所帮助,仅作参考,欢迎阅读内容。

mysql仿asp的数据库操作类(asp连接mysql数据库)

文章相关热门搜索词:asp与sql数据库连接,asp mssql,mysql as,mysql as,mysql as,asp+mysql,mysql as,asp+mysql,内容如对您有帮助,希望把文章链接给更多的朋友!

C#列出局域网中可用SQL Server服务器 SQLDMO由MicrosoftSQLServer自带的SQLDMO.dll提供,由于SQLDMO.dll是一个COM对象,所以大家在用之前必须在.NET项目中添加对它的引用。注意是添加COM引用,在列表

C#编写方法实例 开发应用程序逻辑1.在VisualStudio中打开MyDocuments文件夹下的MicrosoftPressVisualCSharpStepbyStepChapter3DailyRate子文件夹中的DailyRate项目。2.在解决方案资源管

mysql仿asp的数据库操作类 ?phpclassMySQLDB{//MYSQL数据库操作类//作者:熊毅//版本:2.0(发行版)查询数据时Query后可以用GetValue得到相应的值,既可以是字段名也可以是已0开始的序号

标签: asp连接mysql数据库

本文链接地址:https://www.jiuchutong.com/biancheng/319886.html 转载请保留说明!

上一篇:MySQL的语法及其使用指南(mysql中的语法)

下一篇:C#列出局域网中可用SQL Server服务器(c#获取局域网ip)

  • 按份共同保证和连带共同保证
  • 驾驶员培训服务税率
  • 对账结算流程
  • 小微企业所得税减免政策
  • 小规模纳税人利润如何缴税
  • 起重机属于固定资产哪个类别
  • 购买生产原料分录
  • 发票备注栏必须备注的有哪些
  • 跨越发票冲红,填了红字信息表,没有负数发票
  • 银行取钱需要签协议吗
  • 个人所得税申报是什么意思?
  • 信用评估费用收费标准
  • 已上传的红字发票怎么打印
  • 公司分红股需要交税吗
  • 境内公司取得境外收入
  • 购销合同印花税最新政策2023
  • 低值易耗品计入什么账户
  • 商品削价准备怎么算
  • 建总账的注意事项
  • 出口退税申报系统汇率修改
  • 品牌活动推广文案
  • 凭证单据的整理
  • 发票开出来对方不走账会怎么样?
  • 员工借款报销流程
  • 对方跨行转账成功后我却没收到款还能追回来吗
  • 保险合同有啥用
  • 发票入账后还能冲红吗
  • 专利代理服务费入账
  • 股东撤资退出
  • 如何手动更新目录
  • 华为手机屏幕下的三个功能键设置方法
  • win7桌面快捷键是什么
  • 胆固醇为什么会高
  • uniapp监听网络状态
  • php dechex
  • 现金折扣税务处理shi
  • 租入固定资产改建支出何时开始摊销
  • 什么情况需要缴纳增值税
  • thinkphp框架介绍
  • php实现base64图片上传方式实例代码
  • 补付转账支票会退回吗
  • 【手撕Transformer】Transformer输入输出细节以及代码实现(pytorch)
  • 蓝桥杯咋样
  • 退货可以开红字发票吗
  • 应付利息如何结转
  • 工业生产的含义
  • 退股东股本账务处理
  • 包装物押金销项税额的计算
  • 建筑企业会计科目的设置及核算
  • 电子发票开错了应该怎么办?
  • 金蝶财务软件怎么冲销费用
  • 公司收取保证金合法吗
  • 汽车销量多少才能赚钱
  • 外包食堂如何进货
  • 资源税会计科目
  • 税务稽查补缴上年所得税分录
  • 简易征收 简易计税
  • 流动比率计算公式是年初还是年末
  • 公司对公账户的钱怎么取出来
  • 新开的公司税务那边要办什么
  • 小规模转一般纳税人进项票如何处理
  • 备用金如何管理制度
  • 期初建账怎么做
  • 固定资产的折旧年限规定
  • 登记三栏式现金日记账和银行存款日记账的依据
  • xp系统任务栏太小怎么办
  • xp系统怎么取消自动关机
  • centos 怎么用
  • win7 手动输入用户名
  • 电脑找不到关机选项了怎么关机
  • windows10虚拟桌面
  • linux shell !
  • Win10 Mobile RedStone预览版14283更新内容汇总
  • shader cull
  • 游戏引擎有几种
  • python如何精确小数
  • html、css和jquery相结合实现简单的进度条效果实例代码
  • node.js使用教程
  • macbookair安卓系统怎么切换到苹果
  • 12366纳税服务热线存在的问题
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设