php常用功能封装-Mysql操作

  • A+
所属分类:阁主小札
class DBconn
{
    public $link;
    public function __construct($user = "", $pass = "", $dbName = "", $host = "localhost")
    {
        $this->link = mysqli_connect($host, $user, $pass, $dbName);
        mysqli_query($this->link, "SET NAMES utf-8");
    }

    public function find($sql) //单个查询

    {
        return $res = mysqli_fetch_array(mysqli_query($this->link, $sql));
    }
    public function findAll($sql) //多个查询

    {
        return $res = mysqli_fetch_all(mysqli_query($this->link, $sql));
    }
    public function query($sql) //执行普通SQL

    {

        return $res = mysqli_query($this->link, $sql);

    }

    public function showErr() //返回最近的错误信息

    {
        return array(
            "code" => mysqli_errno($this->link),
            "msg"  => mysqli_error($this->link),
        );
    }
}
weinxin
画麟阁QQ群
这是一个有爱的大家庭,也是东阁唯一的社区,快来和大家一起闲聊、讨论吧!
谷雨

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: