封装php连接数据库返回方法

<?phpclass fengzhuang
{public $host="localhost";public $uid="root";public $pwd="159357";public $sjkname="yuheng";//返回二维数组    function query($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type==1){return $reslut->fetch_all();}else{return $reslut;}}//返回关联数组function glquery($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type==1){$attr = array();while($a = $reslut->fetch_assoc())        //取一条
            {$attr[] = $a;}return $attr;}else{return $reslut;}}//返回接字符串function strquery($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type=1){$attr = $reslut->fetch_all();        //二维数组不能用implode$str = "";foreach($attr as $v){$str .= implode("^",$v);$str .= "|";}return substr($str,0,strlen($str)-1);}else{return $reslut;}}
}

 

转载于:https://www.cnblogs.com/u1020641/p/6416470.html

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注