迷你mysql操作类

使用方法:

<?php

 require "gridtable.css"; 
 require "mydb_class.php";
 
 $DB = new mydb();
 $RS = new myrs();
 $DB->conn('localhost','root','root');
 $DB->open('caigou');
 $DB->query('SET NAMES UTF8');
 $DB->query('SELECT * from caigou');
 $RS->load($DB->rsl);
 $RS->maketable('class="gridtable"','title','lis');
 $DB->close();
?>

rsl = $rsl;
			$this->seek(0);
			$this->fld = @mysqli_num_fields($this->rsl)
				or die('无法解析记录集结构。');
			$this->finfo = @mysqli_fetch_fields($this->rsl)
				or die('无法解析记录集结构。');
				
		}
		
		function seek($recno) {
			@mysqli_data_seek($this->rsl,$recno)
				or die('无法移动记录集指针。');
			$this->fetch_row()
				or die('无法获取记录集表头结构。');			
		}
		
		function fetch_row() {
			$this->row = @mysqli_fetch_row($this->rsl);
			return $this->row;
		}
		
		function lis() {
			while($this->row) {
				$this->disp();
			}
		}
		
		function maketable(...$cmds) {
			$showcss = false;
			$showtit = false;
			$showlis = false;
			$strcss = '';
			
			foreach($cmds as $val) {
				if($val == 'title')	$showtit = true;
				if($val == 'lis')	$showlis = true;
				if(strpos($val,'class') !== false){
					$showcss = true;
					$strcss = $val;
				}
			}
			echo "title();
			if($showlis == true) $this->lis();
			echo "\n";
		}

		function title() {
			echo "\t
\n"; foreach ($this->finfo as $val) { echo "\t\t
".$val->name."
\n"; //if ($val->type==10) echo 'date'; } echo "\t\n"; } function disp() { echo "\t
\n"; for($i=0;$i<$this->fld;$i++) echo "\t\t
".$this->row[$i]."
\n"; echo "\t\n"; $this->fetch_row(); } } Class mydb { var $url; var $uid; var $pwd; var $tid; var $con; var $fun; var $rsl; function conn($url,$uid,$pwd) { $this->fun = 'conn'; $this->url = $url; $this->uid = $uid; $this->pwd = $pwd; $this->con = @mysqli_connect($this->url,$this->uid,$this->pwd) or $this->showerr('连接数据库失败。'); return $this->con; } function open($tid) { $this->fun = 'open'; $this->tid = $tid; @mysqli_select_db($this->con,$this->tid) or $this->showerr('无法打开库。'); } function close() { $this->fun = 'close'; @mysqli_close($this->con) or $this->showerr('在关闭数据库时发生错误。'); @mysqli_free_result($this->rsl); } function query($sql) { $this->fun = 'query'; $this->rsl = @mysqli_query($this->con,$sql) or $this->showerr('查询数据库失败。在命令:'.$sql); return $this->rsl; } function showerr($msg) { $this->fun = 'showerr'; echo '错误:'.$msg.'
'; die(-1); } } ?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值