当前位置:编程学习 > php >>

PHP实战第一天

今天我学到了

php发送给浏览器设置编码

header('content-type:text/html;charset=utf-8');

 


smarty模板引擎在类里面会报N多错

 


brophp里的DB类,我修改了也无法单独使用

 


thinkphp里的DB类,我修改了也是不能单独使用.

 


最后使用了 网上开源的 mysql类


[php]  <?php 
// +----------------------------------------------------------------------  
// |MySQL操作类  
// +----------------------------------------------------------------------  
// |@微凉 QQ:496928838  
// +----------------------------------------------------------------------  
class MySQL{ 
     
    private $db_mysql_hostname; 
    private $db_mysql_username; 
    private $db_mysql_password; 
    private $db_mysql_database; 
    private $db_mysql_port; 
    private $db_mysql_charset; 
     
    private $query_list = array(); 
     
    //查询次数  
    public $query_count = 0; 
    //查询开始时间  
    public $query_start_time; 
     
    //当前查询ID  
    protected $queryID; 
    //当前连接  
    protected $conn; 
    // 事务指令数  
    protected $transTimes = 0; 
    // 返回或者影响记录数  
    protected $numRows    = 0; 
    // 错误信息  
    protected $error      = ''; 
     
    public function __construct($hostname_or_conf,$username,$password,$database,$port = '3306',$char = 'utf8'){ 
        if(is_array($hostname_or_conf)){ 
            $this->db_mysql_hostname = $hostname_or_conf['hostname']; 
            $this->db_mysql_username = $hostname_or_conf['username']; 
            $this->db_mysql_password = $hostname_or_conf['password']; 
            $this->db_mysql_database = $hostname_or_conf['database']; 
            $this->db_mysql_port = isset($hostname_or_conf['port'])?$hostname_or_conf['port']:'3306'; 
            $this->db_mysql_charset = isset($hostname_or_conf['charset'])?$hostname_or_conf['charset']:'utf8'; 
             
        }elseif(!empty($hostname_or_conf)||!empty($username)||!empty($password)||!empty($database)) 
        { 
             $this->db_mysql_hostname = $hostname_or_conf; 
             $this->db_mysql_username = $username; 
             $this->db_mysql_password = $password; 
             $this->db_mysql_database = $database; 
             $this->db_mysql_port = $port; 
             $this->db_mysql_charset = $char; 
              
        }else{ 
            die('configuration error.'); 
        } 
        $this->connect(); 
    } 
     
    private function connect(){ 
        $server = $this->db_mysql_hostname.':'.$this->db_mysql_port; 
        $this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) or die('Connect MySQL DB error!'); 
        mysql_select_db($this->db_mysql_database,$this->conn) or die('select db error!'); 
        mysql_query("set names " . $this->db_mysql_charset, $this->conn); 
    } 
    /**
     +----------------------------------------------------------
     * 设置数据对象值
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     *table,where,order,limit,data,field,join,group,having
     +----------------------------------------------------------
     */ 
    public function table($table){ 
        $this->query_list['table'] = $table; 
        return $this; 
    } 
     
    public function where($where){ 
        $this->query_list['where'] = $where; 
        return $this; 
    } 
     
    public function order($order){ 
        $this->query_list['order'] = $order; 
        return $this; 
    } 
     
    public function limit($offset,$length){ 
        if(!isset($length)){ 
            $length = $offset; 
            $offset = 0; 
        } 
        $this->query_list['limit'] = 'limit '.$offset.','.$length; 
        return $this; 
    } 
     
    public function data($data){ 
        /*
        if(is_

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,