zoukankan      html  css  js  c++  java
  • 数据访问类封装

    <?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;//返回字符串
    		}
    }
    
  • 相关阅读:
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    jchdl
    UVa 437 (变形的LIS) The Tower of Babylon
    UVa 1025 (动态规划) A Spy in the Metro
    UVa 10129 (并查集 + 欧拉路径) Play on Words
  • 原文地址:https://www.cnblogs.com/yi11/p/6854808.html
Copyright © 2011-2022 走看看