【php开源代码栏目提醒】:本文主要为网学会员提供adodb-sqlite.inc.php,希望对需要adodb-sqlite.inc.php网友有所帮助,学习一下!
<?php
/*
V4.21 20 Mar 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Latest version is available at http://php.
weblogs.com/
SQLite info: http://www.hwaci.com/sw/sqlite/
Install Instructions:
====================
1. Place this in adodb/drivers
2. Rename the file, remove the .txt prefix.
*/
class ADODB_sqlite extends ADOConnection {
var $databaseType = "sqlite";
var $replaceQuote = "''"; // string to use to replace quotes
var $concat_operator='||';
var $_errorNo = 0;
var $hasLimit = true;
var $hasInsertID = true; /// supports autoincrement ID?
var $hasAffectedRows = true; /// supports affected rows for update/delete?
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
var $sysDate = "adodb_date('Y-m-d')";
var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
function ADODB_sqlite()
{
}
/*
function __get($name)
{
switch($name) {
case 'sysDate': return "'".date($this->fmtDate)."'";
case 'sysTimeStamp' : return "'".date($this->sysTimeStamp)."'";
}
}*/
function ServerInfo()
{
$arr['version'] = sqlite_libversion();
$arr['description'] = 'SQLite ';
$arr['encoding'] = sqlite_libencoding();
return $arr;
}
function BeginTrans()
{
if ($this->transOff) return true;
$ret = $this->Execute("BEGIN TRANSACTION");
$this->transCnt += 1;
return true;
}
function CommitTrans($ok=true)
{
if ($this->transOff) return true;
if (!$ok) return $this->RollbackTrans();
$ret = $this->Execute("COMMIT");
if ($this->transCnt>0)$this->transCnt -= 1;
return !empty($ret);
}
function RollbackTrans()
{
if ($this->transOff) return true;
$ret = $this->Execute("ROLLBACK");
if ($this->transCnt>0)$this->transCnt -= 1;
return !empty($ret);
}
function _insertid()
{
return sqlite_last_insert_rowid($this->_connectionID);
}
function _affectedrows()
{
return sqlite_changes($this->_connectionID);
}
function ErrorMsg()
{
if ($this->_logsql) return $this->_errorMsg;
return ($this->_errorNo) ? sqlite_error_string($this->_errorNo) : '';
}
function ErrorNo()
{
return $this->_errorNo;
}
function SQLDate($fmt, $col=false)
{
$fmt = $this->qstr($fmt);
return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
}
function &MetaColumns($tab)
{
global $ADODB_FETCH_MODE;
$rs = $this->Execute("select * from $tab limit 1");
if (!$rs) return false;
$arr = array();
for ($i=0,$max=$rs->_numOfFields; $i < $max; $i++) {
$fld =& $rs->FetchField($i);
if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] =& $fld;
else $arr[strtoupper($fld->name)] =& $fld;
}
$rs->Close();
return $arr;
}
function _createFunctions()
{
@sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1);
@sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2);
}
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('sqlite_open')) return false;
$this->_connectionID = sqlite_open($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
return true;
}
// returns true or false
function _pconnect($argHostname, $argUsername, $argPass
word, $argDatabasename)
{
if (!function_exists('
sqlite_open')) return false;
$this->_connectionID = sqlite_popen($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
return true;
}
// returns query ID if successful, otherwise false
function _query($sql,$inputarr=false)
{
$rez = sqlite_query($sql,$this->_connectionID);
if (!$rez) {
$this->_errorNo = sqlite_last_error($this->_connectionID);
}
return $rez;
}
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
if ($secs2cache)
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
$rs =& $this->Execute($sql."$limitStr$offse