简单mysql类

---恢复内容开始---

class mysql
{
    private $host;
    private $user;
    private $pass;
    private $database;
    private $charset;
    function __construct($host,$user,$pass,$database,$charset)
    {
        $this--->host=$host;
        $this->user=$user;
        $this->pass=$pass;
        $this->database=$database;
        $this->charset=$charset;
        $this->connect();
    }
    private function connect()//连接函数
    {
        mysql_connect($this->host,$this->user,$this->pass) or die ("连接数据库服务器失败!");
        mysql_select_db($this->database) or die ("连接数据库失败!");
        mysql_query("set names $this->charset");        
    }
    function select($sql,$tab,$col,$value)//选择函数
    {
        $select=mysql_query("select $sql from $tab where $col=$value");
        $row=mysql_fetch_array($select);
        return $row;
    }
    function insert($tab,$col,$value)//插入数据函数
    {
        mysql_query("INSERT INTO $tab($col)values($value)");
    }
    function update($tab,$col,$new_value,$colm,$value)//更新数据函数
    {
        mysql_query("UPDATE $tab SET $col=$new_value where $colm=$value");    
    }
    function delete($tab,$col,$value)//删除数据函数
    {
        mysql_query("DELETE FROM $tab where $col=$value");
        }
    function close()//关闭连接函数
    {
    mysql_close();
    
    }
}
//$mysql=new mysql("127.0.0.1","root","120360150","test","gbk");连接数据库
//$sql=$mysql->select("*","admin","id","3");//选择数据
//print_r($sql);//打印返回的数组
//$mysql->insert("admin","user_name,user_pass","‘123‘,‘123‘");插入数据
//$mysql->update("admin","user_pass","22","id","3");更新数据
//$mysql->delete("admin","id","4");删除数据
//$mysql->close();关闭连接

 

---恢复内容结束---

简单mysql类,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。