📄 adodb.inc.php
字号:
} if ($this->debug) ADOConnection::outp( " Cache write error"); } if ($rs->EOF && !$eof) { $rs->MoveFirst(); //$rs = &csv2rs($md5file,$err); $rs->connection = &$this; // Pablo suggestion } } else if (!$this->memCache) @unlink($md5file); } else { $this->_errorMsg = ''; $this->_errorCode = 0; if ($this->fnCacheExecute) { $fn = $this->fnCacheExecute; $fn($this, $secs2cache, $sql, $inputarr); } // ok, set cached object found $rs->connection = &$this; // Pablo suggestion if ($this->debug){ $inBrowser = isset($_SERVER['HTTP_USER_AGENT']); $ttl = $rs->timeCreated + $secs2cache - time(); $s = is_array($sql) ? $sql[0] : $sql; if ($inBrowser) $s = '<i>'.htmlspecialchars($s).'</i>'; ADOConnection::outp( " $md5file reloaded, ttl=$ttl [ $s ]"); } } return $rs; } /* Similar to PEAR DB's autoExecute(), except that $mode can be 'INSERT' or 'UPDATE' or DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE If $mode == 'UPDATE', then $where is compulsory as a safety measure. $forceUpdate means that even if the data has not changed, perform update. */ function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) { $false = false; $sql = 'SELECT * FROM '.$table; if ($where!==FALSE) $sql .= ' WHERE '.$where; else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) { ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause'); return $false; } $rs =& $this->SelectLimit($sql,1); if (!$rs) return $false; // table does not exist $rs->tableName = $table; switch((string) $mode) { case 'UPDATE': case '2': $sql = $this->GetUpdateSQL($rs, $fields_values, $forceUpdate, $magicq); break; case 'INSERT': case '1': $sql = $this->GetInsertSQL($rs, $fields_values, $magicq); break; default: ADOConnection::outp("AutoExecute: Unknown mode=$mode"); return $false; } $ret = false; if ($sql) $ret = $this->Execute($sql); if ($ret) $ret = true; return $ret; } /** * Generates an Update Query based on an existing recordset. * $arrFields is an associative array of fields with the value * that should be assigned. * * Note: This function should only be used on a recordset * that is run against a single table and sql should only * be a simple select stmt with no groupby/orderby/limit * * "Jonathan Younger" <jyounger@unilab.com> */ function GetUpdateSQL(&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=null) { global $ADODB_INCLUDED_LIB; //********************************************************// //This is here to maintain compatibility //with older adodb versions. Sets force type to force nulls if $forcenulls is set. if (!isset($force)) { global $ADODB_FORCE_TYPE; $force = $ADODB_FORCE_TYPE; } //********************************************************// if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force); } /** * Generates an Insert Query based on an existing recordset. * $arrFields is an associative array of fields with the value * that should be assigned. * * Note: This function should only be used on a recordset * that is run against a single table. */ function GetInsertSQL(&$rs, $arrFields,$magicq=false,$force=null) { global $ADODB_INCLUDED_LIB; if (!isset($force)) { global $ADODB_FORCE_TYPE; $force = $ADODB_FORCE_TYPE; } if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force); } /** * Update a blob column, given a where clause. There are more sophisticated * blob handling functions that we could have implemented, but all require * a very complex API. Instead we have chosen something that is extremely * simple to understand and use. * * Note: $blobtype supports 'BLOB' and 'CLOB', default is BLOB of course. * * Usage to update a $blobvalue which has a primary key blob_id=1 into a * field blobtable.blobcolumn: * * UpdateBlob('blobtable', 'blobcolumn', $blobvalue, 'blob_id=1'); * * Insert example: * * $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); * $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); */ function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') { return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false; } /** * Usage: * UpdateBlob('TABLE', 'COLUMN', '/path/to/file', 'ID=1'); * * $blobtype supports 'BLOB' and 'CLOB' * * $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); * $conn->UpdateBlob('blobtable','blobcol',$blobpath,'id=1'); */ function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') { $fd = fopen($path,'rb'); if ($fd === false) return false; $val = fread($fd,filesize($path)); fclose($fd); return $this->UpdateBlob($table,$column,$val,$where,$blobtype); } function BlobDecode($blob) { return $blob; } function BlobEncode($blob) { return $blob; } function SetCharSet($charset) { return false; } function IfNull( $field, $ifNull ) { return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; } function LogSQL($enable=true) { include_once(ADODB_DIR.'/adodb-perf.inc.php'); if ($enable) $this->fnExecute = 'adodb_log_sql'; else $this->fnExecute = false; $old = $this->_logsql; $this->_logsql = $enable; if ($enable && !$old) $this->_affected = false; return $old; } function GetCharSet() { return false; } /** * Usage: * UpdateClob('TABLE', 'COLUMN', $var, 'ID=1', 'CLOB'); * * $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, null)'); * $conn->UpdateClob('clobtable','clobcol',$clob,'id=1'); */ function UpdateClob($table,$column,$val,$where) { return $this->UpdateBlob($table,$column,$val,$where,'CLOB'); } // not the fastest implementation - quick and dirty - jlim // for best performance, use the actual $rs->MetaType(). function MetaType($t,$len=-1,$fieldobj=false) { if (empty($this->_metars)) { $rsclass = $this->rsPrefix.$this->databaseType; $this->_metars = new $rsclass(false,$this->fetchMode); $this->_metars->connection =& $this; } return $this->_metars->MetaType($t,$len,$fieldobj); } /** * Change the SQL connection locale to a specified locale. * This is used to get the date formats written depending on the client locale. */ function SetDateLocale($locale = 'En') { $this->locale = $locale; switch (strtoupper($locale)) { case 'EN': $this->fmtDate="'Y-m-d'"; $this->fmtTimeStamp = "'Y-m-d H:i:s'"; break; case 'US': $this->fmtDate = "'m-d-Y'"; $this->fmtTimeStamp = "'m-d-Y H:i:s'"; break; case 'PT_BR': case 'NL': case 'FR': case 'RO': case 'IT': $this->fmtDate="'d-m-Y'"; $this->fmtTimeStamp = "'d-m-Y H:i:s'"; break; case 'GE': $this->fmtDate="'d.m.Y'"; $this->fmtTimeStamp = "'d.m.Y H:i:s'"; break; default: $this->fmtDate="'Y-m-d'"; $this->fmtTimeStamp = "'Y-m-d H:i:s'"; break; } } function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false) { global $_ADODB_ACTIVE_DBS; $save = $this->SetFetchMode(ADODB_FETCH_NUM); if (empty($whereOrderBy)) $whereOrderBy = '1=1'; $rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr); $this->SetFetchMode($save); $false = false; if ($rows === false) { return $false; } if (!isset($_ADODB_ACTIVE_DBS)) { include(ADODB_DIR.'/adodb-active-record.inc.php'); } if (!class_exists($class)) { ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()"); return $false; } $arr = array(); foreach($rows as $row) { $obj = new $class($table,$primkeyArr,$this); if ($obj->ErrorMsg()){ $this->_errorMsg = $obj->ErrorMsg(); return $false; } $obj->Set($row); $arr[] = $obj; } return $arr; } function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) { $arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); return $arr; } /** * Close Connection */ function Close() { $rez = $this->_close(); $this->_connectionID = false; return $rez; } /** * Begin a Transaction. Must be followed by CommitTrans() or RollbackTrans(). * * @return true if succeeded or false if database does not support transactions */ function BeginTrans() { if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver"); return false; } /* set transaction mode */ function SetTransactionMode( $transaction_mode ) { $transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider); $this->_transmode = $transaction_mode; }/*http://msdn2.microsoft.com/en-US/ms173763.aspxhttp://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-isolation.htmlhttp://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.htmlhttp://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm*/ function MetaTransaction($mode,$db) { $mode = strtoupper($mode); $mode = str_replace('ISOLATION LEVEL ','',$mode); switch($mode) { case 'READ UNCOMMITTED': switch($db) { case 'oci8': case 'oracle': return 'ISOLATION LEVEL READ COMMITTED'; default: return 'ISOLATION LEVEL READ UNCOMMITTED'; } break; case 'READ COMMITTED': return 'ISOLATION LEVEL READ COMMITTED'; break; case 'REPEATABLE READ': switch($db) { case 'oci8': case 'oracle': return 'ISOLATION LEVEL SERIALIZABLE'; default: return 'ISOLATION LEVEL REPEATABLE READ'; } break; case 'SERIALIZABLE': return 'ISOLATION LEVEL SERIALIZABLE'; break; default: return $mode; } } /** * If database does not support transactions, always return true as data always commited * * @param $ok set to false to rollback transaction, true to commit * * @return true/false. */ function CommitTrans($ok=true) { return true;} /** * If database does not support transactions, rollbacks always fail, so return false * * @return true/false. */ function RollbackTrans() { return false;} /** * return the databases that the driver can connect to. * Some databases will return an empty array. * * @return an array of database names. */ function MetaDatabases() { global $ADODB_FETCH_MODE; if ($this->metaDatabasesSQL) { $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); $arr = $this->GetCol($this->metaDatabasesSQL); if (isset($savem)) $this->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; return $arr; } return false; } /** * @param ttype can either be 'VIEW' or 'TABLE' or false. * If false, both views and tables are returned. * "VIEW" retu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -