`
hawaii162162
  • 浏览: 74995 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

PHP5使用DBO简单操作SQLITE类

阅读更多

今天一个朋友想使用PHP读取火车采集器采集来的数据库,因为他使用的是标准版,火车采集器标准版默认使用的是SQLITE数据库,想起原来在旧的博客里面有一个PHP操作SQLITE数据库的类,便找出来,继续分享,很简洁的说。

 

<?php 
/** 
 * 使用方法 
 * $DB=new SQLite('SpiderResult.db3'); 
 * $ARR = $DB->RecordCount('select * from Content order by ID desc'); 
 * print_r($ARR); 
 */ 

class SQLite { 
    function __construct($file) { 
        try { 
            $this -> Connection = new PDO('sqlite2:' . $file); 
        }  
        catch(PDOException $e) { 
            try { 
                $this -> Connection = new PDO('sqlite:' . $file); 
            }  
            catch(PDOException $e) { 
                exit('error!'); 
            }  
        }  
    }  
    function __destruct() { 
        $this -> Connection = null; 
    }  
    function Query($SQL) { 
        return $this -> Connection -> Query($SQL); 
    }  
    function Execute($SQL) { 
        return $this -> Query($SQL) -> fetch(); 
    }  
    function RecordArray($SQL) { 
        return $this -> Query($SQL) -> fetchAll(); 
    }  
    function RecordCount($SQL) { 
        return count($this -> RecordArray($SQL)); 
    }  
    function RecordLastID() { 
        return $this -> Connection -> lastInsertId(); 
    }  
}  

?> 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics