最经典的php链接操作mysql数据库类

相信很多人都在搜索php如何链接和操作mysql,或者稍微懂点的人都会搜索php链接和操作mysql数据库的类,算你找对对方了。下方我极力推荐一个php操作mysql的数据库类,是我多年改写的质量不错的版本,你可以拿回去再完善。当然,我不保证完全安全。

<?php
class db{
    var $Record = array();var $Link_ID  = 0;var $Query_ID = 0;
    function db(){   
        if(!$this->Link_ID){
            $this->Link_ID=mysql_connect('localhost','root','123');//在这里填写mysql数控的地址、用户、密码即可
            mysql_select_db('fangsongle',$this->Link_ID);
        }
        mysql_query("set names 'utf8'",$this->Link_ID);//此处务必使用set names 'utf8',不能使用set names utf8
    }
    function insert_id(){return mysql_insert_id($this->Link_ID);}
    function query($sql){
        $this->Query_ID = mysql_query($sql);
        if(!$this->Query_ID) {return 0;}
        return $this->Query_ID;
    }
    function next_record() {
        if(!$this->Query_ID) {return 0;}
        $this->Record = mysql_fetch_array($this->Query_ID);
        if(!is_array($this->Record)) {return 0;}
        return $this->Record;
    }
    function query_first($sql){ 
        if(!$this->query($sql)) {return 0;}
        $this->Record = mysql_fetch_array($this->Query_ID);
        return $this->Record;
    }
    function num_rows() {return mysql_num_rows($this->Query_ID);}
    function f($field) {if(isset($this->Record[$field])) {return $this->Record[$field];}}
}
$db=new db();
?>
希望这个php操作控制mysql的类可以帮到你。

 

  • 留言列表: