/* 由于PDO的sqlite取出的值,老是出现首字母小写变大写的问题,只好自己写一个类来替代。

 

 

<?php


/*
0. both
1. PDORow Object
2. assoc
3. num
4. both
5. stdClass Object
6. ?  11
7. first column value

$result = sqlite_query($db, 'select bar from foo');
var_dump(sqlite_fetch_array($result));

$stmt = $pdo->prepare( 'SELECT * FROM file' );
$stmt->execute();
$rows = $stmt->fetchAll(5);
*/

class PDO_sqlite
{
 function PDO_sqlite($dsn)
 {
     $this->connect( $dsn );
 }

 function connect( $dsn , $pConn = false)
 {
  $connFunc = $pConn ? "sqlite_popen" : "sqlite_open";
  $this->conn = @ $connFunc( $dsn, 0666 , $error);
  if (!$this->conn)
  {
   $this->errStr = "DataBase Connect False : ($dsn) !<br />$error";
   //$this->dbError();
  }
 }

 function exec($sql)
 {
    return sqlite_exec( $this->conn , $sql , $error );
 } 

 function prepare($sql)
 {
     $this->_sql = $sql;
 }

 function execute()
 {
    $this->_result = sqlite_query( $this->conn , $this->_sql );
 }

 function fetchAll( $mode=5 )
 {
  if($mode==5)
   $fetchFunc = "sqlite_fetch_object";
     while( $row = $fetchFunc($this->_result))
     {
         $rows[] = $row;
     }
  return $rows;
 }
}

?>

Posted on 2009-02-11 14:37  古代  阅读(658)  评论(0编辑  收藏  举报