码迷,mamicode.com
首页 > 其他好文 > 详细

数据访问类封装

时间:2017-05-15 10:09:44      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:定义   语句   访问   name   this   执行sql   oca   UI   roo   

<?php
class Wxk
{
	public $host="localhost";
	public $uid="root";
	public $pwd="123";
	public $dbname="Wxk";
	//执行SQL语句返回相应的结果
	//$sql 要执行的SQL语句
	//$type 代表SQL语句的类型,0代表增删改 1代表查询
	function query($sql,$type=1)
			{
				$db= new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
				$result= $db -> query($sql);
				if($type)
				{	
					//如果是查询,返回数据
					return $result->fetch_all();
				}
				else
				{
					//如果是增删改,返回true或false
					return $result;
				}
			}
		
	function strquery($sql,$type=1)
		{
			$db= new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
			$arry= $db -> query($sql);
			$arr =$arry->fetch_all();
			$str = "";//定义一个空的字符串
			foreach($arr as $v)
			{
				$str = $str.implode("-",$v)."|";//数组拼接字符串
			}
			$result = substr($str,0,strlen($str)-1);//删除多余的“|”
			return $result;//返回字符串
		}
}

 

数据访问类封装

标签:定义   语句   访问   name   this   执行sql   oca   UI   roo   

原文地址:http://www.cnblogs.com/yi11/p/6854808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!