[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html><head><title>ADODB Manual</title> 3 4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 5 6 7 <style> 8 pre { 9 background-color: #eee; 10 padding: 0.75em 1.5em; 11 font-size: 12px; 12 border: 1px solid #ddd; 13 } 14 </style></head> 15 <body bgcolor="#ffffff" text="black"> 16 17 <h2>ADOdb Library for PHP</h2> 18 <p>V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com)</p> 19 <p><font size="1">This software is dual licensed using BSD-Style and LGPL. This 20 means you can use it in compiled proprietary and commercial products.</font></p> 21 22 23 <p>Useful ADOdb links: <a href="http://adodb.sourceforge.net/#download">Download</a> <a href="http://adodb.sourceforge.net/#docs">Other Docs</a> 24 25 </p><p><a href="#intro"><b>Introduction</b></a><b><br> 26 <a href="#features">Unique Features</a><br> 27 <a href="#users">How People are using ADOdb</a><br> 28 <a href="#bugs">Feature Requests and Bug Reports</a><br> 29 </b><b><a href="#install">Installation</a><br> 30 <a href="#mininstall">Minimum Install</a><br> 31 <a href="#coding">Initializing Code and Connectioning to Databases</a><br> 32 </b><font size="2"> <a href="#dsnsupport">Data Source Name (DSN) Support</a></font> <a href="#connect_ex">Connection Examples</a> <br> 33 <b><a href="#speed">High Speed ADOdb - tuning tips</a></b><br> 34 <b><a href="#hack">Hacking and Modifying ADOdb Safely</a><br> 35 <a href="#php5">PHP5 Features</a></b><br> 36 <font size="2"><a href="#php5iterators">foreach iterators</a> <a href="#php5exceptions">exceptions</a></font><br> 37 <b> <a href="#drivers">Supported Databases</a></b><br> 38 <b> <a href="#quickstart">Tutorials</a></b><br> 39 <a href="#ex1">Example 1: Select</a><br> 40 <a href="#ex2">Example 2: Advanced Select</a><br> 41 <a href="#ex3">Example 3: Insert</a><br> 42 <a href="#ex4">Example 4: Debugging</a> <a href="#exrs2html">rs2html 43 example</a><br> 44 <a href="#ex5">Example 5: MySQL and Menus</a><br> 45 <a href="#ex6">Example 6: Connecting to Multiple Databases at once</a> <br> 46 <a href="#ex7">Example 7: Generating Update and Insert SQL</a> <br> 47 <a href="#ex8">Example 8: Implementing Scrolling with Next and Previous</a><br> 48 <a href="#ex9">Example 9: Exporting in CSV or Tab-Delimited Format</a> <br> 49 <a href="#ex10">Example 10: Custom filters</a><br> 50 <a href="#ex11">Example 11: Smart Transactions</a><br> 51 <br> 52 <b> <a href="#errorhandling">Using Custom Error Handlers and PEAR_Error</a><br> 53 <a href="#DSN">Data Source Names</a><br> 54 <a href="#caching">Caching</a><br> 55 <a href="#pivot">Pivot Tables</a></b> 56 </p><p><a href="#ref"><b>REFERENCE</b></a> 57 </p><p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> 58 <a href="#adodb_ansi_padding_off">$ADODB_ANSI_PADDING_OFF</a> 59 <a href="#adodb_cache_dir">$ADODB_CACHE_DIR</a> <br> 60 <a href="#force_type">$ADODB_FORCE_TYPE</a> 61 <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a> 62 <a href="#adodb_lang">$ADODB_LANG</a> <a href=#adodb_auto_quote>ADODB_QUOTE_FIELDNAMES</a> <br> 63 Constants: </font><font size="2"><a href="#adodb_assoc_case">ADODB_ASSOC_CASE</a> 64 </font><br> 65 <a href="#ADOConnection"><b> ADOConnection</b></a><br> 66 <font size="2">Connections: <a href="#connect">Connect</a> <a href="#pconnect">PConnect</a> 67 <a href="#nconnect">NConnect</a> <a href="#isconnected">IsConnected</a><br> 68 Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute"><i>CacheExecute</i></a> 69 <a href="#selectlimit">SelectLimit</a> <a href="#cacheSelectLimit"><i>CacheSelectLimit</i></a> 70 <a href="#param">Param</a> <a href="#prepare">Prepare</a> <a href="#preparesp">PrepareSP</a> 71 <a href="#inparameter">InParameter</a> <a href="#outparameter">OutParameter</a> <a href="#autoexecute">AutoExecute</a> 72 <br> 73 <a href="#getone">GetOne</a> 74 <a href="#cachegetone"><i>CacheGetOne</i></a> <a href="#getrow">GetRow</a> <a href="#cachegetrow"><i>CacheGetRow</i></a> 75 <a href="#getall">GetAll</a> <a href="#cachegetall"><i>CacheGetAll</i></a> <a href="#getcol">GetCol</a> 76 <a href="#cachegetcol"><i>CacheGetCol</i></a> <a href="#getassoc1">GetAssoc</a> <a href="#cachegetassoc"><i>CacheGetAssoc</i></a> <a href="#replace">Replace</a> 77 <br> 78 <a href="#executecursor">ExecuteCursor</a> 79 (oci8 only)<br> 80 Generates SQL strings: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a> 81 <a href="#concat">Concat</a> <a href="#ifnull">IfNull</a> <a href="#length">length</a> <a href="#random">random</a> <a href="#substr">substr</a> 82 <a href="#qstr">qstr</a> <a href="#param">Param</a> <a href="#OffsetDate">OffsetDate</a> <a href="#sqldate">SQLDate</a> 83 <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> 84 <a href="#binddate">BindDate</a> <a href="#bindtimestamp">BindTimeStamp</a> 85 <br> 86 Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a> 87 <a href="#updateblobfile">UpdateBlobFile</a> <a href="#blobencode">BlobEncode</a> 88 <a href="#blobdecode">BlobDecode</a><br> 89 Paging/Scrolling: <a href="#pageexecute">PageExecute</a> <a href="#cachepageexecute">CachePageExecute</a><br> 90 Cleanup: <a href="#cacheflush">CacheFlush</a> <a href="#Close">Close</a><br> 91 Transactions: <a href="#starttrans">StartTrans</a> <a href="#completetrans">CompleteTrans</a> 92 <a href="#failtrans">FailTrans</a> <a href="#hasfailedtrans">HasFailedTrans</a> 93 <a href="#begintrans">BeginTrans</a> <a href="#committrans">CommitTrans</a> 94 <a href="#rollbacktrans">RollbackTrans</a> <a href=#SetTransactionMode>SetTransactionMode</a><br> 95 Fetching Data: </font> <font size="2"><a href="#setfetchmode">SetFetchMode</a><br> 96 Strings: <a href="#concat">concat</a> <a href="#length">length</a> <a href="#qstr">qstr</a> <a href="#quote">quote</a> <a href="#substr">substr</a><br> 97 Dates: <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> <a href="#unixdate">UnixDate</a> 98 <a href="#binddate">BindDate</a> <a href="#bindtimestamp">BindTimeStamp</a> 99 <a href="#unixtimestamp">UnixTimeStamp</a> <a href="#OffsetDate">OffsetDate</a> 100 <a href="#SQLDate">SQLDate</a> <br> 101 Row Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a> <a href="#rowlock">RowLock</a> 102 <a href="#genid">GenID</a> <a href="#createseq">CreateSequence</a> <a href="#dropseq">DropSequence</a> 103 <br> 104 Error Handling: <a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a> 105 <a href="#metaerror">MetaError</a> <a href="#metaerrormsg">MetaErrorMsg</a> <a href="#ignoreerrors">IgnoreErrors</a><br> 106 Data Dictionary (metadata): <a href="#metadatabases">MetaDatabases</a> <a href="#metatables">MetaTables</a> 107 <a href="#metacolumns">MetaColumns</a> <a href="#metacolumnames">MetaColumnNames</a> 108 <a href="#metaprimarykeys">MetaPrimaryKeys</a> <a href="#metaforeignkeys">MetaForeignKeys</a> 109 <a href="#serverinfo">ServerInfo</a> <br> 110 Statistics and Query-Rewriting: <a href="#logsql">LogSQL</a> <a href="#fnexecute">fnExecute 111 and fnCacheExecute</a><br> 112 </font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a> 113 <a href="#parameter">Parameter</a></font> 114 <a href="#adorecordSet"><b><br> 115 ADORecordSet</b></a><br> 116 <font size="2"> 117 Returns one field: <a href="#fields">Fields</a><br> 118 Returns one row:<a href="#fetchrow">FetchRow</a> <a href="#fetchinto">FetchInto</a> 119 <a href="#fetchobject">FetchObject</a> <a href="#fetchnextobject">FetchNextObject</a> 120 <a href="#fetchobj">FetchObj</a> <a href="#fetchnextobj">FetchNextObj</a> 121 <a href="#getrowassoc">GetRowAssoc</a> <br> 122 Returns all rows:<a href="#getarray">GetArray</a> <a href="#getrows">GetRows</a> 123 <a href="#getassoc">GetAssoc</a><br> 124 Scrolling:<a href="#move">Move</a> <a href="#movenext">MoveNext</a> <a href="#movefirst">MoveFirst</a> 125 <a href="#movelast">MoveLast</a> <a href="#abspos">AbsolutePosition</a> <a href="#currentrow">CurrentRow</a> 126 <a href="#atfirstpage">AtFirstPage</a> <a href="#atlastpage">AtLastPage</a> 127 <a href="#absolutepage">AbsolutePage</a> </font> <font size="2"><br> 128 Menu generation:<a href="#getmenu">GetMenu</a> <a href="#getmenu2">GetMenu2</a><br> 129 Dates:<a href="#userdate">UserDate</a> <a href="#usertimestamp">UserTimeStamp</a> 130 <a href="#unixdate">UnixDate</a> <a href="#unixtimestamp">UnixTimeStamp<br> 131 </a>Recordset Info:<a href="#recordcount">RecordCount</a> <a href="#po_recordcount">PO_RecordCount</a> 132 <a href="#nextrecordset">NextRecordSet</a><br> 133 Field Info:<a href="#fieldcount">FieldCount</a> <a href="#fetchfield">FetchField</a> 134 <a href="#metatype">MetaType</a><br> 135 Cleanup: <a href="#rsclose">Close</a></font> 136 </p> 137 <p><font size="2"><a href="#rs2html"><b>rs2html</b></a> <a href="#exrs2html">example</a></font><br> 138 <a href="#adodiff">Differences between ADOdb and ADO</a><br> 139 <a href="#driverguide"><b>Database Driver Guide<br> 140 </b></a><b><a href="#changes">Change Log</a></b><br> 141 </p> 142 <h2>Introduction<a name="intro"></a></h2> 143 <p>PHP's database access functions are not standardised. This creates a need for 144 a database class library to hide the differences between the different database 145 API's (encapsulate the differences) so we can easily switch databases. PHP 4.0.5 or later 146 is now required (because we use array-based str_replace).</p> 147 <p>We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, 148 PostgreSQL, FrontBase, SQLite, Interbase (Firebird and Borland variants), Foxpro, Access, ADO, DB2, SAP DB and ODBC. 149 We have had successful reports of connecting to Progress and CacheLite via ODBC. We hope more people 150 will contribute drivers to support other databases.</p> 151 <p>PHP4 supports session variables. You can store your session information using 152 ADOdb for true portability and scalability. See adodb-session.php for more information.</p> 153 <p>Also read <a href="http://phplens.com/lens/adodb/tips_portable_sql.htm">tips_portable_sql.htm</a> 154 for tips on writing 155 portable SQL.</p> 156 <h2>Unique Features of ADOdb<a name="features"></a></h2> 157 <ul> 158 <li><b>Easy for Windows programmers</b> to adapt to because many of the conventions 159 are similar to Microsoft's ADO.</li> 160 <li>Unlike other PHP database classes which focus only on select statements, 161 <b>we provide support code to handle inserts and updates which can be adapted 162 to multiple databases quickly.</b> Methods are provided for date handling, 163 string concatenation and string quoting characters for differing databases.</li> 164 <li>A<b> metatype system </b>is built in so that we can figure out that types 165 such as CHAR, TEXT and STRING are equivalent in different databases.</li> 166 <li><b>Easy to port</b> because all the database dependant code are stored in 167 stub functions. You do not need to port the core logic of the classes.</li> 168 <li><b>Portable table and index creation</b> with the <a href="docs-datadict.htm">datadict</a> classes. 169 </li><li><b>Database performance monitoring and SQL tuning</b> with the <a href="docs-perf.htm">performance monitoring</a> classes. 170 </li><li><b>Database-backed sessions</b> with the <a href="docs-session.htm">session management</a> classes. Supports session expiry notification. 171 <li><b>Object-Relational Mapping</b> using <a href="docs-active-record.htm">ADOdb_Active_Record</a> classes. 172 </li></ul> 173 <h2>How People are using ADOdb<a name="users"></a></h2> 174 Here are some examples of how people are using ADOdb (for a much longer list, 175 visit <a href="http://phplens.com/phpeverywhere/adodb-cool-apps">adodb-cool-apps</a>): 176 <ul> 177 <li><a href="http://phplens.com/">PhpLens</a> is a commercial data grid 178 component that allows both cool Web designers and serious unshaved 179 programmers to develop and maintain databases on the Web easily. 180 Developed by the author of ADOdb.<p> 181 182 </p></li><li><a href="http://www.interakt.ro/phakt/">PHAkt: PHP Extension for DreamWeaver Ultradev</a> allows you to script PHP in the popular Web page editor. Database handling provided by ADOdb.<p> 183 184 </p></li><li><a href="http://www.andrew.cmu.edu/%7Erdanyliw/snort/snortacid.html">Analysis Console for Intrusion Databases</a> 185 (ACID): PHP-based analysis engine to search and process a database of 186 security incidents generated by security-related software such as IDSes 187 and firewalls (e.g. Snort, ipchains). By Roman Danyliw.<p> 188 189 </p></li><li><a href="http://www.postnuke.com/">PostNuke</a> is a very 190 popular free content management system and weblog system. It offers 191 full CSS support, HTML 4.01 transitional compliance throughout, an 192 advanced blocks system, and is fully multi-lingual enabled. <p> 193 194 </p></li><li><a href="http://www.auto-net.no/easypublish.php?page=index&lang_id=2">EasyPublish CMS</a> 195 is another free content management system for managing information and 196 integrated modules on your internet, intranet- and extranet-sites. From 197 Norway.<p> 198 199 </p></li><li><a href="http://nola.noguska.com/">NOLA</a> is a full featured accounting, inventory, and job tracking application. It is licensed under the GPL, and developed by Noguska. 200 </li></ul><p> 201 202 </p><h2>Feature Requests and Bug Reports<a name="bugs"></a></h2> 203 <p>Feature requests and bug reports can be emailed to <a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a> 204 or posted to the ADOdb Help forums at <a href="http://phplens.com/lens/lensforum/topics.php?id=4">http://phplens.com/lens/lensforum/topics.php?id=4</a>.</p> 205 <h2>Installation Guide<a name="install"></a></h2> 206 <p>Make sure you are running PHP 4.0.5 or later. 207 Unpack all the files into a directory accessible by your webserver.</p> 208 <p>To test, try modifying some of the tutorial examples. Make sure you customize 209 the connection settings correctly. You can debug using <i>$db->debug = true</i> as shown below:</p> 210 <pre><?php<br> include('adodb/adodb.inc.php');<br> $db = <a href="#adonewconnection">ADONewConnection</a>($dbdriver); # eg 'mysql' or 'postgres'<br> $db->debug = true;<br> $db-><a href="#connect">Connect</a>($server, $user, $password, $database);<br> $rs = $db-><a href="#execute">Execute</a>('select * from some_small_table');<br> print "<pre>";<br> print_r($rs-><a href="#getrows">GetRows</a>());<br> print "</pre>";<br>?></pre> 211 212 <h3>Minimum Install<a name="mininstall"></a></h3> 213 <p>For developers who want to release a minimal install of ADOdb, you will need: 214 </p><ul> 215 <li>adodb.inc.php 216 </li><li>adodb-lib.inc.php 217 </li><li>adodb-time.inc.php 218 </li><li>drivers/adodb-$database.inc.php 219 </li><li>license.txt (for legal reasons) 220 </li><li>adodb-php4.inc.php 221 </li><li>adodb-iterator.inc.php (php5 functionality) 222 </li></ul> 223 Optional: 224 <ul> 225 <li>adodb-error.inc.php and lang/adodb-$lang.inc.php (if you use MetaError()) 226 </li><li>adodb-csvlib.inc.php (if you use cached recordsets - CacheExecute(), etc) 227 </li><li>adodb-exceptions.inc.php and adodb-errorhandler.inc.php (if you use adodb error handler or php5 exceptions). 228 <li>adodb-active-record.inc.php if you use <a href=docs-active-record.htm>Active Records</a>. 229 </li></ul> 230 231 <h3>Code Initialization Examples<a name="coding"></a></h3> 232 <p>When running ADOdb, at least two files are loaded. First is adodb/adodb.inc.php, 233 which contains all functions used by all database classes. The code specific 234 to a particular database is in the adodb/driver/adodb-????.inc.php file.</p> 235 <a name="adonewconnection"></a> 236 <p>For example, to connect to a mysql database:</p> 237 <pre>include('/path/to/set/here/adodb.inc.php');<br>$conn = &ADONewConnection('mysql');<br></pre> 238 <p>Whenever you need to connect to a database, you create a Connection object 239 using the <b>ADONewConnection</b>($driver) function. 240 <b>NewADOConnection</b>($driver) is an alternative name for the same function.</p> 241 242 <p>At this point, you are not connected to the database (no longer true if you pass in a <a href="#dsnsupport">dsn</a>). You will first need to decide 243 whether to use <i>persistent</i> or <i>non-persistent</i> connections. The advantage of <i>persistent</i> 244 connections is that they are faster, as the database connection is never closed (even 245 when you call Close()). <i>Non-persistent </i>connections take up much fewer resources though, 246 reducing the risk of your database and your web-server becoming overloaded. 247 </p><p>For persistent connections, 248 use $conn-><a href="#pconnect">PConnect()</a>, 249 or $conn-><a href="#connect">Connect()</a> for non-persistent connections. 250 Some database drivers also support <a href="#nconnect">NConnect()</a>, which forces 251 the creation of a new connection. 252 253 <a name="connection_gotcha"></a> 254 </p><p><b>Connection Gotcha</b>: If you create two connections, but both use the same userid and password, 255 PHP will share the same connection. This can cause problems if the connections are meant to 256 different databases. The solution is to always use different userid's for different databases, 257 or use NConnect(). 258 259 <a name="dsnsupport"></a> 260 </p><h3>Data Source Name (DSN) Support</h3> 261 <p> Since ADOdb 4.51, you can connect to a database by passing a dsn to NewADOConnection() (or ADONewConnection, which is 262 the same function). The dsn format is: 263 </p><pre> $driver://$username:$password@hostname/$database?options[=value]<br></pre><p> 264 NewADOConnection() calls Connect() or PConnect() internally for you. If the connection fails, false is returned. 265 </p><pre> <font color="#008000"># non-persistent connection</font> 266 $dsn = 'mysql://root:pwd@localhost/mydb'; 267 $db = NewADOConnection($dsn); 268 if (!$db) die("Connection failed"); 269 270 <font color="#008000"># no need to call connect/pconnect!</font> 271 $arr = $db->GetArray("select * from table"); 272 273 <font color="#008000"># persistent connection</font> 274 $dsn2 = 'mysql://root:pwd@localhost/mydb?persist'; 275 </pre> 276 <p> 277 If you have special characters such as /:?_ in your dsn, then you need to rawurlencode them first: 278 </p><pre> $pwd = rawurlencode($pwd);<br> $dsn = "mysql://root:$pwd@localhost/mydb"; 279 $dsn2=rawurlencode("sybase_ase")."://user:pass@host/path?query";<br></pre> 280 <p> 281 Legal options are: 282 </p><p> 283 <table align="center" border="1"><tbody><tr><td>For all drivers</td><td> 284 'persist', 'persistent', 'debug', 'fetchmode', 'new' 285 </td></tr><tr><td>Interbase/Firebird 286 </td><td> 287 'dialect','charset','buffers','role' 288 </td></tr><tr><td>M'soft ADO</td><td> 289 'charpage' 290 291 </td></tr><tr><td>MySQL</td><td> 292 'clientflags' 293 </td></tr><tr><td>MySQLi</td><td> 294 'port', 'socket', 'clientflags' 295 </td></tr><tr><td>Oci8</td><td> 296 'nls_date_format','charset' 297 </td></tr></tbody></table> 298 </p><p> 299 For all drivers, when the options <i>persist</i> or <i>persistent</i> are set, a persistent connection is forced; similarly, when <i>new</i> is set, then 300 a new connection will be created using NConnect if the underlying driver supports it. 301 The <i>debug</i> option enables debugging. The <i>fetchmode</i> calls <a href="#setfetchmode">SetFetchMode()</a>. 302 If no value is defined for an option, then the value is set to 1. 303 </p><p> 304 ADOdb DSN's are compatible with version 1.0 of PEAR DB's DSN format. 305 <a name="connect_ex"> 306 </a></p><h3><a name="connect_ex">Examples of Connecting to Databases</a></h3> 307 <h4><a name="connect_ex">MySQL and Most Other Database Drivers</a></h4> 308 <p><a name="connect_ex">MySQL connections are very straightforward, and the parameters are identical 309 to mysql_connect:</a></p> 310 <pre><a name="connect_ex"> $conn = &ADONewConnection('mysql'); <br> $conn->PConnect('localhost','userid','password','database');<br> <br> <font color="#008000"># or dsn </font> 311 $dsn = 'mysql://user:pwd@localhost/mydb'; 312 $conn = ADONewConnection($dsn); # no need for Connect() 313 314 <font color="#008000"># or persistent dsn</font> 315 $dsn = 'mysql://user:pwd@localhost/mydb?persist'; 316 $conn = ADONewConnection($dsn); # no need for PConnect() 317 318 <font color="#008000"># a more complex example:</font> 319 $pwd = urlencode($pwd); 320 $flags = MYSQL_CLIENT_COMPRESS; 321 $dsn = "mysql://user:$pwd@localhost/mydb?persist&clientflags=$flags"; 322 $conn = ADONewConnection($dsn); # no need for PConnect() 323 </a></pre> 324 <p><a name="connect_ex"> For most drivers, you can use the standard function: Connect($server, $user, $password, $database), or 325 a </a><a href="dsnsupport">DSN</a> since ADOdb 4.51. Exceptions to this are listed below. 326 </p> 327 <a name=pdo> 328 <h4>PDO</h4> 329 <p>PDO, which only works with PHP5, accepts a driver specific connection string: 330 <pre> 331 $conn =& NewADConnection('pdo'); 332 $conn->Connect('mysql:host=localhost',$user,$pwd,$mydb); 333 $conn->Connect('mysql:host=localhost;dbname=mydb',$user,$pwd); 334 $conn->Connect("mysql:host=localhost;dbname=mydb;username=$user;password=$pwd"); 335 </pre> 336 <p>The DSN mechanism is also supported: 337 <pre> 338 $conn =& NewADConnection("pdo_mysql://user:pwd@localhost/mydb?persist"); # persist is optional 339 </pre> 340 <h4>PostgreSQL</h4> 341 <p>PostgreSQL 7 and 8 accepts connections using: </p> 342 <p>a. the standard connection string:</p> 343 <pre> $conn = &ADONewConnection('postgres'); <br> $conn->PConnect('host=localhost port=5432 dbname=mary');</pre> 344 <p> b. the classical 4 parameters:</p> 345 <pre> $conn->PConnect('localhost','userid','password','database');<br> </pre> 346 <p>c. dsn: 347 </p><pre> $dsn = 'postgres://user:pwd@localhost/mydb?persist'; # persist is optional 348 $conn = ADONewConnection($dsn); # no need for Connect/PConnect<br></pre> 349 <a name="ldap"></a> 350 351 <h4>LDAP</h4> 352 <p>Here is an example of querying a LDAP server. Thanks to Josh Eldridge for the driver and this example: 353 </p><pre> 354 require('/path/to/adodb.inc.php'); 355 356 /* Make sure to set this BEFORE calling Connect() */ 357 $LDAP_CONNECT_OPTIONS = Array( 358 Array ("OPTION_NAME"=>LDAP_OPT_DEREF, "OPTION_VALUE"=>2), 359 Array ("OPTION_NAME"=>LDAP_OPT_SIZELIMIT,"OPTION_VALUE"=>100), 360 Array ("OPTION_NAME"=>LDAP_OPT_TIMELIMIT,"OPTION_VALUE"=>30), 361 Array ("OPTION_NAME"=>LDAP_OPT_PROTOCOL_VERSION,"OPTION_VALUE"=>3), 362 Array ("OPTION_NAME"=>LDAP_OPT_ERROR_NUMBER,"OPTION_VALUE"=>13), 363 Array ("OPTION_NAME"=>LDAP_OPT_REFERRALS,"OPTION_VALUE"=>FALSE), 364 Array ("OPTION_NAME"=>LDAP_OPT_RESTART,"OPTION_VALUE"=>FALSE) 365 ); 366 $host = 'ldap.baylor.edu'; 367 $ldapbase = 'ou=People,o=Baylor University,c=US'; 368 369 $ldap = NewADOConnection( 'ldap' ); 370 $ldap->Connect( $host, $user_name='', $password='', $ldapbase ); 371 372 echo "<pre>"; 373 374 print_r( $ldap->ServerInfo() ); 375 $ldap->SetFetchMode(ADODB_FETCH_ASSOC); 376 $userName = 'eldridge'; 377 $filter="(|(CN=$userName*)(sn=$userName*)(givenname=$userName*)(uid=$userName*))"; 378 379 $rs = $ldap->Execute( $filter ); 380 if ($rs) 381 while ($arr = $rs->FetchRow()) { 382 print_r($arr); 383 } 384 385 $rs = $ldap->Execute( $filter ); 386 if ($rs) 387 while (!$rs->EOF) { 388 print_r($rs->fields); 389 $rs->MoveNext(); 390 } 391 392 print_r( $ldap->GetArray( $filter ) ); 393 print_r( $ldap->GetRow( $filter ) ); 394 395 $ldap->Close(); 396 echo "</pre>"; 397 </pre> 398 <p>Using DSN: 399 <pre> 400 $dsn = "ldap://ldap.baylor.edu/ou=People,o=Baylor University,c=US"; 401 $db = NewADOConnection($dsn); 402 </pre> 403 <h4>Interbase/Firebird</h4> 404 You define the database in the $host parameter: 405 <pre> $conn = &ADONewConnection('ibase'); <br> $conn->PConnect('localhost:c:\ibase\employee.gdb','sysdba','masterkey');<br></pre> 406 <p>Or dsn: 407 </p><pre> $dsn = 'firebird://user:pwd@localhost/mydb?persist&dialect=3'; # persist is optional<br> $conn = ADONewConnection($dsn); # no need for Connect/PConnect<br></pre> 408 <h4>SQLite</h4> 409 Sqlite will create the database file if it does not exist. 410 <pre> $conn = &ADONewConnection('sqlite'); 411 $conn->PConnect('c:\path\to\sqlite.db'); # sqlite will create if does not exist<br></pre> 412 <p>Or dsn: 413 </p><pre> $path = urlencode('c:\path\to\sqlite.db'); 414 $dsn = "sqlite://$path/?persist"; # persist is optional 415 $conn = ADONewConnection($dsn); # no need for Connect/PConnect<br></pre> 416 <h4>Oracle (oci8)</h4> 417 <p>With oci8, you can connect in multiple ways. Note that oci8 works fine with 418 newer versions of the Oracle, eg. 9i and 10g.</p> 419 <p>a. PHP and Oracle reside on the same machine, use default SID.</p> 420 <pre> $conn->Connect(false, 'scott', 'tiger');</pre> 421 <p>b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS'</p> 422 <pre> $conn->PConnect(false, 'scott', 'tiger', 'myTNS');</pre> 423 <p>or</p> 424 <pre> $conn->PConnect('myTNS', 'scott', 'tiger');</pre> 425 <p>c. Host Address and SID</p> 426 <pre> 427 $conn->connectSID = true; 428 $conn->Connect('192.168.0.1', 'scott', 'tiger', 'SID');</pre> 429 <p>d. Host Address and Service Name</p> 430 <pre> $conn->Connect('192.168.0.1', 'scott', 'tiger', 'servicename');</pre> 431 <p>e. Oracle connection string: 432 </p><pre> $cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port))<br> (CONNECT_DATA=(SID=$sid)))";<br> $conn->Connect($cstr, 'scott', 'tiger');<br></pre> 433 <p>f. ADOdb dsn: 434 </p><pre> $dsn = 'oci8://user:pwd@tnsname/?persist'; # persist is optional<br> $conn = ADONewConnection($dsn); # no need for Connect/PConnect<br> <br> $dsn = 'oci8://user:pwd@host/sid';<br> $conn = ADONewConnection($dsn);<br> <br> $dsn = 'oci8://user:pwd@/'; # oracle on local machine<br> $conn = ADONewConnection($dsn);<br></pre> 435 <p>You can also set the charSet for Oracle 9.2 and later, supported since PHP 4.3.2, ADOdb 4.54: 436 </p><pre> $conn->charSet = 'we8iso8859p1';<br> $conn->Connect(...);<br> <br> # or<br> $dsn = 'oci8://user:pwd@tnsname/?charset=WE8MSWIN1252';<br> $db = ADONewConnection($dsn);<br></pre> 437 <a name="dsnless"></a> 438 <h4>DSN-less ODBC ( Access, MSSQL and DB2 examples)</h4> 439 <p>ODBC DSN's can be created in the ODBC control panel, or you can use a DSN-less 440 connection.To use DSN-less connections with ODBC you need PHP 4.3 or later. 441 </p> 442 <p>For Microsoft Access:</p> 443 <pre> $db =& ADONewConnection('access');<br> $dsn = <strong>"Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;";</strong> 444 $db->Connect($dsn); 445 </pre> 446 For Microsoft SQL Server: 447 <pre> $db =& ADONewConnection('odbc_mssql');<br> $dsn = <strong>"Driver={SQL Server};Server=localhost;Database=northwind;"</strong>;<br> $db->Connect($dsn,'userid','password');<br></pre> 448 or if you prefer to use the mssql extension (which is limited to mssql 6.5 functionality): 449 <pre> $db =& ADONewConnection('mssql');<br> $db->Execute('localhost', 'userid', 'password', 'northwind');<br></pre> 450 For DB2: 451 <pre> 452 $dbms = 'db2'; # or 'odbc_db2' if db2 extension not available 453 $db =& ADONewConnection($dbms); 454 $dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP;". 455 "uid=root; pwd=secret";<br> $db->Connect($dsn); 456 </pre> 457 <b>DSN-less Connections with ADO</b><br> 458 If you are using versions of PHP earlier than PHP 4.3.0, DSN-less connections 459 only work with Microsoft's ADO, which is Microsoft's COM based API. An example 460 using the ADOdb library and Microsoft's ADO: 461 <pre><?php<br> include ('adodb.inc.php'); <br> $db = &ADONewConnection("ado_mssql");<br> print "<h1>Connecting DSN-less $db->databaseType...</h1>";<br> <br> <b>$myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};"<br> . "SERVER=flipper;DATABASE=ai;UID=sa;PWD=;" ;</b> 462 $db->Connect($myDSN); 463 464 $rs = $db->Execute("select * from table"); 465 $arr = $rs->GetArray(); 466 print_r($arr); 467 ?> 468 </pre><a name="speed"></a> 469 <h2>High Speed ADOdb - tuning tips</h2> 470 <p>ADOdb is a big class library, yet it <a href="http://phplens.com/lens/adodb/">consistently beats</a> all other PHP class 471 libraries in performance. This is because it is designed in a layered fashion, 472 like an onion, with the fastest functions in the innermost layer. Stick to the 473 following functions for best performance:</p> 474 <table align="center" border="1" width="40%"> 475 <tbody><tr> 476 <td><div align="center"><b>Innermost Layer</b></div></td> 477 </tr> 478 <tr> 479 <td><p align="center">Connect, PConnect, NConnect<br> 480 Execute, CacheExecute<br> 481 SelectLimit, CacheSelectLimit<br> 482 MoveNext, Close <br> 483 qstr, Affected_Rows, Insert_ID</p></td> 484 </tr> 485 </tbody></table> 486 <p>The fastest way to access the field data is by accessing the array $recordset->fields 487 directly. Also set the global variables <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a> 488 = ADODB_FETCH_NUM, and (for oci8, ibase/firebird and odbc) <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> = false 489 before you connect to your database.</p> 490 <p>Consider using bind parameters if your database supports it, as it improves 491 query plan reuse. Use ADOdb's performance tuning system to identify bottlenecks 492 quickly. At the time of writing (Dec 2003), this means oci8 and odbc drivers.</p> 493 <p>Lastly make sure you have a PHP accelerator cache installed such as APC, Turck 494 MMCache, Zend Accelerator or ionCube.</p> 495 <p>Some examples:</p> 496 <table align="center" border="1"><tbody><tr><td><b>Fastest data retrieval using PHP</b></td><td><b>Fastest data retrieval using ADOdb extension</b></td></tr> 497 <tr><td> 498 <pre>$rs =& $rs->Execute($sql);<br>while (!$rs->EOF) {<br> var_dump($rs->fields);<br> $rs->MoveNext();<br>}</pre></td><td> 499 <pre>$rs =& $rs->Execute($sql);<br>$array = adodb_getall($rs);<br>var_dump($array);<br><br><br></pre></td></tr></tbody></table> 500 <p><b>Advanced Tips</b> 501 </p><p>If you have the <a href="http://adodb.sourceforge.net/#extension">ADOdb C extension</a> installed, 502 you can replace your calls to $rs->MoveNext() with adodb_movenext($rs). 503 This doubles the speed of this operation. For retrieving entire recordsets at once, 504 use GetArray(), which uses the high speed extension function adodb_getall($rs) internally. 505 </p><p>Execute() is the default way to run queries. You can use the low-level functions _Execute() and _query() 506 to reduce query overhead. Both these functions share the same parameters as Execute(). 507 </p><p>If you do not have any bind parameters or your database supports 508 binding (without emulation), 509 then you can call _Execute() directly. Calling this function bypasses 510 bind emulation. Debugging is still supported in _Execute(). 511 </p><p>If you do not require debugging facilities nor emulated 512 binding, and do not require a recordset to be returned, then you can 513 call _query. This is great for inserts, updates and deletes. Calling 514 this function 515 bypasses emulated binding, debugging, and recordset handling. Either 516 the resultid, true or false are returned by _query(). </p><p>For Informix, you can disable scrollable cursors with $db->cursorType = 0. 517 </p><p><a name="hack"></a> </p> 518 <h2>Hacking ADOdb Safely</h2> 519 <p>You might want to modify ADOdb for your own purposes. Luckily you can 520 still maintain backward compatibility by sub-classing ADOdb and using the $ADODB_NEWCONNECTION 521 variable. $ADODB_NEWCONNECTION allows you to override the behaviour of ADONewConnection(). 522 ADOConnection() checks for this variable and will call 523 the function-name stored in this variable if it is defined. 524 </p><p>In the following example, new functionality for the connection object 525 is placed in the <i>hack_mysql</i> and <i>hack_postgres7</i> classes. The recordset class naming convention 526 can be controlled using $rsPrefix. Here we set it to 'hack_rs_', which will make ADOdb use 527 <i>hack_rs_mysql</i> and <i>hack_rs_postgres7</i> as the recordset classes. 528 529 530 </p><pre>class hack_mysql extends adodb_mysql {<br>var $rsPrefix = 'hack_rs_';<br> /* Your mods here */<br>}<br><br>class hack_rs_mysql extends ADORecordSet_mysql {<br> /* Your mods here */<br>}<br><br>class hack_postgres7 extends adodb_postgres7 {<br>var $rsPrefix = 'hack_rs_';<br> /* Your mods here */<br>}<br><br>class hack_rs_postgres7 extends ADORecordSet_postgres7 {<br> /* Your mods here */<br>}<br><br>$ADODB_NEWCONNECTION = 'hack_factory';<br><br>function& hack_factory($driver)<br>{<br> if ($driver !== 'mysql' && $driver !== 'postgres7') return false;<br> <br> $driver = 'hack_'.$driver;<br> $obj = new $driver();<br> return $obj;<br>}<br><br>include_once ('adodb.inc.php');<br></pre> 531 <p></p><p>Don't forget to call the constructor of the parent class in 532 your constructor. If you want to use the default ADOdb drivers return 533 false in the above hack_factory() function. 534 Also you can define your own ADORecordSet_empty() class, by defining a class $$this->rsPrefix.'empty' since 4.96/5.02. 535 <a name="php5"></a> 536 </p><h2>PHP5 Features</h2> 537 ADOdb 4.02 or later will transparently determine which version of PHP you are using. 538 If PHP5 is detected, the following features become available: 539 <ul> 540 541 <li><b>PDO</b>: PDO drivers are available. See the <a href=#pdo>connection examples</a>. Currently PDO drivers are 542 not as powerful as native drivers, and should be treated as experimental.<br><br> 543 <a name="php5iterators"></a> 544 <li><b>Foreach iterators</b>: This is a very natural way of going through a recordset: 545 <pre> $ADODB_FETCH_MODE = ADODB_FETCH_NUM;<br> $rs = $db->Execute($sql);<br> foreach($rs as $k => $row) {<br> echo "r1=".$row[0]." r2=".$row[1]."<br>";<br> }<br></pre> 546 <p> 547 <a name="php5exceptions"></a> 548 </p></li><li><b>Exceptions</b>: Just include <i>adodb-exceptions.inc.php</i> and you can now 549 catch exceptions on errors as they occur. 550 <pre> <b>include ("../adodb-exceptions.inc.php");</b> <br> include("../adodb.inc.php"); <br> try { <br> $db = NewADOConnection("oci8"); <br> $db->Connect('','scott','bad-password'); <br> } catch (exception $e) { <br> var_dump($e); <br> adodb_backtrace($e->gettrace());<br> } <br></pre> 551 <p>Note that reaching EOF is <b>not</b> considered an error nor an exception. 552 </p></li></ul> 553 <h3><a name="drivers"></a>Databases Supported</h3> 554 The <i>name</i> below is the value you pass to NewADOConnection($name) to create a connection object for that database. 555 <p> 556 </p><p> 557 </p><table border="1" width="100%"> 558 <tbody><tr valign="top"> 559 <td><b>Name</b></td> 560 <td><b>Tested</b></td> 561 <td><b>Database</b></td> 562 <td><b><font size="2">RecordCount() usable</font></b></td> 563 <td><b>Prerequisites</b></td> 564 <td><b>Operating Systems</b></td> 565 </tr> 566 <tr valign="top"> 567 <td><b><font size="2">access</font></b></td> 568 <td><font size="2">B</font></td> 569 <td><font size="2">Microsoft Access/Jet. You need to create an ODBC DSN.</font></td> 570 <td><font size="2">Y/N</font></td> 571 <td><font size="2">ODBC </font></td> 572 <td><font size="2">Windows only</font></td> 573 </tr> 574 <tr valign="top"> 575 <td><b><font size="2">ado</font></b></td> 576 <td><font size="2">B</font></td> 577 <td><p><font size="2">Generic ADO, not tuned for specific databases. Allows 578 DSN-less connections. For best performance, use an OLEDB provider. This 579 is the base class for all ado drivers.</font></p> 580 <p><font size="2">You can set $db->codePage before connecting.</font></p></td> 581 <td><font size="2">? depends on database</font></td> 582 <td><font size="2">ADO or OLEDB provider</font></td> 583 <td><font size="2">Windows only</font></td> 584 </tr> 585 <tr valign="top"> 586 <td><b><font size="2">ado_access</font></b></td> 587 <td><font size="2">B</font></td> 588 <td><font size="2">Microsoft Access/Jet using ADO. Allows DSN-less connections. 589 For best performance, use an OLEDB provider.</font></td> 590 <td><font size="2">Y/N</font></td> 591 <td><font size="2">ADO or OLEDB provider</font></td> 592 <td><font size="2">Windows only</font></td> 593 </tr> 594 <tr valign="top"> 595 <td><b><font size="2">ado_mssql</font></b></td> 596 <td><font size="2">B</font></td> 597 <td><font size="2">Microsoft SQL Server using ADO. Allows DSN-less connections. 598 For best performance, use an OLEDB provider.</font></td> 599 <td><font size="2">Y/N</font></td> 600 <td><font size="2">ADO or OLEDB provider</font></td> 601 <td><font size="2">Windows only</font></td> 602 </tr> 603 <tr valign="top"> 604 <td height="54"><b><font size="2">db2</font></b></td> 605 <td height="54"><font size="2">C</font></td> 606 <td height="54"><font size="2">Uses PHP's db2-specific extension for better performance.</font></td> 607 <td height="54"><font size="2">Y/N</font></td> 608 <td height="54"><font size="2">DB2 CLI/ODBC interface</font></td> 609 <td height="54"> <p><font size="2">Unix and Windows. Requires IBM DB2 Universal Database client.</font></p></td> 610 </tr> 611 <tr valign="top"> 612 <td height="54"><b><font size="2">odbc_db2</font></b></td> 613 <td height="54"><font size="2">C</font></td> 614 <td height="54"><font size="2">Connects to DB2 using generic ODBC extension.</font></td> 615 <td height="54"><font size="2">Y/N</font></td> 616 <td height="54"><font size="2">DB2 CLI/ODBC interface</font></td> 617 <td height="54"> <p><font size="2">Unix and Windows. <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/6283/fid/14">Unix 618 install hints</a>. I have had reports that the $host and $database params have to be reversed in Connect() when using the CLI interface.</font></p></td> 619 </tr> 620 <tr valign="top"> 621 <td><b><font size="2">vfp</font></b></td> 622 <td><font size="2">A</font></td> 623 <td><font size="2">Microsoft Visual FoxPro. You need to create an ODBC DSN.</font></td> 624 <td><font size="2">Y/N</font></td> 625 <td><font size="2">ODBC</font></td> 626 <td><font size="2">Windows only</font></td> 627 </tr> 628 <tr valign="top"> 629 <td><b><font size="2">fbsql</font></b></td> 630 <td><font size="2">C</font></td> 631 <td><font size="2">FrontBase. </font></td> 632 <td><font size="2">Y</font></td> 633 <td><font size="2">?</font></td> 634 <td> <p><font size="2">Unix and Windows</font></p></td> 635 </tr> 636 <tr valign="top"> 637 <td><b><font size="2">ibase</font></b></td> 638 <td><font size="2">B</font></td> 639 <td><font size="2">Interbase 6 or earlier. Some users report you might need 640 to use this<br> 641 $db->PConnect('localhost:c:/ibase/employee.gdb', "sysdba", "masterkey") 642 to connect. Lacks Affected_Rows currently.<br> 643 <br> 644 You can set $db->role, $db->dialect, $db->buffers and $db->charSet before connecting.</font></td> 645 <td><font size="2">Y/N</font></td> 646 <td><font size="2">Interbase client</font></td> 647 <td><font size="2">Unix and Windows</font></td> 648 </tr> 649 <tr valign="top"> 650 <td><b><i><font size="2">firebird</font></i></b></td> 651 <td><font size="2">C</font></td> 652 <td><font size="2">Firebird version of interbase.</font></td> 653 <td><font size="2">Y/N</font></td> 654 <td><font size="2">Interbase client</font></td> 655 <td><font size="2">Unix and Windows</font></td> 656 </tr> 657 <tr valign="top"> 658 <td><b><i><font size="2">borland_ibase</font></i></b></td> 659 <td><font size="2">C</font></td> 660 <td><font size="2">Borland version of Interbase 6.5 or later. Very sad that 661 the forks differ.</font></td> 662 <td><font size="2">Y/N</font></td> 663 <td><font size="2">Interbase client</font></td> 664 <td><font size="2">Unix and Windows</font></td> 665 </tr> 666 667 <tr valign="top"> 668 <td><b><font size="2">informix</font></b></td> 669 <td><font size="2">C</font></td> 670 <td><font size="2">Generic informix driver. Use this if you are using Informix 7.3 or later.</font></td> 671 <td><font size="2">Y/N</font></td> 672 <td><font size="2">Informix client</font></td> 673 <td><font size="2">Unix and Windows</font></td> 674 </tr> 675 <tr valign="top"> 676 <td><b><font size="2">informix72</font></b></td> 677 <td><font size="2">C</font></td> 678 <td><font size="2"> Informix databases before Informix 7.3 that do no support 679 SELECT FIRST.</font></td> 680 <td><font size="2">Y/N</font></td> 681 <td><font size="2">Informix client</font></td> 682 <td><font size="2">Unix and Windows</font></td> 683 </tr> 684 <tr valign="top"> 685 <td><b><font size="2">ldap</font></b></td> 686 <td><font size="2">C</font></td> 687 <td><font size="2">LDAP driver. See this example for usage information.</font></td> 688 <td> </td> 689 <td><font size="2">LDAP extension</font></td> 690 <td><font size="2">?</font></td> 691 </tr> 692 <tr valign="top"> 693 <td height="73"><b><font size="2">mssql</font></b></td> 694 <td height="73"><font size="2">A</font></td> 695 <td height="73"> <p><font size="2">Microsoft SQL Server 7 and later. Works 696 with Microsoft SQL Server 2000 also. Note that date formating is problematic 697 with this driver. For example, the PHP mssql extension does not return 698 the seconds for datetime!</font></p></td> 699 <td height="73"><font size="2">Y/N</font></td> 700 <td height="73"><font size="2">Mssql client</font></td> 701 <td height="73"> <p><font size="2">Unix and Windows. <br> 702 <a href="http://phpbuilder.com/columns/alberto20000919.php3">Unix install 703 howto</a> and <a href="http://linuxjournal.com/article.php?sid=6636&mode=thread&order=0">another 704 one</a>. </font></p></td> 705 </tr> 706 <tr valign="top"> 707 <td height="73"><b><font size="2">mssqlpo</font></b></td> 708 <td height="73"><font size="2">A</font></td> 709 <td height="73"> <p><font size="2">Portable mssql driver. Identical to above 710 mssql driver, except that '||', the concatenation operator, is converted 711 to '+'. Useful for porting scripts from most other sql variants that use 712 ||.</font></p></td> 713 <td height="73"><font size="2">Y/N</font></td> 714 <td height="73"><font size="2">Mssql client</font></td> 715 <td height="73"> <p><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3"><br> 716 Unix install howto</a>.</font></p></td> 717 </tr> 718 <tr valign="top"> 719 <td><b><font size="2">mysql</font></b></td> 720 <td><font size="2">A</font></td> 721 <td><font size="2">MySQL without transaction support. You can also set $db->clientFlags 722 before connecting.</font></td> 723 <td><font size="2">Y</font></td> 724 <td><font size="2">MySQL client</font></td> 725 <td><font size="2">Unix and Windows</font></td> 726 </tr> 727 <tr valign="top"> 728 <td><font size="2"><b>mysqlt</b> or <b>maxsql</b></font></td> 729 <td><font size="2">A</font></td> 730 <td> <p><font size="2">MySQL with transaction support. We recommend using 731 || as the concat operator for best portability. This can be done by running 732 MySQL using: <br> 733 <i>mysqld --ansi</i> or <i>mysqld --sql-mode=PIPES_AS_CONCAT</i></font></p></td> 734 <td><font size="2">Y/N</font></td> 735 <td><font size="2">MySQL client</font></td> 736 <td><font size="2">Unix and Windows</font></td> 737 </tr> 738 <tr valign="top"> 739 <td><b><font size="2">oci8</font></b></td> 740 <td><font size="2">A</font></td> 741 <td><font size="2">Oracle 8/9. Has more functionality than <i>oracle</i> driver 742 (eg. Affected_Rows). You might have to putenv('ORACLE_HOME=...') before 743 Connect/PConnect. </font> <p><font size="2"> There are 2 ways of connecting 744 - with server IP and service name: <br> 745 <i>PConnect('serverip:1521','scott','tiger','service'</i>)<br> 746 or using an entry in TNSNAMES.ORA or ONAMES or HOSTNAMES: <br> 747 <i>PConnect(false, 'scott', 'tiger', $oraname)</i>. </font> 748 </p><p><font size="2">Since 2.31, we support Oracle REF cursor variables directly 749 (see <a href="#executecursor">ExecuteCursor</a>).</font> </p></td> 750 <td><font size="2">Y/N</font></td> 751 <td><font size="2">Oracle client</font></td> 752 <td><font size="2">Unix and Windows</font></td> 753 </tr> 754 <tr valign="top"> 755 <td><b><font size="2">oci805</font></b></td> 756 <td><font size="2">C</font></td> 757 <td><font size="2">Supports reduced Oracle functionality for Oracle 8.0.5. 758 SelectLimit is not as efficient as in the oci8 or oci8po drivers.</font></td> 759 <td><font size="2">Y/N</font></td> 760 <td><font size="2">Oracle client</font></td> 761 <td><font size="2">Unix and Windows</font></td> 762 </tr> 763 <tr valign="top"> 764 <td><b><font size="2">oci8po</font></b></td> 765 <td><font size="2">A</font></td> 766 <td><font size="2">Oracle 8/9 portable driver. This is nearly identical with 767 the oci8 driver except (a) bind variables in Prepare() use the ? convention, 768 instead of :bindvar, (b) field names use the more common PHP convention 769 of lowercase names. </font> <p><font size="2">Use this driver if porting 770 from other databases is important. Otherwise the oci8 driver offers better 771 performance. </font> </p></td> 772 <td><font size="2">Y/N</font></td> 773 <td><font size="2">Oracle client</font></td> 774 <td><font size="2">Unix and Windows</font></td> 775 </tr> 776 <tr valign="top"> 777 <td><b><font size="2">odbc</font></b></td> 778 <td><font size="2">A</font></td> 779 <td><font size="2">Generic ODBC, not tuned for specific databases. To connect, 780 use <br> 781 PConnect('DSN','user','pwd'). This is the base class for all odbc derived 782 drivers.</font></td> 783 <td><font size="2">? depends on database</font></td> 784 <td><font size="2">ODBC</font></td> 785 <td><font size="2">Unix and Windows. <a href="http://phpbuilder.com/columns/alberto20000919.php3?page=4">Unix 786 hints.</a></font></td> 787 </tr> 788 <tr valign="top"> 789 <td><b><font size="2">odbc_mssql</font></b></td> 790 <td><font size="2">C</font></td> 791 <td><font size="2">Uses ODBC to connect to MSSQL</font></td> 792 <td><font size="2">Y/N</font></td> 793 <td><font size="2">ODBC</font></td> 794 <td><font size="2">Unix and Windows. </font></td> 795 </tr> 796 <tr valign="top"> 797 <td><b><font size="2">odbc_oracle</font></b></td> 798 <td><font size="2">C</font></td> 799 <td><font size="2">Uses ODBC to connect to Oracle</font></td> 800 <td><font size="2">Y/N</font></td> 801 <td><font size="2">ODBC</font></td> 802 <td><font size="2">Unix and Windows. </font></td> 803 </tr> 804 805 <tr valign="top"> 806 <td><b><font size="2">odbtp</font></b></td> 807 <td><font size="2">C</font></td> 808 <td><font size="2">Generic odbtp driver. <a href="http://odbtp.sourceforge.net/">Odbtp</a> is a software for 809 accessing Windows ODBC data sources from other operating systems.</font></td> 810 <td><font size="2">Y/N</font></td> 811 <td><font size="2">odbtp</font></td> 812 <td><font size="2">Unix and Windows</font></td> 813 </tr> 814 <tr valign="top"> 815 <td><b><font size="2">odbtp_unicode</font></b></td> 816 <td><font size="2">C</font></td> 817 <td><font size="2">Odtbp with unicode support</font></td> 818 <td><font size="2">Y/N</font></td> 819 <td><font size="2">odbtp</font></td> 820 <td><font size="2">Unix and Windows</font></td> 821 </tr> 822 <tr valign="top"> 823 <td height="34"><b><font size="2">oracle</font></b></td> 824 <td height="34"><font size="2">C</font></td> 825 <td height="34"><font size="2">Implements old Oracle 7 client API. Use oci8 826 driver if possible for better performance.</font></td> 827 <td height="34"><font size="2">Y/N</font></td> 828 <td height="34"><font size="2">Oracle client</font></td> 829 <td height="34"><font size="2">Unix and Windows</font></td> 830 </tr> 831 <tr valign="top"> 832 <td height="34"><b><font size="2">netezza</font></b></td> 833 <td height="34"><font size="2">C</font></td> 834 <td height="34"><font size="2">Netezza driver. Netezza is based on postgres code-base.</font></td> 835 <td height="34"><font size="2">Y</font></td> 836 <td height="34"><font size="2">?</font></td> 837 <td height="34"><font size="2">?</font></td> 838 </tr> 839 <tr valign="top"> 840 <td><b><font size="2">pdo</font></b></td> 841 <td><font size="2">C</font></td> 842 <td><font size="2">Generic PDO driver for PHP5. </font></td> 843 <td><font size="2">Y</font></td> 844 <td><font size="2">PDO extension and database specific drivers</font></td> 845 <td><font size="2">Unix and Windows. </font></td> 846 </tr> 847 <tr valign="top"> 848 <td><b><font size="2">postgres</font></b></td> 849 <td><font size="2">A</font></td> 850 <td><font size="2">Generic PostgreSQL driver. Currently identical to postgres7 851 driver.</font></td> 852 <td><font size="2">Y</font></td> 853 <td><font size="2">PostgreSQL client</font></td> 854 <td><font size="2">Unix and Windows. </font></td> 855 </tr> 856 <tr valign="top"> 857 <td><b><font size="2">postgres64</font></b></td> 858 <td><font size="2">A</font></td> 859 <td><font size="2">For PostgreSQL 6.4 and earlier which does not support LIMIT 860 internally.</font></td> 861 <td><font size="2">Y</font></td> 862 <td><font size="2">PostgreSQL client</font></td> 863 <td><font size="2">Unix and Windows. </font></td> 864 </tr> 865 <tr valign="top"> 866 <td><b><font size="2">postgres7</font></b></td> 867 <td><font size="2">A</font></td> 868 <td><font size="2">PostgreSQL which supports LIMIT and other version 7 functionality.</font></td> 869 <td><font size="2">Y</font></td> 870 <td><font size="2">PostgreSQL client</font></td> 871 <td><font size="2">Unix and Windows. </font></td> 872 </tr> 873 <tr valign="top"> 874 <td><b><font size="2">postgres8</font></b></td> 875 <td><font size="2">A</font></td> 876 <td><font size="2">PostgreSQL which supports version 8 functionality.</font></td> 877 <td><font size="2">Y</font></td> 878 <td><font size="2">PostgreSQL client</font></td> 879 <td><font size="2">Unix and Windows. </font></td> 880 </tr> 881 <tr valign="top"> 882 <td><b><font size="2">sapdb</font></b></td> 883 <td><font size="2">C</font></td> 884 <td><font size="2">SAP DB. Should work reliably as based on ODBC driver.</font></td> 885 <td><font size="2">Y/N</font></td> 886 <td><font size="2">SAP ODBC client</font></td> 887 <td> <p><font size="2">?</font></p></td> 888 </tr> 889 <tr valign="top"> 890 <td><b><font size="2">sqlanywhere</font></b></td> 891 <td><font size="2">C</font></td> 892 <td><font size="2">Sybase SQL Anywhere. Should work reliably as based on ODBC 893 driver.</font></td> 894 <td><font size="2">Y/N</font></td> 895 <td><font size="2">SQL Anywhere ODBC client</font></td> 896 <td> <p><font size="2">?</font></p></td> 897 </tr> 898 <tr valign="top"> 899 <td height="54"><b><font size="2">sqlite</font></b></td> 900 <td height="54"><font size="2">B</font></td> 901 <td height="54"><font size="2">SQLite.</font></td> 902 <td height="54"><font size="2">Y</font></td> 903 <td height="54"><font size="2">-</font></td> 904 <td height="54"> <p><font size="2">Unix and Windows.</font></p></td> 905 </tr> 906 <tr valign="top"> 907 <td height="54"><b><font size="2">sqlitepo</font></b></td> 908 <td height="54"><font size="2">B</font></td> 909 <td height="54"><font size="2">Portable SQLite driver. This is because assoc mode does not work like other drivers in sqlite. 910 Namely, when selecting (joining) multiple tables, the table 911 names are included in the assoc keys in the "sqlite" driver.</font><p> 912 <font size="2"> In "sqlitepo" driver, the table names are stripped from the returned column names. 913 When this results in a conflict, the first field get preference. 914 </font></p></td> 915 <td height="54"><font size="2">Y</font></td> 916 <td height="54"><font size="2">-</font></td> 917 <td height="54"> <p><font size="2">Unix and Windows.</font></p></td> 918 </tr> 919 920 921 <tr valign="top"> 922 <td><b><font size="2">sybase</font></b></td> 923 <td><font size="2">C</font></td> 924 <td><font size="2">Sybase. </font></td> 925 <td><font size="2">Y/N</font></td> 926 <td><font size="2">Sybase client</font></td> 927 <td> <p><font size="2">Unix and Windows.</font></p></td> 928 </tr> 929 930 <tr valign="top"> 931 <td><b><font size="2">sybase_ase</font></b></td> 932 <td><font size="2">C</font></td> 933 <td><font size="2">Sybase ASE. </font></td> 934 <td><font size="2">Y/N</font></td> 935 <td><font size="2">Sybase client</font></td> 936 <td> <p><font size="2">Unix and Windows.</font></p></td> 937 </tr> 938 </tbody></table> 939 940 <p></p><p>The "Tested" column indicates how extensively the code has been tested 941 and used. <br> 942 A = well tested and used by many people<br> 943 B = tested and usable, but some features might not be implemented<br> 944 C = user contributed or experimental driver. Might not fully support all of 945 the latest features of ADOdb. </p> 946 <p>The column "RecordCount() usable" indicates whether RecordCount() 947 return the number of rows, or returns -1 when a SELECT statement is executed. 948 If this column displays Y/N then the RecordCount() is emulated when the global 949 variable $ADODB_COUNTRECS=true (this is the default). Note that for large recordsets, 950 it might be better to disable RecordCount() emulation because substantial amounts 951 of memory are required to cache the recordset for counting. Also there is a 952 speed penalty of 40-50% if emulation is required. This is emulated in most databases 953 except for PostgreSQL and MySQL. This variable is checked every time a query 954 is executed, so you can selectively choose which recordsets to count.</p> 955 <p> 956 </p><hr /> 957 <h1>Tutorials<a name="quickstart"></a></h1> 958 <h3>Example 1: Select Statement<a name="ex1"></a></h3> 959 <p>Task: Connect to the Access Northwind DSN, display the first 2 columns of each 960 row.</p> 961 <p>In this example, we create a ADOConnection object, which represents the connection 962 to the database. The connection is initiated with <a href="#pconnect"><font face="Courier New, Courier, mono">PConnect</font></a>, 963 which is a persistent connection. Whenever we want to query the database, we 964 call the <font face="Courier New, Courier, mono">ADOConnection.<a href="#execute">Execute</a>()</font> 965 function. This returns an ADORecordSet object which is actually a cursor that 966 holds the current row in the array <font face="Courier New, Courier, mono">fields[]</font>. 967 We use <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font> 968 to move from row to row.</p> 969 <p>NB: A useful function that is not used in this example is <font face="Courier New, Courier, mono"><a href="#selectlimit">SelectLimit</a></font>, 970 which allows us to limit the number of rows shown. 971 </p><pre><?<br><font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#660000">conn</font> = &ADONewConnection('access'); # create a connection<br>$<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind DSN<br>$<font color="#660000">recordSet</font> = &$<font color="#660000">conn</font>->Execute('select * from products');<br>if (!$<font color="#660000">recordSet</font>) <br> print $<font color="#660000">conn</font>->ErrorMsg();<br>else<br><b>while</b> (!$<font color="#660000">recordSet</font>->EOF) {<br> <b>print</b> $<font color="#660000">recordSet</font>->fields[0].' '.$<font color="#660000">recordSet</font>->fields[1].'<BR>';<br> $<font color="#660000">recordSet</font>->MoveNext();<br>}</font><font face="Courier New, Courier, mono"> 972 973 $<font color="#660000">recordSet</font>->Close(); # optional<br>$<font color="#660000">conn</font>->Close(); # optional<br></font> 974 ?> 975 </pre> 976 <p>The $<font face="Courier New, Courier, mono">recordSet</font> returned stores 977 the current row in the <font face="Courier New, Courier, mono">$recordSet->fields</font> 978 array, indexed by column number (starting from zero). We use the <font face="Courier New, Courier, mono"><a href="#movenext">MoveNext</a>()</font> 979 function to move to the next row. The <font face="Courier New, Courier, mono">EOF</font> 980 property is set to true when end-of-file is reached. If an error occurs in Execute(), 981 we return false instead of a recordset.</p> 982 <p>The <code>$recordSet->fields[]</code> array is generated by the PHP database 983 extension. Some database extensions only index by number and do not index the 984 array by field name. To force indexing by name - that is associative arrays 985 - use the SetFetchMode function. Each recordset saves and uses whatever fetch 986 mode was set when the recordset was created in Execute() or SelectLimit(). 987 </p><pre> $db->SetFetchMode(ADODB_FETCH_NUM);<br> $rs1 = $db->Execute('select * from table');<br> $db->SetFetchMode(ADODB_FETCH_ASSOC);<br> $rs2 = $db->Execute('select * from table');<br> print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i> 988 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i> 989 </pre> 990 <p> </p> 991 <p>To get the number of rows in the select statement, you can use <font face="Courier New, Courier, mono">$recordSet-><a href="#recordcount">RecordCount</a>()</font>. 992 Note that it can return -1 if the number of rows returned cannot be determined.</p> 993 <h3>Example 2: Advanced Select with Field Objects<a name="ex2"></a></h3> 994 <p>Select a table, display the first two columns. If the second column is a date 995 or timestamp, reformat the date to US format.</p> 996 <pre><?<br><font face="Courier New, Courier, mono"><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#660000">conn</font> = &ADONewConnection('access'); # create a connection<br>$<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn<br>$<font color="#660000">recordSet</font> = &$<font color="#660000">conn</font>->Execute('select CustomerID,OrderDate from Orders');<br>if (!$<font color="#660000">recordSet</font>) <br> print $<font color="#660000">conn</font>->ErrorMsg();<br>else<br><b>while</b> (!$<font color="#660000">recordSet</font>->EOF) {<br> $<font color="#660000">fld</font> = <font color="#336600"><b>$</b><font color="#660000">recordSet</font><b>->FetchField</b></font><font color="#006600">(</font>1<font color="#006600">);</font> 997 $<font color="#660000">type</font> = <font color="#336600"><b>$</b><font color="#660000">recordSet</font><b>->MetaType</b></font>($fld->type);<br><br> <b>if</b> ( $<font color="#660000">type</font> == 'D' || $<font color="#660000">type</font> == 'T') <br> <b>print</b> $<font color="#660000">recordSet</font>->fields[0].' '.<br> <b><font color="#336600">$</font></b><font color="#660000">recordSet</font><b><font color="#336600">->UserDate</font></b>($<font color="#660000">recordSet</font>->fields[1],'<b>m/d/Y</b>').'<BR>';<br> <b>else </b> 998 <b>print</b> $<font color="#660000">recordSet</font>->fields[0].' '.$<font color="#660000">recordSet</font>->fields[1].'<BR>';<br><br> $<font color="#660000">recordSet</font>->MoveNext();<br>}</font><font face="Courier New, Courier, mono"> 999 $<font color="#660000">recordSet</font>->Close(); # optional<br>$<font color="#660000">conn</font>->Close(); # optional<br></font> 1000 ?> 1001 </pre> 1002 <p>In this example, we check the field type of the second column using <font face="Courier New, Courier, mono"><a href="#fetchfield">FetchField</a>().</font> 1003 This returns an object with at least 3 fields.</p> 1004 <ul> 1005 <li><b>name</b>: name of column</li> 1006 <li> <b>type</b>: native field type of column</li> 1007 <li> <b>max_length</b>: maximum length of field. Some databases such as MySQL 1008 do not return the maximum length of the field correctly. In these cases max_length 1009 will be set to -1.</li> 1010 </ul> 1011 <p>We then use <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font> 1012 to translate the native type to a <i>generic</i> type. Currently the following 1013 <i>generic</i> types are defined:</p> 1014 <ul> 1015 <li><b>C</b>: character fields that should be shown in a <input type="text"> 1016 tag.</li> 1017 <li><b>X</b>: TeXt, large text fields that should be shown in a <textarea></li> 1018 <li><b>B</b>: Blobs, or Binary Large Objects. Typically images. 1019 </li><li><b>D</b>: Date field</li> 1020 <li><b>T</b>: Timestamp field</li> 1021 <li><b>L</b>: Logical field (boolean or bit-field)</li> 1022 <li><b>I</b>: Integer field</li> 1023 <li><b>N</b>: Numeric field. Includes autoincrement, numeric, floating point, 1024 real and integer. </li> 1025 <li><b>R</b>: Serial field. Includes serial, autoincrement integers. This works 1026 for selected databases. </li> 1027 </ul> 1028 <p>If the metatype is of type date or timestamp, then we print it using the user 1029 defined date format with <font face="Courier New, Courier, mono"><a href="#userdate">UserDate</a>(),</font> 1030 which converts the PHP SQL date string format to a user defined one. Another 1031 use for <font face="Courier New, Courier, mono"><a href="#metatype">MetaType</a>()</font> 1032 is data validation before doing an SQL insert or update.</p> 1033 <h3>Example 3: Inserting<a name="ex3"></a></h3> 1034 <p>Insert a row to the Orders table containing dates and strings that need to 1035 be quoted before they can be accepted by the database, eg: the single-quote 1036 in the word <i>John's</i>.</p> 1037 <pre><?<br><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#660000">conn</font> = &ADONewConnection('access'); # create a connection<br><br>$<font color="#660000">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn<br>$<font color="#660000">shipto</font> = <font color="#006600"><b>$conn->qstr</b></font>("<i>John's Old Shoppe</i>");<br><br>$<font color="#660000">sql</font> = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";<br>$<font color="#660000">sql</font> .= "values ('ANATR',2,".<b><font color="#006600">$conn->DBDate(</font>time()<font color="#006600">)</font></b><font color="#006600">.</font>",$<font color="#660000">shipto</font>)";<br><br><b>if</b> ($<font color="#660000">conn</font>->Execute($<font color="#660000">sql</font>) <font color="#336600"><b>=== false</b></font>) {<br> <b>print</b> 'error inserting: '.<font color="#336600"><b>$conn->ErrorMsg()</b></font>.'<BR>';<br>}<br>?><br></pre> 1038 <p>In this example, we see the advanced date and quote handling facilities of 1039 ADOdb. The unix timestamp (which is a long integer) is appropriately formated 1040 for Access with <font face="Courier New, Courier, mono"><a href="#dbdate">DBDate</a>()</font>, 1041 and the right escape character is used for quoting the <i>John's Old Shoppe</i>, 1042 which is<b> </b><i>John'<b>'</b>s Old Shoppe</i> and not PHP's default <i>John<b>'</b>s 1043 Old Shoppe</i> with <font face="Courier New, Courier, mono"><a href="#qstr">qstr</a>()</font>. 1044 </p> 1045 <p>Observe the error-handling of the Execute statement. False is returned by<font face="Courier New, Courier, mono"> 1046 <a href="#execute">Execute</a>() </font>if an error occured. The error message 1047 for the last error that occurred is displayed in <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font>. 1048 Note: <i>php_track_errors</i> might have to be enabled for error messages to 1049 be saved.</p> 1050 <h3> Example 4: Debugging<a name="ex4"></a></h3> 1051 <pre><?<br><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#663300">conn</font> = &ADONewConnection('access'); # create a connection<br>$<font color="#663300">conn</font>->PConnect('northwind'); # connect to MS-Access, northwind dsn<br><font>$<font color="#663300">shipto</font> = <b>$conn->qstr</b>("John's Old Shoppe");<br>$<font color="#663300">sql</font> = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";<br>$<font color="#663300">sql</font> .= "values ('ANATR',2,".$<font color="#663300">conn</font>->FormatDate(time()).",$shipto)";<br><b><font color="#336600">$<font color="#663300">conn</font>->debug = true;</font></b> 1052 <b>if</b> ($<font color="#663300">conn</font>->Execute($sql) <b>=== false</b>) <b>print</b> 'error inserting';</font> 1053 ?> 1054 </pre> 1055 <p>In the above example, we have turned on debugging by setting <b>debug = true</b>. 1056 This will display the SQL statement before execution, and also show any error 1057 messages. There is no need to call <font face="Courier New, Courier, mono"><a href="#errormsg">ErrorMsg</a>()</font> 1058 in this case. For displaying the recordset, see the <font face="Courier New, Courier, mono"><a href="#exrs2html">rs2html</a>() 1059 </font>example.</p> 1060 <p>Also see the section on <a href="#errorhandling">Custom Error Handlers</a>.</p> 1061 <h3>Example 5: MySQL and Menus<a name="ex5"></a></h3> 1062 <p>Connect to MySQL database <i>agora</i>, and generate a <select> menu 1063 from an SQL statement where the <option> captions are in the 1st column, 1064 and the value to send back to the server is in the 2nd column.</p> 1065 <pre><?<br><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#663300">conn</font> = &ADONewConnection('mysql'); # create a connection<br>$<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db<br><font>$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';<br>$<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute($sql);<br><b>print</b> <b><font color="#336600">$<font color="#663300">rs</font>->GetMenu('GetCust','Mary Rosli');<br>?></font></b></font></pre> 1066 <p>Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected. 1067 See <a href="#getmenu"><font face="Courier New, Courier, mono">GetMenu</font></a><font face="Courier New, Courier, mono">()</font>. 1068 We also have functions that return the recordset as an array: <font face="Courier New, Courier, mono"><a href="#getarray">GetArray</a>()</font>, 1069 and as an associative array with the key being the first column: <a href="#getassoc1">GetAssoc</a>().</p> 1070 <h3>Example 6: Connecting to 2 Databases At Once<a name="ex6"></a></h3> 1071 <pre><?<br><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$<font color="#663300">conn1</font> = &ADONewConnection('mysql'); # create a mysql connection<br>$<font color="#663300">conn2</font> = &ADONewConnection('oracle'); # create a oracle connection<br><br>$conn1->PConnect($server, $userid, $password, $database);<br>$conn2->PConnect(false, $ora_userid, $ora_pwd, $oraname);<br><br>$conn1->Execute('insert ...');<br>$conn2->Execute('update ...');<br>?></pre> 1072 <p> 1073 </p><h3>Example 7: Generating Update and Insert SQL<a name="ex7"></a></h3> 1074 <p>Since ADOdb 4.56, we support <a href="reference.functions.getupdatesql.html#autoexecute">AutoExecute()</a>, 1075 which simplifies things by providing an advanced wrapper for GetInsertSQL() and GetUpdateSQL(). For example, 1076 an INSERT can be carried out with: 1077 1078 <pre> 1079 $record["firstname"] = "Bob"; 1080 $record["lastname"] = "Smith"; 1081 $record["created"] = time(); 1082 $insertSQL = $conn->AutoExecute($rs, $record, 'INSERT'); 1083 </pre> 1084 1085 and an UPDATE with: 1086 <pre> 1087 $record["firstname"] = "Caroline"; 1088 $record["lastname"] = "Smith"; # Update Caroline's lastname from Miranda to Smith 1089 $insertSQL = $conn->AutoExecute($rs, $record, 'UPDATE', 'id = 1'); 1090 </pre> 1091 <p> 1092 The rest of this section is out-of-date: 1093 <p>ADOdb 1.31 and later supports two new recordset functions: GetUpdateSQL( ) and 1094 GetInsertSQL( ). This allow you to perform a "SELECT * FROM table query WHERE...", 1095 make a copy of the $rs->fields, modify the fields, and then generate the SQL to 1096 update or insert into the table automatically. 1097 <p> We show how the functions can be used when accessing a table with the following 1098 fields: (ID, FirstName, LastName, Created). 1099 </p><p> Before these functions can be called, you need to initialize the recordset 1100 by performing a select on the table. Idea and code by Jonathan Younger jyounger#unilab.com. 1101 Since ADOdb 2.42, you can pass a table name instead of a recordset into 1102 GetInsertSQL (in $rs), and it will generate an insert statement for that table. 1103 </p><p> 1104 </p><pre><?<br>#==============================================<br># SAMPLE GetUpdateSQL() and GetInsertSQL() code<br>#==============================================<br>include ('adodb.inc.php');<br>include('tohtml.inc.php');<br><br>#==========================<br># This code tests an insert<br><br>$sql = "SELECT * FROM ADOXYZ WHERE id = -1"; <br># Select an empty record from the database<br><br>$conn = &ADONewConnection("mysql"); # create a connection<br>$conn->debug=1;<br>$conn->PConnect("localhost", "admin", "", "test"); # connect to MySQL, testdb<br>$rs = $conn->Execute($sql); # Execute the query and get the empty recordset<br><br>$record = array(); # Initialize an array to hold the record data to insert<br><br># Set the values for the fields in the record<br># Note that field names are case-insensitive<br>$record["firstname"] = "Bob";<br>$record["lastNamE"] = "Smith";<br>$record["creaTed"] = time();<br><br># Pass the empty recordset and the array containing the data to insert<br># into the GetInsertSQL function. The function will process the data and return<br># a fully formatted insert sql statement.<br>$insertSQL = $conn->GetInsertSQL($rs, $record);<br><br>$conn->Execute($insertSQL); # Insert the record into the database<br><br>#==========================<br># This code tests an update<br><br>$sql = "SELECT * FROM ADOXYZ WHERE id = 1"; <br># Select a record to update<br><br>$rs = $conn->Execute($sql); # Execute the query and get the existing record to update<br><br>$record = array(); # Initialize an array to hold the record data to update<br><br># Set the values for the fields in the record<br># Note that field names are case-insensitive<br>$record["firstname"] = "Caroline";<br>$record["LasTnAme"] = "Smith"; # Update Caroline's lastname from Miranda to Smith<br><br># Pass the single record recordset and the array containing the data to update<br># into the GetUpdateSQL function. The function will process the data and return<br># a fully formatted update sql statement with the correct WHERE clause.<br># If the data has not changed, no recordset is returned<br>$updateSQL = $conn->GetUpdateSQL($rs, $record);<br><br>$conn->Execute($updateSQL); # Update the record in the database<br>$conn->Close();<br>?><br></pre> 1105 <a name="ADODB_FORCE_TYPE"></a> 1106 <b>$ADODB_FORCE_TYPE</b><p> 1107 The behaviour of AutoExecute(), GetUpdateSQL() and GetInsertSQL() 1108 when converting empty or null PHP variables to SQL is controlled by the 1109 global $ADODB_FORCE_TYPE variable. Set it to one of the values below. Default 1110 is ADODB_FORCE_VALUE (3): 1111 </p><pre>0 = ignore empty fields. All empty fields in array are ignored.<br>1 = force null. All empty, php null and string 'null' fields are changed to sql NULL values.<br>2 = force empty. All empty, php null and string 'null' fields are changed to sql empty '' or 0 values.<br>3 = force value. Value is left as it is. Php null and string 'null' are set to sql NULL values and <br> empty fields '' are set to empty '' sql values.<br><br>define('ADODB_FORCE_IGNORE',0);<br>define('ADODB_FORCE_NULL',1);<br>define('ADODB_FORCE_EMPTY',2);<br>define('ADODB_FORCE_VALUE',3);<br></pre> 1112 <p> 1113 Thanks to Niko (nuko#mbnet.fi) for the $ADODB_FORCE_TYPE code. 1114 </p><p> 1115 Note: the constant ADODB_FORCE_NULLS is obsolete since 4.52 and is ignored. Set $ADODB_FORCE_TYPE = ADODB_FORCE_NULL 1116 for equivalent behaviour. 1117 <p>Since 4.62, the table name to be used can be overridden by setting $rs->tableName before AutoExecute(), GetInsertSQL() or GetUpdateSQL() is called. 1118 </p><h3>Example 8: Implementing Scrolling with Next and Previous<a name="ex8"></a></h3> 1119 <p> The following code creates a very simple recordset pager, where you can scroll 1120 from page to page of a recordset.</p> 1121 <pre>include_once ('../adodb.inc.php');<br>include_once('../adodb-pager.inc.php');<br>session_start();<br><br>$db = NewADOConnection('mysql');<br><br>$db->Connect('localhost','root','','xphplens');<br><br>$sql = "select * from adoxyz ";<br><br>$pager = new ADODB_Pager($db,$sql);<br>$pager->Render($rows_per_page=5);</pre> 1122 <p>This will create a basic record pager that looks like this: <a name="scr"></a> 1123 </p><p> 1124 <table bgcolor="beige" border="1"> 1125 <tbody><tr> 1126 <td> <a href="#scr"><code>|<</code></a> <a href="#scr"><code><<</code></a> 1127 <a href="#scr"><code>>></code></a> <a href="#scr"><code>>|</code></a> 1128 </td> 1129 </tr> 1130 <tr> 1131 <td><table bgcolor="white" border="1" cols="4" width="100%"> 1132 <tbody><tr><th>ID</th> 1133 <th>First Name</th> 1134 <th>Last Name</th> 1135 <th>Date Created</th> 1136 </tr><tr> 1137 <td align="right">36 </td> 1138 <td>Alan </td> 1139 <td>Turing </td> 1140 <td>Sat 06, Oct 2001 </td> 1141 </tr> 1142 <tr> 1143 <td align="right">37 </td> 1144 <td>Serena </td> 1145 <td>Williams </td> 1146 <td>Sat 06, Oct 2001 </td> 1147 </tr> 1148 <tr> 1149 <td align="right">38 </td> 1150 <td>Yat Sun </td> 1151 <td>Sun </td> 1152 <td>Sat 06, Oct 2001 </td> 1153 </tr> 1154 <tr> 1155 <td align="right">39 </td> 1156 <td>Wai Hun </td> 1157 <td>See </td> 1158 <td>Sat 06, Oct 2001 </td> 1159 </tr> 1160 <tr> 1161 <td align="right">40 </td> 1162 <td>Steven </td> 1163 <td>Oey </td> 1164 <td>Sat 06, Oct 2001 </td> 1165 </tr> 1166 </tbody></table></td> 1167 </tr> 1168 <tr> 1169 <td><font size="-1">Page 8/10</font></td> 1170 </tr> 1171 </tbody></table> 1172 </p><p>The number of rows to display at one time is controled by the Render($rows) 1173 method. If you do not pass any value to Render(), ADODB_Pager will default to 1174 10 records per page. 1175 </p><p>You can control the column titles by modifying your SQL (supported by most 1176 databases): 1177 </p><pre>$sql = 'select id as "ID", firstname as "First Name", <br> lastname as "Last Name", created as "Date Created" <br> from adoxyz';</pre> 1178 <p>The above code can be found in the <i>adodb/tests/testpaging.php</i> example 1179 included with this release, and the class ADODB_Pager in <i>adodb/adodb-pager.inc.php</i>. 1180 The ADODB_Pager code can be adapted by a programmer so that the text links can 1181 be replaced by images, and the dull white background be replaced with more interesting 1182 colors. 1183 </p><p>You can also allow display of html by setting $pager->htmlSpecialChars = false. 1184 </p><p>Some of the code used here was contributed by Iván Oliva and Cornel 1185 G. </p> 1186 <h3><a name="ex9"></a>Example 9: Exporting in CSV or Tab-Delimited Format</h3> 1187 <p>We provide some helper functions to export in comma-separated-value (CSV) and 1188 tab-delimited formats:</p> 1189 <pre><b>include_once('/path/to/adodb/toexport.inc.php');</b><br>include_once('/path/to/adodb/adodb.inc.php');<br> 1190 $db = &NewADOConnection('mysql');<br>$db->Connect($server, $userid, $password, $database);<br><br>$rs = $db->Execute('select fname as "First Name", surname as "Surname" from table');<br><br>print "<pre>";<br>print <b>rs2csv</b>($rs); # return a string, CSV format<p>print '<hr>';<br><br>$rs->MoveFirst(); # note, some databases do not support MoveFirst<br>print <b>rs2tab</b>($rs,<i>false</i>); # return a string, tab-delimited<br> # false == suppress field names in first line</p>print '<hr>';<br>$rs->MoveFirst();<br><b>rs2tabout</b>($rs); # send to stdout directly (there is also an rs2csvout function)<br>print "</pre>";<br><br>$rs->MoveFirst();<br>$fp = fopen($path, "w");<br>if ($fp) {<br> <b>rs2csvfile</b>($rs, $fp); # write to file (there is also an rs2tabfile function)<br> fclose($fp);<br>}<br></pre> 1191 <p> Carriage-returns or newlines are converted to spaces. Field names are returned 1192 in the first line of text. Strings containing the delimiter character are quoted 1193 with double-quotes. Double-quotes are double-quoted again. This conforms to 1194 Excel import and export guide-lines. 1195 </p><p>All the above functions take as an optional last parameter, $addtitles which 1196 defaults to <i>true</i>. When set to <i>false</i> field names in the first line 1197 are suppressed. <br> 1198 </p><h3>Example 10: Recordset Filters<a name="ex10"></a></h3> 1199 <p>Sometimes we want to pre-process all rows in a recordset before we use it. 1200 For example, we want to ucwords all text in recordset. 1201 </p><pre>include_once('adodb/rsfilter.inc.php');<br>include_once('adodb/adodb.inc.php');<br><br>// ucwords() every element in the recordset<br>function do_ucwords(&$arr,$rs)<br>{<br> foreach($arr as $k => $v) {<br> $arr[$k] = ucwords($v);<br> }<br>}<br><br>$db = NewADOConnection('mysql');<br>$db->PConnect('server','user','pwd','db');<br><br>$rs = $db->Execute('select ... from table');<br>$rs = <b>RSFilter</b>($rs,'do_ucwords');<br></pre> 1202 <p>The <i>RSFilter</i> function takes 2 parameters, the recordset, and the name 1203 of the <i>filter</i> function. It returns the processed recordset scrolled to 1204 the first record. The <i>filter</i> function takes two parameters, the current 1205 row as an array, and the recordset object. For future compatibility, you should 1206 not use the original recordset object. </p> 1207 <h3>Example 11:<a name="ex11"></a> Smart Transactions</h3> 1208 The old way of doing transactions required you to use 1209 <pre>$conn-><b>BeginTrans</b>();<br>$ok = $conn->Execute($sql);<br>if ($ok) $ok = $conn->Execute($sql2);<br>if (!$ok) $conn-><b>RollbackTrans</b>();<br>else $conn-><b>CommitTrans</b>();<br></pre> 1210 This is very complicated for large projects because you have to track the error 1211 status. Smart Transactions is much simpler. You start a smart transaction by calling 1212 StartTrans(): 1213 <pre>$conn-><b>StartTrans</b>();<br>$conn->Execute($sql);<br>$conn->Execute($Sql2);<br>$conn-><b>CompleteTrans</b>();<br></pre> 1214 CompleteTrans() detects when an SQL error occurs, and will Rollback/Commit as 1215 appropriate. To specificly force a rollback even if no error occured, use FailTrans(). 1216 Note that the rollback is done in CompleteTrans(), and not in FailTrans(). 1217 <pre>$conn-><b>StartTrans</b>();<br>$conn->Execute($sql);<br>if (!CheckRecords()) $conn-><strong>FailTrans</strong>();<br>$conn->Execute($Sql2);<br>$conn-><b>CompleteTrans</b>();<br></pre> 1218 <p>You can also check if a transaction has failed, using HasFailedTrans(), which 1219 returns true if FailTrans() was called, or there was an error in the SQL execution. 1220 Make sure you call HasFailedTrans() before you call CompleteTrans(), as it is 1221 only works between StartTrans/CompleteTrans. 1222 </p><p>Lastly, StartTrans/CompleteTrans is nestable, and only the outermost block 1223 is executed. In contrast, BeginTrans/CommitTrans/RollbackTrans is NOT nestable. 1224 </p><pre>$conn-><strong>StartTrans</strong>();<br>$conn->Execute($sql);<br> $conn-><strong>StartTrans</strong>(); <font color="#006600"># ignored</font> 1225 if (!CheckRecords()) $conn->FailTrans(); 1226 $conn-><strong>CompleteTrans</strong>(); <font color="#006600"># ignored</font> 1227 $conn->Execute($Sql2); 1228 $conn-><strong>CompleteTrans</strong>();<br></pre> 1229 <p>Note: Savepoints are currently not supported. 1230 </p><h2><a name="errorhandling"></a>Using Custom Error Handlers and PEAR_Error</h2> 1231 <p>ADOdb supports PHP5 exceptions. Just include <i>adodb-exceptions.inc.php</i> and you can now 1232 catch exceptions on errors as they occur. 1233 </p><pre> <b>include ("../adodb-exceptions.inc.php");</b> <br> include("../adodb.inc.php"); <br> try { <br> $db = NewADOConnection("oci8://scott:bad-password@mytns/"); <br> } catch (exception $e) { <br> var_dump($e); <br> adodb_backtrace($e->gettrace());<br> } <br></pre> 1234 <p> ADOdb also provides two custom handlers which you can modify for your needs. The 1235 first one is in the <b>adodb-errorhandler.inc.php</b> file. This makes use of 1236 the standard PHP functions <a href="http://php.net/error_reporting">error_reporting</a> 1237 to control what error messages types to display, and <a href="http://php.net/trigger_error">trigger_error</a> 1238 which invokes the default PHP error handler. 1239 </p><p> Including the above file will cause <i>trigger_error($errorstring,E_USER_ERROR)</i> 1240 to be called when<br> 1241 (a) Connect() or PConnect() fails, or <br> 1242 (b) a function that executes SQL statements such as Execute() or SelectLimit() 1243 has an error.<br> 1244 (c) GenID() appears to go into an infinite loop. 1245 </p><p> The $errorstring is generated by ADOdb and will contain useful debugging information 1246 similar to the error.log data generated below. This file adodb-errorhandler.inc.php 1247 should be included before you create any ADOConnection objects. 1248 </p><p> If you define error_reporting(0), no errors will be passed to the error handler. 1249 If you set error_reporting(E_ALL), all errors will be passed to the error handler. 1250 You still need to use <b>ini_set("display_errors", "0" or "1")</b> to control 1251 the display of errors. 1252 </p><pre><?php<br><b>error_reporting(E_ALL); # pass any error messages triggered to error handler<br>include('adodb-errorhandler.inc.php');</b> 1253 include ('adodb.inc.php'); 1254 include('tohtml.inc.php'); 1255 $c = NewADOConnection('mysql'); 1256 $c->PConnect('localhost','root','','northwind'); 1257 $rs=$c->Execute('select * from productsz'); #invalid table productsz'); 1258 if ($rs) rs2html($rs); 1259 ?> 1260 </pre> 1261 <p> If you want to log the error message, you can do so by defining the following 1262 optional constants ADODB_ERROR_LOG_TYPE and ADODB_ERROR_LOG_DEST. ADODB_ERROR_LOG_TYPE 1263 is the error log message type (see <a href="http://php.net/error_log">error_log</a> 1264 in the PHP manual). In this case we set it to 3, which means log to the file 1265 defined by the constant ADODB_ERROR_LOG_DEST. 1266 </p><pre><?php<br><b>error_reporting(E_ALL); # report all errors<br>ini_set("display_errors", "0"); # but do not echo the errors<br>define('ADODB_ERROR_LOG_TYPE',3);<br>define('ADODB_ERROR_LOG_DEST','C:/errors.log');<br>include('adodb-errorhandler.inc.php');</b> 1267 include ('adodb.inc.php'); 1268 include('tohtml.inc.php'); 1269 1270 $c = NewADOConnection('mysql'); 1271 $c->PConnect('localhost','root','','northwind'); 1272 $rs=$c->Execute('select * from productsz'); ## invalid table productsz 1273 if ($rs) rs2html($rs); 1274 ?> 1275 </pre> 1276 The following message will be logged in the error.log file: 1277 <pre>(2001-10-28 14:20:38) mysql error: [1146: Table 'northwind.productsz' doesn't exist] in<br> EXECUTE("select * from productsz")<br></pre> 1278 <h3>PEAR_ERROR</h3> 1279 The second error handler is <b>adodb-errorpear.inc.php</b>. This will create a 1280 PEAR_Error derived object whenever an error occurs. The last PEAR_Error object 1281 created can be retrieved using ADODB_Pear_Error(). 1282 <pre><?php<br><b>include('adodb-errorpear.inc.php');</b> 1283 include ('adodb.inc.php'); 1284 include('tohtml.inc.php'); 1285 $c = NewADOConnection('mysql'); 1286 $c->PConnect('localhost','root','','northwind'); 1287 $rs=$c->Execute('select * from productsz'); #invalid table productsz'); 1288 if ($rs) rs2html($rs); 1289 else { 1290 <b>$e = ADODB_Pear_Error();<br> echo '<p>',$e->message,'</p>';</b> 1291 } 1292 ?> 1293 </pre> 1294 <p> You can use a PEAR_Error derived class by defining the constant ADODB_PEAR_ERROR_CLASS 1295 before the adodb-errorpear.inc.php file is included. For easy debugging, you 1296 can set the default error handler in the beginning of the PHP script to PEAR_ERROR_DIE, 1297 which will cause an error message to be printed, then halt script execution: 1298 </p><pre>include('PEAR.php');<br>PEAR::setErrorHandling('PEAR_ERROR_DIE');<br></pre> 1299 <p> Note that we do not explicitly return a PEAR_Error object to you when an error 1300 occurs. We return false instead. You have to call ADODB_Pear_Error() to get 1301 the last error or use the PEAR_ERROR_DIE technique. 1302 </p> 1303 <h3>MetaError and MetaErrMsg</h3> 1304 <p>If you need error messages that work across multiple databases, then use <a href="#metaerror">MetaError()</a>, which returns a virtualized error number, based on PEAR DB's error number system, and <a href=<a href="#metaerrmsg">MetaErrMsg()</a>. 1305 1306 <h4>Error Messages</h4> 1307 <p>Error messages are outputted using the static method ADOConnnection::outp($msg,$newline=true). 1308 By default, it sends the messages to the client. You can override this to perform 1309 error-logging. 1310 </p><h2><a name="dsn"></a> Data Source Names</h2> 1311 <p>We now support connecting using PEAR style DSN's. A DSN is a connection string 1312 of the form:</p> 1313 <p>$dsn = <i>"$driver://$username:$password@$hostname/$databasename"</i>;</p> 1314 <p>An example:</p> 1315 <pre> $username = 'root';<br> $password = '';<br> $hostname = 'localhost';<br> $databasename = 'xphplens';<br> $driver = 'mysql';<br> $dsn = "$driver://$username:$password@$hostname/$databasename"<br> $db = NewADOConnection(); <br> # DB::Connect($dsn) also works if you include 'adodb/adodb-pear.inc.php' at the top<br> $rs = $db->query('select firstname,lastname from adoxyz');<br> $cnt = 0;<br> while ($arr = $rs->fetchRow()) {<br> print_r($arr); print "<br>";<br> }</pre> 1316 <p></p> 1317 <p> <a href="#dsnsupport">More info and connection examples</a> on the DSN format. 1318 1319 </p><h2><a name="pear"></a>PEAR Compatibility</h2> 1320 We support DSN's (see above), and the following functions: 1321 <pre><b> DB_Common</b> 1322 query - returns PEAR_Error on error 1323 limitQuery - return PEAR_Error on error 1324 prepare - does not return PEAR_Error on error 1325 execute - does not return PEAR_Error on error 1326 setFetchMode - supports ASSOC and ORDERED 1327 errorNative 1328 quote 1329 nextID 1330 disconnect 1331 1332 getOne 1333 getAssoc 1334 getRow 1335 getCol 1336 1337 <b> DB_Result</b> 1338 numRows - returns -1 if not supported 1339 numCols 1340 fetchInto - does not support passing of fetchmode 1341 fetchRows - does not support passing of fetchmode 1342 free 1343 </pre> 1344 <h2><a name="caching"></a>Caching of Recordsets</h2> 1345 <p>ADOdb now supports caching of recordsets using the CacheExecute( ), CachePageExecute( 1346 ) and CacheSelectLimit( ) functions. There are similar to the non-cache functions, 1347 except that they take a new first parameter, $secs2cache. 1348 </p><p> An example: 1349 </p><pre><b>include</b>('adodb.inc.php'); # load code common to ADOdb<br>$ADODB_CACHE_DIR = '/usr/ADODB_cache';<br>$<font color="#663300">conn</font> = &ADONewConnection('mysql'); # create a connection<br>$<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db<br><font>$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers';<br>$<font color="#663300">rs</font> = $<font color="#663300">conn</font>->CacheExecute(15,$sql);</font></pre> 1350 <p><font> The first parameter is the number of seconds to cache 1351 the query. Subsequent calls to that query will used the cached version stored 1352 in $ADODB_CACHE_DIR. To force a query to execute and flush the cache, call CacheExecute() 1353 with the first parameter set to zero. Alternatively, use the CacheFlush($sql) 1354 call. </font></p> 1355 <p><font>For the sake of security, we recommend you set <i>register_globals=off</i> 1356 in php.ini if you are using $ADODB_CACHE_DIR.</font></p> 1357 <p>In ADOdb 1.80 onwards, the secs2cache parameter is optional in CacheSelectLimit() 1358 and CacheExecute(). If you leave it out, it will use the $connection->cacheSecs 1359 parameter, which defaults to 60 minutes. 1360 </p><pre> $conn->Connect(...);<br> $conn->cacheSecs = 3600*24; # cache 24 hours<br> $rs = $conn->CacheExecute('select * from table');<br></pre> 1361 <p>Please note that magic_quotes_runtime should be turned off. <a href="http://phplens.com/lens/lensforum/msgs.php?LeNs#LensBM_forummsg">More 1362 info</a>, and do not change $ADODB_FETCH_MODE (or SetFetchMode) 1363 as the cached recordset will use the $ADODB_FETCH_MODE set when the query was executed. <font> 1364 <h2><a name="pivot"></a>Pivot Tables</h2> 1365 </font> </p><p><font>Since ADOdb 2.30, we support the generation of 1366 SQL to create pivot tables, also known as cross-tabulations. For further explanation 1367 read this DevShed <a href="http://www.devshed.com/Server_Side/MySQL/MySQLWiz/">Cross-Tabulation 1368 tutorial</a>. We assume that your database supports the SQL case-when expression. </font></p> 1369 <font> 1370 <p>In this example, we will use the Northwind database from Microsoft. In the 1371 database, we have a products table, and we want to analyze this table by <i>suppliers 1372 versus product categories</i>. We will place the suppliers on each row, and 1373 pivot on categories. So from the table on the left, we generate the pivot-table 1374 on the right:</p> 1375 </font> 1376 <table align="center" border="0" cellpadding="2" cellspacing="2"> 1377 <tbody><tr> 1378 <td> 1379 <table align="center" border="1" cellpadding="2" cellspacing="2" width="142"> 1380 <tbody><tr> 1381 <td><i>Supplier</i></td> 1382 <td><i>Category</i></td> 1383 </tr> 1384 <tr> 1385 <td>supplier1</td> 1386 <td>category1</td> 1387 </tr> 1388 <tr> 1389 <td>supplier2</td> 1390 <td>category1</td> 1391 </tr> 1392 <tr> 1393 <td>supplier2</td> 1394 <td>category2</td> 1395 </tr> 1396 </tbody></table> 1397 </td> 1398 <td> <font face="Courier New, Courier, mono">--></font></td> 1399 <td> 1400 <table align="center" border="1" cellpadding="2" cellspacing="2"> 1401 <tbody><tr> 1402 <td> </td> 1403 <td><i>category1</i></td> 1404 <td><i>category2</i></td> 1405 <td><i>total</i></td> 1406 </tr> 1407 <tr> 1408 <td><i>supplier1</i></td> 1409 <td align="right">1</td> 1410 <td align="right">0</td> 1411 <td align="right">1</td> 1412 </tr> 1413 <tr> 1414 <td><i>supplier2</i></td> 1415 <td align="right">1</td> 1416 <td align="right">1</td> 1417 <td align="right">2</td> 1418 </tr> 1419 </tbody></table> 1420 </td> 1421 </tr> 1422 </tbody></table> 1423 <font> 1424 </font><p><font>The following code will generate the SQL for a cross-tabulation: 1425 </font></p><pre><font># Query the main "product" table<br># Set the rows to SupplierName<br># and the columns to the values of Categories<br># and define the joins to link to lookup tables <br># "categories" and "suppliers"<br>#<br> include "adodb/pivottable.inc.php";<br> $sql = PivotTableSQL(<br> $gDB, # adodb connection<br> 'products p ,categories c ,suppliers s', # tables<br> 'SupplierName', # rows (multiple fields allowed)<br> 'CategoryName', # column to pivot on <br> 'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where<br>);<br></font></pre> 1426 1427 <p><font> This will generate the following SQL:</font></p> 1428 <p><code><font size="2">SELECT SupplierName, <br> 1429 SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 1430 <br> 1431 SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 1432 <br> 1433 SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 1434 <br> 1435 SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy 1436 Products", <br> 1437 SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 1438 <br> 1439 SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 1440 <br> 1441 SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 1442 <br> 1443 SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 1444 <br> 1445 SUM(1) as Total <br> 1446 FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID 1447 and s.SupplierID= p.SupplierID <br> 1448 GROUP BY SupplierName</font></code></p> 1449 <p> You can also pivot on <i>numerical columns</i> and <i>generate totals</i> 1450 by using ranges. <font>This code was revised in ADODB 2.41 1451 and is not backward compatible.</font> The second example shows this:</p> 1452 <pre> $sql = PivotTableSQL(<br> $gDB, # adodb connection<br> 'products p ,categories c ,suppliers s', # tables<br> 'SupplierName', #<font> rows (multiple fields allowed)</font> 1453 array( # column ranges 1454 ' 0 ' => 'UnitsInStock <= 0', 1455 "1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5', 1456 "6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10', 1457 "11 to 15" => '10 < UnitsInStock and UnitsInStock <= 15', 1458 "16+" => '15 < UnitsInStock' 1459 ), 1460 ' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where 1461 'UnitsInStock', # sum this field 1462 'Sum ' # sum label prefix 1463 ); 1464 </pre> 1465 <p>Which generates: </p> 1466 <p> <code> <font size="2">SELECT SupplierName, <br> 1467 SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum 1468 0 ", <br> 1469 SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock 1470 ELSE 0 END) AS "Sum 1 to 5",<br> 1471 SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock 1472 ELSE 0 END) AS "Sum 6 to 10",<br> 1473 SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock 1474 ELSE 0 END) AS "Sum 11 to 15", <br> 1475 SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 1476 16+", <br> 1477 SUM(UnitsInStock) AS "Sum UnitsInStock", <br> 1478 SUM(1) as Total,<br> 1479 FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID 1480 and s.SupplierID= p.SupplierID <br> 1481 GROUP BY SupplierName</font></code><font size="2"><br> 1482 </font> </p> 1483 <font><hr /> 1484 <h1>Class Reference<a name="ref"></a></h1> 1485 <p>Function parameters with [ ] around them are optional.</p> 1486 </font> 1487 <h2>Global Variables</h2> 1488 <h3><font><a name="adodb_countrecs"></a></font>$ADODB_COUNTRECS</h3> 1489 <p>If the database driver API does not support counting the number of records 1490 returned in a SELECT statement, the function RecordCount() is emulated when 1491 the global variable $ADODB_COUNTRECS is set to true, which is the default. 1492 We emulate this by buffering the records, which can take up large amounts 1493 of memory for big recordsets. Set this variable to false for the best performance. 1494 This variable is checked every time a query is executed, so you can selectively 1495 choose which recordsets to count.</p> 1496 <h3><font><a name="adodb_cache_dir"></a>$ADODB_CACHE_DIR</font></h3> 1497 <font> 1498 <p>If you are using recordset caching, this is the directory to save your recordsets 1499 in. Define this before you call any caching functions such as CacheExecute( 1500 ). We recommend setting <i>register_globals=off</i> in php.ini if you use this 1501 feature for security reasons.</p> 1502 <p>If you are using Unix and apache, you might need to set your cache directory 1503 permissions to something similar to the following:</p> 1504 </font> 1505 <p>chown -R apache /path/to/adodb/cache<br> 1506 chgrp -R apache /path/to/adodb/cache </p> 1507 <h3><font><a name="adodb_ansi_padding_off"></a>$ADODB_ANSI_PADDING_OFF</font></h3> 1508 <p><font>Determines whether to right trim CHAR fields (and also VARCHAR for ibase/firebird). 1509 Set to true to trim. Default is false. Currently works for oci8po, ibase and firebird 1510 drivers. Added in ADOdb 4.01. 1511 </font></p><h3><font><a name="adodb_lang"></a>$ADODB_LANG</font></h3> 1512 <p><font>Determines the language used in MetaErrorMsg(). The default is 'en', for English. 1513 To find out what languages are supported, see the files 1514 in adodb/lang/adodb-$lang.inc.php, where $lang is the supported langauge. 1515 </font></p><h3><font><a name="adodb_fetch_mode"></a>$ADODB_FETCH_MODE</font></h3> 1516 <p><font>This is a global variable that determines how arrays are retrieved by recordsets. 1517 The recordset saves this value on creation (eg. in Execute( ) or SelectLimit( 1518 )), and any subsequent changes to $ADODB_FETCH_MODE have no affect on existing 1519 recordsets, only on recordsets created in the future.</font></p> 1520 <p><font>The following constants are defined:</font></p> 1521 <p><font>define('ADODB_FETCH_DEFAULT',0);<br> 1522 define('ADODB_FETCH_NUM',1);<br> 1523 define('ADODB_FETCH_ASSOC',2);<br> 1524 define('ADODB_FETCH_BOTH',3); </font></p> 1525 <font> 1526 </font><p><font> An example: 1527 </font></p><pre><font> $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_NUM;<br> $rs1 = $db->Execute('select * from table');<br> $ADODB_<b>FETCH_MODE</b> = ADODB_FETCH_ASSOC;<br> $rs2 = $db->Execute('select * from table');<br> print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i> 1528 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i> 1529 </font></pre> 1530 <p><font> As you can see in the above example, both recordsets store and use different 1531 fetch modes based on the $ADODB_FETCH_MODE setting when the recordset was 1532 created by Execute().</font></p> 1533 <p><font>If no fetch mode is predefined, the fetch mode defaults to ADODB_FETCH_DEFAULT. 1534 The behaviour of this default mode varies from driver to driver, so do not 1535 rely on ADODB_FETCH_DEFAULT. For portability, we recommend sticking to ADODB_FETCH_NUM 1536 or ADODB_FETCH_ASSOC. Many drivers do not support ADODB_FETCH_BOTH.</font></p> 1537 <p><font><strong>SetFetchMode Function</strong></font></p> 1538 <p><font>If you have multiple connection objects, and want to have different fetch modes for each 1539 connection, then use <a href="#setfetchmode">SetFetchMode</a>. 1540 Once this function is called for a connection object, that connection object 1541 will ignore the global variable $ADODB_FETCH_MODE and will use the internal 1542 fetchMode property exclusively.</font></p> 1543 <pre><font> $db->SetFetchMode(ADODB_FETCH_NUM);<br> $rs1 = $db->Execute('select * from table');<br> $db->SetFetchMode(ADODB_FETCH_ASSOC);<br> $rs2 = $db->Execute('select * from table');<br> print_r($rs1->fields); # shows <i>array([0]=>'v0',[1] =>'v1')</i> 1544 print_r($rs2->fields); # shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i></font></pre> 1545 <p><font>To retrieve the previous fetch mode, you can use check the $db->fetchMode 1546 property, or use the return value of SetFetchMode( ). 1547 </font></p><p><font><strong><a name="adodb_assoc_case"></a>ADODB_ASSOC_CASE</strong></font></p> 1548 <p><font>You can control the associative fetch case for certain drivers which behave 1549 differently. For the sybase, oci8po, mssql, odbc and ibase drivers and all 1550 drivers derived from them, ADODB_ASSOC_CASE will by default generate recordsets 1551 where the field name keys are lower-cased. Use the constant ADODB_ASSOC_CASE 1552 to change the case of the keys. There are 3 possible values:</font></p> 1553 <p><font>0 = assoc lowercase field names. $rs->fields['orderid']<br> 1554 1 = assoc uppercase field names. $rs->fields['ORDERID']<br> 1555 2 = use native-case field names. $rs->fields['OrderID'] -- this is the 1556 default since ADOdb 2.90</font></p> 1557 <p><font>To use it, declare it before you incldue adodb.inc.php.</font></p> 1558 <p><font>define('ADODB_ASSOC_CASE', 2); # use native-case for ADODB_FETCH_ASSOC<br> 1559 include ('adodb.inc.php'); </font></p> 1560 <h3><font><a name="force_type"></a>$ADODB_FORCE_TYPE</font></h3> 1561 <p><font>See the <a href="#ADODB_FORCE_TYPE">GetUpdateSQL tutorial</a>. 1562 </font></p> 1563 <h3><font><a name="adodb_auto_quote"></a>$ADODB_QUOTE_FIELDNAMES</font></h3> 1564 <p><font>Auto-quotes field names when using AutoExecute() when set to true. </font> 1565 <p> </p> 1566 <hr /> 1567 <h2><font>ADOConnection<a name="adoconnection"></a></font></h2> 1568 <p><font>Object that performs the connection to the database, executes SQL statements 1569 and has a set of utility functions for standardising the format of SQL statements 1570 for issues such as concatenation and date formats.</font></p> 1571 <h3><font>ADOConnection Fields</font></h3> 1572 <p><font><b>databaseType</b>: Name of the database system we are connecting to. Eg. 1573 <b>odbc</b> or <b>mssql</b> or <b>mysql</b>.</font></p> 1574 <p><font><b>dataProvider</b>: The underlying mechanism used to connect to the database. 1575 Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</font></p> 1576 <p><font><b>host: </b>Name of server or data source name (DSN) to connect to.</font></p> 1577 <p><font><b>database</b>: Name of the database or to connect to. If ado is used, it 1578 will hold the ado data provider.</font></p> 1579 <p><font><b>user</b>: Login id to connect to database. Password is not saved for security 1580 reasons.</font></p> 1581 <p><font><b>raiseErrorFn</b>: Allows you to define an error handling function. See adodb-errorhandler.inc.php 1582 for an example.</font></p> 1583 <p><font><b>debug</b>: Set to <i>true</i> to make debug statements to appear.</font></p> 1584 <p><font><b>concat_operator</b>: Set to '+' or '||' normally. The operator used to concatenate 1585 strings in SQL. Used by the <b><a href="#concat">Concat</a></b> function.</font></p> 1586 <p><font><b>fmtDate</b>: The format used by the <b><a href="#dbdate">DBDate</a></b> 1587 function to send dates to the database. is '#Y-m-d#' for Microsoft Access, 1588 and ''Y-m-d'' for MySQL.</font></p> 1589 <p><font><b>fmtTimeStamp: </b>The format used by the <b><a href="#dbtimestamp">DBTimeStamp</a></b> 1590 function to send timestamps to the database. </font></p> 1591 <p><font><b>true</b>: The value used to represent true.Eg. '.T.'. for Foxpro, '1' for 1592 Microsoft SQL.</font></p> 1593 <p><font><b>false: </b> The value used to represent false. Eg. '.F.'. for Foxpro, '0' 1594 for Microsoft SQL.</font></p> 1595 <p><font><b>replaceQuote</b>: The string used to escape quotes. Eg. double single-quotes 1596 for Microsoft SQL, and backslash-quote for MySQL. Used by <a href="#qstr">qstr</a>.</font></p> 1597 <p><font><b>autoCommit</b>: indicates whether automatic commit is enabled. Default is 1598 true.</font></p> 1599 <p><font><b>charSet</b>: set the default charset to use. Currently only interbase/firebird supports 1600 this.</font></p> 1601 <p><font><b>dialect</b>: set the default sql dialect to use. Currently only interbase/firebird 1602 supports this.</font></p> 1603 <p><font><b>role</b>: set the role. Currently only interbase/firebird 1604 supports this.</font></p> 1605 <p><font><b>metaTablesSQL</b>: SQL statement to return a list of available tables. Eg. 1606 <i>SHOW TABLES</i> in MySQL.</font></p> 1607 <p><font><b>genID</b>: The latest id generated by GenID() if supported by the database.</font></p> 1608 <p><font><b>cacheSecs</b>: The number of seconds to cache recordsets if CacheExecute() 1609 or CacheSelectLimit() omit the $secs2cache parameter. Defaults to 60 minutes.</font></p> 1610 <p><font><b>sysDate</b>: String that holds the name of the database function to call 1611 to get the current date. Useful for inserts and updates.</font></p> 1612 <p><font><b>sysTimeStamp</b>: String that holds the name of the database function to 1613 call to get the current timestamp/datetime value.</font></p> 1614 <p><font><b>leftOuter</b>: String that holds operator for left outer join, if known. 1615 Otherwise set to false.</font></p> 1616 <p><font><b>rightOuter</b>: String that holds operator for left outer join, if known. 1617 Otherwise set to false.</font></p> 1618 <p><font><b>ansiOuter</b>: Boolean that if true indicates that ANSI style outer joins 1619 are permitted. Eg. <i>select * from table1 left join table2 on p1=p2.</i></font></p> 1620 <p><font><b>connectSID</b>: Boolean that indicates whether to treat the $database parameter 1621 in connects as the SID for the oci8 driver. Defaults to false. Useful for 1622 Oracle 8.0.5 and earlier.</font></p> 1623 <p><font><b>autoRollback</b>: Persistent connections are auto-rollbacked in PConnect( 1624 ) if this is set to true. Default is false.</font></p> 1625 <hr /> 1626 <h3><font>ADOConnection Main Functions</font></h3> 1627 <p><font><b>ADOConnection( )</b></font></p> 1628 <p><font>Constructor function. Do not call this directly. Use ADONewConnection( ) instead.</font></p> 1629 <p><font><b>Connect<a name="connect"></a>($host,[$user],[$password],[$database])</b></font></p> 1630 <p><font>Non-persistent connect to data source or server $<b>host</b>, using userid 1631 $<b>user </b>and password $<b>password</b>. If the server supports multiple 1632 databases, connect to database $<b>database</b>. </font></p> 1633 <p><font>Returns true/false depending on connection success. Since 4.23, null is returned if the extension is not loaded.</font></p> 1634 <p><font>ADO Note: If you are using a Microsoft ADO and not OLEDB, you can set the $database 1635 parameter to the OLEDB data provider you are using.</font></p> 1636 <p><font>PostgreSQL: An alternative way of connecting to the database is to pass the 1637 standard PostgreSQL connection string in the first parameter $host, and the 1638 other parameters will be ignored.</font></p> 1639 <p><font>For Oracle and Oci8, there are two ways to connect. First is to use the TNS 1640 name defined in your local tnsnames.ora (or ONAMES or HOSTNAMES). Place the 1641 name in the $database field, and set the $host field to false. Alternatively, 1642 set $host to the server, and $database to the database SID, this bypassed 1643 tnsnames.ora. 1644 </font></p><p><font>Examples: 1645 </font></p><pre><font> # $oraname in tnsnames.ora/ONAMES/HOSTNAMES<br> $conn->Connect(false, 'scott', 'tiger', $oraname); <br> $conn->Connect('server:1521', 'scott', 'tiger', 'ServiceName'); # bypass tnsnames.ora</font></pre> 1646 <p><font>There are many examples of connecting to a database. 1647 See <a href="#connect_ex">Connection Examples</a> for many examples. 1648 1649 </font></p><p><font><b>PConnect<a name="pconnect"></a>($host,[$user],[$password],[$database])</b></font></p> 1650 <p><font>Persistent connect to data source or server $<b>host</b>, using userid $<b>user</b> 1651 and password $<b>password</b>. If the server supports multiple databases, 1652 connect to database $<b>database</b>.</font></p> 1653 <p><font>We now perform a rollback on persistent connection for selected databases since 1654 2.21, as advised in the PHP manual. See change log or source code for which 1655 databases are affected. 1656 </font></p><p><font>Returns true/false depending on connection. Since 4.23, 0 is returned if the extension is not loaded. 1657 See Connect( ) above for more info.</font></p> 1658 <p><font>Since ADOdb 2.21, we also support autoRollback. If you set:</font></p> 1659 1660 <pre> $conn = &NewADOConnection('mysql');<br> $conn->autoRollback = true; # default is false<br> $conn->PConnect(...); # rollback here</pre> 1661 <p> Then when doing a persistent connection with PConnect( ), ADOdb will 1662 perform a rollback first. This is because it is documented that PHP is 1663 not guaranteed to rollback existing failed transactions when 1664 persistent connections are used. This is implemented in Oracle, 1665 MySQL, PgSQL, MSSQL, ODBC currently. 1666 </p><p>Since ADOdb 3.11, you can force non-persistent 1667 connections even if PConnect is called by defining the constant 1668 ADODB_NEVER_PERSIST before you call PConnect. 1669 </p><p> 1670 Since 4.23, null is returned if the extension is not loaded. 1671 </p><p><b>NConnect<a name="nconnect"></a>($host,[$user],[$password],[$database])</b></p> 1672 <p>Always force a new connection. In contrast, PHP sometimes reuses connections 1673 when you use Connect() or PConnect(). Currently works only on mysql (PHP 4.3.0 1674 or later), postgresql and oci8-derived drivers. For other drivers, NConnect() works like 1675 Connect().</p> 1676 <p><font><b>IsConnected( )<a name="isconnected"></a></b></font></p> 1677 <p> 1678 <font>Returns true if connected to database. Added in 4.53. 1679 1680 </font></p><p><font><b>Execute<a name="execute"></a>($sql,$inputarr=false)</b></font></p> 1681 <p><font>Execute SQL statement $<b>sql</b> and return derived class of ADORecordSet 1682 if successful. Note that a record set is always returned on success, even 1683 if we are executing an insert or update statement. You can also pass in $sql a statement prepared 1684 in <a href="#prepare">Prepare()</a>.</font></p> 1685 <p><font>Returns derived class of ADORecordSet. Eg. if connecting via mysql, then ADORecordSet_mysql 1686 would be returned. False is returned if there was an error in executing the 1687 sql.</font></p> 1688 <p><font>The $inputarr parameter can be used for binding variables to parameters. Below 1689 is an Oracle example:</font></p> 1690 <pre><font> $conn->Execute("SELECT * FROM TABLE WHERE COND=:val", array('val'=> $val));<br> </font></pre> 1691 <p><font>Another example, using ODBC,which uses the ? convention:</font></p> 1692 <pre><font> $conn->Execute("SELECT * FROM TABLE WHERE COND=?", array($val));<br></font></pre> 1693 <font><a name="binding"></a> 1694 <i>Binding variables</i></font><p> 1695 <font>Variable binding speeds the compilation and caching of SQL statements, leading 1696 to higher performance. Currently Oracle, Interbase and ODBC supports variable binding. 1697 Interbase/ODBC style ? binding is emulated in databases that do not support binding. 1698 Note that you do not have to quote strings if you use binding. 1699 </font></p><p><font> Variable binding in the odbc, interbase and oci8po drivers. 1700 </font></p><pre><font>$rs = $db->Execute('select * from table where val=?', array('10'));<br></font></pre> 1701 <font>Variable binding in the oci8 driver: 1702 </font><pre><font>$rs = $db->Execute('select name from table where val=:key', <br> array('key' => 10));<br></font></pre> 1703 <font><a name="bulkbind"></a> 1704 <i>Bulk binding</i> 1705 </font><p><font>Since ADOdb 3.80, we support bulk binding in Execute(), in which you pass in a 2-dimensional array to 1706 be bound to an INSERT/UPDATE or DELETE statement. 1707 </font></p><pre><font>$arr = array(<br> array('Ahmad',32),<br> array('Zulkifli', 24),<br> array('Rosnah', 21)<br> );<br>$ok = $db->Execute('insert into table (name,age) values (?,?)',$arr);<br></font></pre> 1708 <p><font>This provides very high performance as the SQL statement is prepared first. 1709 The prepared statement is executed repeatedly for each array row until all rows are completed, 1710 or until the first error. Very useful for importing data. 1711 1712 </font></p><p><font><b>CacheExecute<a name="cacheexecute"></a>([$secs2cache,]$sql,$inputarr=false)</b></font></p> 1713 <p><font>Similar to Execute, except that the recordset is cached for $secs2cache seconds 1714 in the $ADODB_CACHE_DIR directory, and $inputarr only accepts 1-dimensional arrays. 1715 If CacheExecute() is called again with the same $sql, $inputarr, 1716 and also the same database, same userid, and the cached recordset 1717 has not expired, the cached recordset is returned. 1718 </font></p><pre><font> include ('adodb.inc.php'); <br> include('tohtml.inc.php');<br> $ADODB_<b>CACHE_DIR</b> = '/usr/local/ADOdbcache';<br> $conn = &ADONewConnection('mysql'); <br> $conn->PConnect('localhost','userid','password','database');<br> $rs = $conn-><b>CacheExecute</b>(15, 'select * from table'); # cache 15 secs<br> rs2html($rs); /* recordset to html table */ <br></font></pre> 1719 <p><font> Alternatively, since ADOdb 1.80, the $secs2cache parameter is optional:</font></p> 1720 <pre><font> $conn->Connect(...);<br> $conn->cacheSecs = 3600*24; // cache 24 hours<br> $rs = $conn->CacheExecute('select * from table');<br></font></pre> 1721 <font>If $secs2cache is omitted, we use the value 1722 in $connection->cacheSecs (default is 3600 seconds, or 1 hour). Use CacheExecute() 1723 only with SELECT statements. 1724 </font><p><font>Performance note: I have done some benchmarks and found that they vary so greatly 1725 that it's better to talk about when caching is of benefit. When your database 1726 server is <i>much slower </i>than your Web server or the database is <i>very 1727 overloaded </i>then ADOdb's caching is good because it reduces the load on 1728 your database server. If your database server is lightly loaded or much faster 1729 than your Web server, then caching could actually reduce performance. </font></p> 1730 <p><font><b>ExecuteCursor<a name="executecursor"></a>($sql,$cursorName='rs',$parameters=false)</b></font></p> 1731 <p><font>Execute an Oracle stored procedure, and returns an Oracle REF cursor variable as 1732 a regular ADOdb recordset. Does not work with any other database except oci8. 1733 Thanks to Robert Tuttle for the design. 1734 </font></p><pre><font> $db = ADONewConnection("oci8"); <br> $db->Connect("foo.com:1521", "uid", "pwd", "FOO"); <br> $rs = $db->ExecuteCursor("begin :cursorvar := getdata(:param1); end;", <br> 'cursorvar',<br> array('param1'=>10)); <br> # $rs is now just like any other ADOdb recordset object<br> rs2html($rs);</font></pre> 1735 <p><font>ExecuteCursor() is a helper function that does the following internally: 1736 </font></p><pre><font> $stmt = $db->Prepare("begin :cursorvar := getdata(:param1); end;", true); <br> $db->Parameter($stmt, $cur, 'cursorvar', false, -1, OCI_B_CURSOR);<br> $rs = $db->Execute($stmt,$bindarr);<br></font></pre> 1737 <p><font>ExecuteCursor only accepts 1 out parameter. So if you have 2 out parameters, use: 1738 </font></p><pre><font> $vv = 'A%';<br> $stmt = $db->PrepareSP("BEGIN list_tabs(:crsr,:tt); END;");<br> $db->OutParameter($stmt, $cur, 'crsr', -1, OCI_B_CURSOR);<br> $db->OutParameter($stmt, $vv, 'tt', 32); # return varchar(32)<br> $arr = $db->GetArray($stmt);<br> print_r($arr);<br> echo " val = $vv"; ## outputs 'TEST'<br></font></pre> 1739 <font>for the following PL/SQL: 1740 </font><pre><font> TYPE TabType IS REF CURSOR RETURN TAB%ROWTYPE;<br><br> PROCEDURE list_tabs(tabcursor IN OUT TabType,tablenames IN OUT VARCHAR) IS<br> BEGIN<br> OPEN tabcursor FOR SELECT * FROM TAB WHERE tname LIKE tablenames;<br> tablenames := 'TEST';<br> END list_tabs;<br></font></pre> 1741 <p><font><b>SelectLimit<a name="selectlimit"></a>($sql,$numrows=-1,$offset=-1,$inputarr=false)</b></font></p> 1742 <p><font>Returns a recordset if successful. Returns false otherwise. Performs a select 1743 statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET 1744 $offset clause.</font></p> 1745 <p><font>In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records 1746 only. The equivalent is <code>$connection->SelectLimit('SELECT * FROM TABLE',3)</code>. 1747 This functionality is simulated for databases that do not possess this feature.</font></p> 1748 <p><font>And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg. 1749 after record 2, return 3 rows). The equivalent in ADOdb is <code>$connection->SelectLimit('SELECT 1750 * FROM TABLE',3,2)</code>.</font></p> 1751 <p><font>Note that this is the <i>opposite</i> of MySQL's LIMIT clause. You can also 1752 set <code>$connection->SelectLimit('SELECT * FROM TABLE',-1,10)</code> to 1753 get rows 11 to the last row.</font></p> 1754 <p><font>The last parameter $inputarr is for databases that support variable binding 1755 such as Oracle oci8. This substantially reduces SQL compilation overhead. 1756 Below is an Oracle example:</font></p> 1757 <pre><font> $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val));<br> </font></pre> 1758 <p><font>The oci8po driver (oracle portable driver) uses the more standard bind variable 1759 of ?: 1760 </font></p><pre><font> $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val));<br></font></pre> 1761 <p><font> 1762 </font></p><p><font>Ron Wilson reports that SelectLimit does not work with UNIONs. 1763 </font></p><p><font><b>CacheSelectLimit<a name="cacheselectlimit"></a>([$secs2cache,] $sql, $numrows=-1,$offset=-1,$inputarr=false)</b></font></p> 1764 <p><font>Similar to SelectLimit, except that the recordset returned is cached for $secs2cache 1765 seconds in the $ADODB_CACHE_DIR directory. </font></p> 1766 <p><font>Since 1.80, $secs2cache has been optional, and you can define the caching time 1767 in $connection->cacheSecs.</font></p> 1768 1769 <pre><font> $conn->Connect(...);<br> $conn->cacheSecs = 3600*24; // cache 24 hours<br> $rs = $conn->CacheSelectLimit('select * from table',10);</font></pre> 1770 <font> 1771 </font><p><font><b>CacheFlush<a name="cacheflush"></a>($sql=false,$inputarr=false)</b></font></p> 1772 <p><font>Flush (delete) any cached recordsets for the SQL statement $sql in $ADODB_CACHE_DIR. 1773 </font></p><p><font>If no parameter is passed in, then all adodb_*.cache files are deleted. 1774 </font></p> 1775 <p>CacheSelectLimit() rewrites the SQL query, so you won't be able to pass the SQL to CacheFlush. In this case, 1776 to flush the cached SQL recordset returned by CacheSelectLimit(), set $secs2cache to -1: 1777 <pre> 1778 $db->CacheSelectLimit(-1, $sql, $nrows); 1779 </pre> 1780 <p><font> If you want to flush all cached recordsets manually, execute the following 1781 PHP code (works only under Unix): <br> 1782 <code> system("rm -f `find ".$ADODB_CACHE_DIR." -name 1783 adodb_*.cache`");</code></font></p> 1784 <p><font>For general cleanup of all expired files, you should use <a href="http://www.superscripts.com/tutorial/crontab.html">crontab</a> 1785 on Unix, or at.exe on Windows, and a shell script similar to the following:<font face="Courier New, Courier, mono"><br> 1786 #------------------------------------------------------ <br> 1787 # This particular example deletes files in the TMPPATH <br> 1788 # directory with the string ".cache" in their name that <br> 1789 # are more than 7 days old. <br> 1790 #------------------------------------------------------ <br> 1791 AGED=7 <br> 1792 find $TMPPATH} -mtime +$AGED | grep "\.cache" | xargs rm -f <br> 1793 </font> </font></p> 1794 <p><font><b>MetaError<a name="metaerror"></a>($errno=false)</b></font></p> 1795 <p><font>Returns a virtualized error number, based on PEAR DB's error number system. You might 1796 need to include adodb-error.inc.php before you call this function. The parameter $errno 1797 is the native error number you want to convert. If you do not pass any parameter, MetaError 1798 will call ErrorNo() for you and convert it. If the error number cannot be virtualized, MetaError 1799 will return -1 (DB_ERROR).</font></p> 1800 1801 <p><font><b>MetaErrorMsg<a name="metaerrormsg"></a>($errno)</b></font></p> 1802 <p><font>Pass the error number returned by MetaError() for the equivalent textual error message.</font></p> 1803 <p><font><b>ErrorMsg<a name="errormsg"></a>()</b></font></p> 1804 <p><font>Returns the last status or error message. The error message is reset after every 1805 call to Execute(). 1806 </font></p><p> 1807 <font>This can return a string even if 1808 no error occurs. In general you do not need to call this function unless an 1809 ADOdb function returns false on an error. </font></p> 1810 <p><font>Note: If <b>debug</b> is enabled, the SQL error message is always displayed 1811 when the <b>Execute</b> function is called.</font></p> 1812 <p><font><b>ErrorNo<a name="errorno"></a>()</b></font></p> 1813 <p><font>Returns the last error number. The error number is reset after every call to Execute(). 1814 If 0 is returned, no error occurred. 1815 </font></p><p> 1816 <font>Note that old versions of PHP (pre 4.0.6) do 1817 not support error number for ODBC. In general you do not need to call this 1818 function unless an ADOdb function returns false on an error.</font></p> 1819 <p><font><b>IgnoreErrors<a name="ignoreerrors"></a>($saveErrHandlers)</b></font></p> 1820 <p>Allows you to ignore errors so that StartTrans()/CompleteTrans() is not affected, nor is the default error handler called if an error occurs. 1821 Useful when you want to check if a field or table exists in a database without invoking an error if it does not exist. 1822 <p>Usage: 1823 <pre> 1824 $saveErrHandlers = $conn->IgnoreErrors(); 1825 $rs = $conn->Execute("select field from some_table_that_might_not_exist"); 1826 $conn->IgnoreErrors($saveErrHandlers); 1827 </pre> 1828 <p>Warning: do not call StartTrans()/CompleteTrans() inside a code block that is using IgnoreErrors(). 1829 <p><font><b>SetFetchMode<a name="setfetchmode"></a>($mode)</b></font></p> 1830 <p><font>Sets the current fetch mode for the connection and stores 1831 it in $db->fetchMode. Legal modes are ADODB_FETCH_ASSOC and ADODB_FETCH_NUM. 1832 For more info, see <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>.</font></p> 1833 <p><font>Returns the previous fetch mode, which could be false 1834 if SetFetchMode( ) has not been called before.</font></p> 1835 <font> 1836 </font><p><font><b>CreateSequence<a name="createseq"></a>($seqName = 'adodbseq',$startID=1)</b></font></p> 1837 <p><font>Create a sequence. The next time GenID( ) is called, the value returned will 1838 be $startID. Added in 2.60. 1839 </font></p><p><font><b>DropSequence<a name="dropseq"></a>($seqName = 'adodbseq')</b></font></p> 1840 <p><font>Delete a sequence. Added in 2.60. 1841 </font></p><p><font><b>GenID<a name="genid"></a>($seqName = 'adodbseq',$startID=1)</b></font></p> 1842 <p><font>Generate a sequence number . Works for interbase, 1843 mysql, postgresql, oci8, oci8po, mssql, ODBC based (access,vfp,db2,etc) drivers 1844 currently. Uses $seqName as the name of the sequence. GenID() will automatically 1845 create the sequence for you if it does not exist (provided the userid has 1846 permission to do so). Otherwise you will have to create the sequence yourself. 1847 </font></p><p><font> If your database driver emulates sequences, the name of the table is the sequence 1848 name. The table has one column, "id" which should be of type integer, or if 1849 you need something larger - numeric(16). 1850 </font></p><p><font> For ODBC and databases that do not support sequences natively (eg mssql, mysql), 1851 we create a table for each sequence. If the sequence has not been defined 1852 earlier, it is created with the starting value set in $startID.</font></p> 1853 <p><font>Note that the mssql driver's GenID() before 1.90 used to generate 16 byte GUID's.</font></p> 1854 <p><font><b>UpdateBlob<a name="updateblob"></a>($table,$column,$val,$where)</b></font></p> 1855 <font>Allows you to store a blob (in $val) into $table into $column in a row at $where. 1856 </font><p><font> Usage: 1857 </font></p><p><font> 1858 </font></p><pre><font> # for oracle<br> $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, empty_blob())');<br> $conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');<br> <br> # non oracle databases<br> $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');<br> $conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');<br></font></pre> 1859 <p><font> Returns true if succesful, false otherwise. Supported by MySQL, PostgreSQL, 1860 Oci8, Oci8po and Interbase drivers. Other drivers might work, depending on 1861 the state of development.</font></p> 1862 <p><font>Note that when an Interbase blob is retrieved using SELECT, it still needs 1863 to be decoded using $connection->DecodeBlob($blob); to derive the original 1864 value in versions of PHP before 4.1.0. 1865 </font></p><p><font>For PostgreSQL, you can store your blob using blob oid's or as a bytea field. 1866 You can use bytea fields but not blob oid's currently with UpdateBlob( ). 1867 Conversely UpdateBlobFile( ) supports oid's, but not bytea data.<br> 1868 <br> 1869 If you do not pass in an oid, then UpdateBlob() assumes that you are storing 1870 in bytea fields. 1871 <p>If you do not have any blob fields, you can improve you can improve general SQL query performance by disabling blob handling with $connection->disableBlobs = true. 1872 </p></font><p><font><b>UpdateClob<a name="updateclob"></a>($table,$column,$val,$where)</b></font></p> 1873 <font>Allows you to store a clob (in $val) into $table into $column in a row at $where. 1874 Similar to UpdateBlob (see above), but for Character Large OBjects. 1875 </font><p><font> Usage: 1876 </font></p><pre><font> # for oracle<br> $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, empty_clob())');<br> $conn->UpdateBlob('clobtable','clobcol',$clobvalue,'id=1');<br> <br> # non oracle databases<br> $conn->Execute('INSERT INTO clobtable (id, clobcol) VALUES (1, null)');<br> $conn->UpdateBlob('clobtable','clobcol',$clobvalue,'id=1');<br></font></pre> 1877 <p><font><b>UpdateBlobFile<a name="updateblobfile"></a>($table,$column,$path,$where,$blobtype='BLOB')</b></font></p> 1878 <p><font>Similar to UpdateBlob, except that we pass in a file path to where the blob 1879 resides. 1880 </font></p><p><font>For PostgreSQL, if you are using blob oid's, use this interface. This interface 1881 does not support bytea fields. 1882 </font></p><p><font>Returns true if successful, false otherwise. 1883 </font></p><p><font><b>BlobEncode<a name="blobencode" id="blobencode"></a>($blob)</b> 1884 </font></p><p><font>Some databases require blob's to be encoded manually before upload. Note if 1885 you use UpdateBlob( ) or UpdateBlobFile( ) the conversion is done automatically 1886 for you and you do not have to call this function. For PostgreSQL, currently, 1887 BlobEncode() can only be used for bytea fields. 1888 </font></p><p><font>Returns the encoded blob value. 1889 </font></p><p><font>Note that there is a connection property called <em>blobEncodeType</em> which 1890 has 3 legal values: 1891 </font></p><p><font>false - no need to perform encoding or decoding.<br> 1892 'I' - blob encoding required, and returned encoded blob is a numeric value 1893 (no need to quote).<br> 1894 'C' - blob encoding required, and returned encoded blob is a character value 1895 (requires quoting). 1896 </font></p><p><font>This is purely for documentation purposes, so that programs that accept multiple 1897 database drivers know what is the right thing to do when processing blobs. 1898 </font></p><p><font><strong>BlobDecode<a name="blobdecode"></a>($blob, $maxblobsize = false)</strong> 1899 </font></p><p><font>Some databases require blob's to be decoded manually after doing a select statement. 1900 If the database does not require decoding, then this function will return 1901 the blob unchanged. Currently BlobDecode is only required for one database, 1902 PostgreSQL, and only if you are using blob oid's (if you are using bytea fields, 1903 we auto-decode for you).</font> The default maxblobsize is set in $connection->maxblobsize, which 1904 is set to 256K in adodb 4.54. </p><p> 1905 In ADOdb 4.54 and later, the blob is the return value. In earlier versions, the blob data is sent to stdout.</p><font> 1906 </font><p></p><pre><font>$rs = $db->Execute("select bloboid from postgres_table where id=$key");<br>$blob = $db->BlobDecode( reset($rs->fields) );</font></pre> 1907 <p><font><b>Replace<a name="replace"></a>($table, $arrFields, $keyCols,$autoQuote=false)</b></font></p> 1908 <p><font>Try to update a record, and if the record is not found, an insert statement 1909 is generated and executed. Returns 0 on failure, 1 if update statement worked, 1910 2 if no record was found and the insert was executed successfully. This differs 1911 from MySQL's replace which deletes the record and inserts a new record. This 1912 also means you cannot update the primary key. The only exception to this is 1913 Interbase and its derivitives, which uses delete and insert because of some 1914 Interbase API limitations. 1915 </font></p><p><font>The parameters are $table which is the table name, the $arrFields which is an 1916 associative array where the keys are the field names, and $keyCols is the name 1917 of the primary key, or an array of field names if it is a compound key. If 1918 $autoQuote is set to true, then Replace() will quote all values that are non-numeric; 1919 auto-quoting will not quote nulls. Note that auto-quoting will not work if 1920 you use SQL functions or operators. 1921 </font></p><p><font>Examples: 1922 </font></p><pre><font># single field primary key<br>$ret = $db->Replace('atable', <br> array('id'=>1000,'firstname'=>'Harun','lastname'=>'Al-Rashid'),<br> 'id',$autoquote = true); <br># generates UPDATE atable SET firstname='Harun',lastname='Al-Rashid' WHERE id=1000<br># or INSERT INTO atable (id,firstname,lastname) VALUES (1000,'Harun','Al-Rashid')<br><br># compound key<br>$ret = $db->Replace('atable2', <br> array('firstname'=>'Harun','lastname'=>'Al-Rashid', 'age' => 33, 'birthday' => 'null'),<br> array('lastname','firstname'),<br> $autoquote = true);<br><br># no auto-quoting<br>$ret = $db->Replace('atable2', <br> array('firstname'=>"'Harun'",'lastname'=>"'Al-Rashid'", 'age' => 'null'),<br> array('lastname','firstname')); <br></font></pre> 1923 <p><font><b>AutoExecute<a name="autoexecute"></a>($table, $arrFields, $mode, $where=false, $forceUpdate=true,$magicq=false)</b></font></p> 1924 <p>Since ADOdb 4.56, you can automatically generate and execute INSERTs and UPDATEs on a given table with this 1925 function, which is a wrapper for GetInsertSQL() and GetUpdateSQL(). 1926 <p>AutoExecute() inserts or updates $table given an array of $arrFields, where the keys are the field names and the array values are the 1927 field values to store. Note that there is some overhead because the table is first queried to extract key information 1928 before the SQL is generated. We generate an INSERT or UPDATE based on $mode (see below). 1929 <p> 1930 Legal values for $mode are 1931 <ul> 1932 <li>'INSERT' or 1 or DB_AUTOQUERY_INSERT 1933 <li>'UPDATE' or 2 or DB_AUTOQUERY_UPDATE 1934 </ul> 1935 <p>You have to define the constants DB_AUTOQUERY_UPDATE and DB_AUTOQUERY_INSERT yourself or include adodb-pear.inc.php. 1936 <p>The $where clause is required if $mode == 'UPDATE'. If $forceUpdate=false then we will query the 1937 database first and check if the field value returned by the query matches the current field value; only if they differ do we update that field. 1938 <p>Returns true on success, false on error. 1939 <p>An example of its use is: 1940 <pre> 1941 $record["firstName"] = "Carol"; 1942 $record["lasTname"] = "Smith"; 1943 $conn->AutoExecute($table,$record,'INSERT'); 1944 # executes <i>"INSERT INTO $table (firstName,lasTname) values ('Carol',Smith')"</i>; 1945 1946 $record["firstName"] = "Carol"; 1947 $record["lasTname"] = "Jones"; 1948 $conn->AutoExecute($table,$record,'UPDATE', "lastname like 'Sm%'"); 1949 # executes <i>"UPDATE $table SET firstName='Carol',lasTname='Jones' WHERE lastname like 'Sm%'"</i>; 1950 </pre> 1951 <p>Note: One of the strengths of ADOdb's AutoExecute() is that only valid field names for $table are updated. If $arrFields 1952 contains keys that are invalid field names for $table, they are ignored. There is some overhead in doing this as we have to 1953 query the database to get the field names, but given that you are not directly coding the SQL yourself, you probably aren't interested in 1954 speed at all, but convenience. 1955 <p>Since 4.62, the table name to be used can be overridden by setting $rs->tableName before AutoExecute(), GetInsertSQL() or GetUpdateSQL() is called. 1956 <p>Since 4.94, setting the global variable $ADODB_QUOTE_FIELDNAMES to true will force field names to be auto-quoted in AutoExecute(), GetInsertSQL() and GetUpdateSQL(). </p> 1957 <p><font><b>GetUpdateSQL<a name="getupdatesql"></a>(&$rs, $arrFields, $forceUpdate=false,$magicq=false, $force=null)</b></font></p> 1958 <p><font>Generate SQL to update a table given a recordset $rs, and the modified fields 1959 of the array $arrFields (which must be an associative array holding the column 1960 names and the new values) are compared with the current recordset. If $forceUpdate 1961 is true, then we also generate the SQL even if $arrFields is identical to 1962 $rs->fields. Requires the recordset to be associative. $magicq is used 1963 to indicate whether magic quotes are enabled (see qstr()). The field names in the array 1964 are case-insensitive.</font></p> 1965 <font> </font><p><font>Since 4.52, we allow you to pass the $force type parameter, and this overrides the <a href="#ADODB_FORCE_TYPE">$ADODB_FORCE_TYPE</a> 1966 global variable. 1967 <p>Since 4.62, the table name to be used can be overridden by setting $rs->tableName before AutoExecute(), GetInsertSQL() or GetUpdateSQL() is called. 1968 </p></font><p><font><b>GetInsertSQL<a name="getinsertsql"></a>(&$rs, $arrFields,$magicq=false,$force_type=false)</b></font></p> 1969 <p><font>Generate SQL to insert into a table given a recordset $rs. Requires the query 1970 to be associative. $magicq is used to indicate whether magic quotes are enabled 1971 (for qstr()). The field names in the array are case-insensitive.</font></p> 1972 <p> 1973 <font> Since 2.42, you can pass a table name instead of a recordset into 1974 GetInsertSQL (in $rs), and it will generate an insert statement for that table. 1975 </font></p><p><font>Since 4.52, we allow you to pass the $force_type parameter, and this overrides the <a href="#ADODB_FORCE_TYPE">$ADODB_FORCE_TYPE</a> 1976 global variable. 1977 <p>Since 4.62, the table name to be used can be overridden by setting $rs->tableName before AutoExecute(), GetInsertSQL() or GetUpdateSQL() is called. 1978 </p></font><p><font><b>PageExecute<a name="pageexecute"></a>($sql, $nrows, $page, $inputarr=false)</b> 1979 </font></p><p><font>Used for pagination of recordset. $page is 1-based. See <a href="#ex8">Example 1980 8</a>.</font></p> 1981 1982 <p><font><b>CachePageExecute<a name="cachepageexecute"></a>($secs2cache, 1983 $sql, $nrows, $page, $inputarr=false)</b> </font></p> 1984 <p><font>Used for pagination of recordset. $page is 1-based. See 1985 <a href="#ex8">Example 8</a>. Caching version of PageExecute.</font></p> 1986 <font> 1987 </font><p></p> 1988 <p><font><b>Close<a name="close"></a>( )</b></font></p> 1989 <p><font>Close the database connection. PHP4 proudly states that we no longer have to 1990 clean up at the end of the connection because the reference counting mechanism 1991 of PHP4 will automatically clean up for us.</font></p> 1992 <font> </font><p><font><b>StartTrans<a name="starttrans"></a>( )</b></font></p> 1993 <font> </font><p><font>Start a monitored transaction. As SQL statements are executed, ADOdb will monitor 1994 for SQL errors, and if any are detected, when CompleteTrans() is called, we auto-rollback. 1995 </font></p><p> 1996 <font> </font></p><p><font> To understand why StartTrans() is superior to BeginTrans(), 1997 let us examine a few ways of using BeginTrans(). 1998 The following is the wrong way to use transactions: 1999 </font></p><pre><font>$DB->BeginTrans();<br>$DB->Execute("update table1 set val=$val1 where id=$id");<br>$DB->Execute("update table2 set val=$val2 where id=$id");<br>$DB->CommitTrans();<br></font></pre> 2000 <p><font>because you perform no error checking. It is possible to update table1 and 2001 for the update on table2 to fail. Here is a better way: 2002 </font></p><pre><font>$DB->BeginTrans();<br>$ok = $DB->Execute("update table1 set val=$val1 where id=$id");<br>if ($ok) $ok = $DB->Execute("update table2 set val=$val2 where id=$id");<br>if ($ok) $DB->CommitTrans();<br>else $DB->RollbackTrans();<br></font></pre> 2003 <p><font>Another way is (since ADOdb 2.0): 2004 </font></p><pre><font>$DB->BeginTrans();<br>$ok = $DB->Execute("update table1 set val=$val1 where id=$id");<br>if ($ok) $ok = $DB->Execute("update table2 set val=$val2 where id=$id");<br>$DB->CommitTrans($ok);<br></font></pre> 2005 <p><font> Now it is a headache monitoring $ok all over the place. StartTrans() is an 2006 improvement because it monitors all SQL errors for you. This is particularly 2007 useful if you are calling black-box functions in which SQL queries might be executed. 2008 Also all BeginTrans, CommitTrans and RollbackTrans calls inside a StartTrans block 2009 will be disabled, so even if the black box function does a commit, it will be ignored. 2010 </font></p><pre><font>$DB->StartTrans();<br>CallBlackBox();<br>$DB->Execute("update table1 set val=$val1 where id=$id");<br>$DB->Execute("update table2 set val=$val2 where id=$id");<br>$DB->CompleteTrans();<br></font></pre> 2011 <p><font>Note that a StartTrans blocks are nestable, the inner blocks are ignored. 2012 </font></p><p><font><b>CompleteTrans<a name="completetrans"></a>($autoComplete=true)</b></font></p> 2013 <font> </font><p><font>Complete a transaction called with StartTrans(). This function monitors 2014 for SQL errors, and will commit if no errors have occured, otherwise it will rollback. 2015 Returns true on commit, false on rollback. If the parameter $autoComplete is true 2016 monitor sql errors and commit and rollback as appropriate. Set $autoComplete to false 2017 to force rollback even if no SQL error detected. 2018 </font></p><p><font><b>FailTrans<a name="failtrans"></a>( )</b></font></p> 2019 <font> </font><p><font>Fail a transaction started with StartTrans(). The rollback will only occur when 2020 CompleteTrans() is called. 2021 </font></p><p><font><b>HasFailedTrans<a name="hasfailedtrans"></a>( )</b></font></p> 2022 <font> </font><p><font>Check whether smart transaction has failed, 2023 eg. returns true if there was an error in SQL execution or FailTrans() was called. 2024 If not within smart transaction, returns false. 2025 </font></p><p><font><b>BeginTrans<a name="begintrans"></a>( )</b></font></p> 2026 <p><font>Begin a transaction. Turns off autoCommit. Returns true if successful. Some 2027 databases will always return false if transaction support is not available. 2028 Any open transactions will be rolled back when the connection is closed. Among the 2029 databases that support transactions are Oracle, PostgreSQL, Interbase, MSSQL, certain 2030 versions of MySQL, DB2, Informix, Sybase, etc.</font></p> 2031 <font> </font><p><font>Note that <a href="#starttrans">StartTrans()</a> and CompleteTrans() is a superior method of 2032 handling transactions, available since ADOdb 3.40. For a explanation, see the <a href="#starttrans">StartTrans()</a> documentation. 2033 2034 </font></p><p><font>You can also use the ADOdb <a href="#errorhandling">error handler</a> to die 2035 and rollback your transactions for you transparently. Some buggy database extensions 2036 are known to commit all outstanding tranasactions, so you might want to explicitly 2037 do a $DB->RollbackTrans() in your error handler for safety. 2038 </font></p><h4><font>Detecting Transactions</font></h4> 2039 <font> </font><p><font>Since ADOdb 2.50, you are able to detect when you are inside a transaction. Check 2040 that $connection->transCnt > 0. This variable is incremented whenever BeginTrans() is called, 2041 and decremented whenever RollbackTrans() or CommitTrans() is called. 2042 </font></p><p><font><b>CommitTrans<a name="committrans"></a>($ok=true)</b></font></p> 2043 <p><font>End a transaction successfully. Returns true if successful. If the database 2044 does not support transactions, will return true also as data is always committed. 2045 </font></p> 2046 <p><font>If you pass the parameter $ok=false, the data is rolled back. See example in 2047 BeginTrans().</font></p> 2048 <p><font><b>RollbackTrans<a name="rollbacktrans"></a>( )</b></font></p> 2049 <p><font>End a transaction, rollback all changes. Returns true if successful. If the 2050 database does not support transactions, will return false as data is never rollbacked. 2051 </font></p> 2052 2053 <p><font><b>SetTransactionMode<a name="SetTransactionMode"></a>($mode )</b></font></p> 2054 <p>SetTransactionMode allows you to pass in the transaction mode to use for all subsequent transactions. 2055 Note: if you have persistent connections and using mssql or mysql, you might have to explicitly reset your transaction mode at the beginning of each page request. 2056 This is only supported in postgresql, mssql, mysql with InnoDB and oci8 currently. For example: 2057 <pre> 2058 $db->SetTransactionMode("SERIALIZABLE"); 2059 $db->BeginTrans(); 2060 $db->Execute(...); $db->Execute(...); 2061 $db->CommiTrans(); 2062 2063 $db->SetTransactionMode(""); // restore to default 2064 $db->StartTrans(); 2065 $db->Execute(...); $db->Execute(...); 2066 $db->CompleteTrans(); 2067 </pre> 2068 2069 <p>Supported values to pass in: 2070 <ul> 2071 <li>READ UNCOMMITTED (allows dirty reads, but fastest) 2072 <li>READ COMMITTED (default postgres, mssql and oci8) 2073 <li>REPEATABLE READ (default mysql) 2074 <li>SERIALIZABLE (slowest and most restrictive) 2075 </ul> 2076 <p>You can also pass in database specific values such as 'SNAPSHOT' for mssql or 'READ ONLY' for oci8/postgres. 2077 <p>See transaction levels for <a href=http://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.html>PostgreSQL</a>, 2078 <a href=http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm>Oracle</a>, 2079 <a href=http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html>MySQL</a>, and 2080 <a href=http://msdn2.microsoft.com/en-US/ms173763.aspx>MS SQL Server</a>. 2081 <p><font><b>GetAssoc<a name="getassoc1"></a>($sql,$inputarr=false,$force_array=false,$first2cols=false)</b></font></p> 2082 <p><font>Returns an associative array for the given query $sql with optional bind parameters 2083 in $inputarr. If the number of columns returned is greater to two, a 2-dimensional 2084 array is returned, with the first column of the recordset becomes the keys 2085 to the rest of the rows. If the columns is equal to two, a 1-dimensional array 2086 is created, where the the keys directly map to the values (unless $force_array 2087 is set to true, when an array is created for each value). 2088 </font></p><p><font> Examples:<a name="getassocex"></a></font></p> 2089 2090 <p><font>We have the following data in a recordset:</font></p> 2091 <p><font>row1: Apple, Fruit, Edible<br> 2092 row2: Cactus, Plant, Inedible<br> 2093 row3: Rose, Flower, Edible</font></p> 2094 <p><font>GetAssoc will generate the following 2-dimensional associative 2095 array:</font></p> 2096 <p><font>Apple => array[Fruit, Edible]<br> 2097 Cactus => array[Plant, Inedible]<br> 2098 Rose => array[Flower,Edible]</font></p> 2099 <p><font>If the dataset is:</font></p> 2100 <p><font>row1: Apple, Fruit<br> 2101 row2: Cactus, Plant<br> 2102 row3: Rose, Flower </font></p> 2103 <p><font>GetAssoc will generate the following 1-dimensional associative 2104 array (with $force_array==false):</font></p> 2105 <p><font>Apple => Fruit</font><br> 2106 Cactus=>Plant<br> 2107 Rose=>Flower </p> 2108 <p><font>The function returns:</font></p> 2109 <p><font>The associative array, or false if an error occurs.</font></p> 2110 <font> 2111 <p><b>CacheGetAssoc<a name="cachegetassoc"></a>([$secs2cache,] $sql,$inputarr=false,$force_array=false,$first2cols=false)</b></p> 2112 </font> 2113 <p><font>Caching version of <a href="#getassoc1">GetAssoc</a> function above. 2114 </font></p><p><font><b>GetOne<a name="getone"></a>($sql,$inputarr=false)</b></font></p> 2115 <p><font>Executes the SQL and returns the first field of the first row. The recordset 2116 and remaining rows are discarded for you automatically. If an error occur, false 2117 is returned; use ErrorNo() or ErrorMsg() to get the error details. 2118 Since 4.96, we return null if no records were found.</font></p> 2119 <p><font><b>GetRow<a name="getrow"></a>($sql,$inputarr=false)</b></font></p> 2120 <p><font>Executes the SQL and returns the first row as an array. The recordset and remaining 2121 rows are discarded for you automatically. If an error occurs, false is returned.</font></p> 2122 <p><font><b>GetAll<a name="getall"></a>($sql,$inputarr=false)</b></font></p> 2123 2124 <p>Executes the SQL and returns the all the rows as a 2-dimensional 2125 array. The recordset is discarded for you automatically. If an error occurs, 2126 false is returned. <i>GetArray</i> is a synonym for <i>GetAll</i>.</p> 2127 <p><b>GetCol<a name="getcol"></a>($sql,$inputarr=false,$trim=false)</b></p> 2128 2129 <p><font>Executes the SQL and returns all elements of the first column as a 2130 1-dimensional array. The recordset is discarded for you automatically. If an error occurs, 2131 false is returned.</font></p> 2132 <p><font><b>CacheGetOne<a name="cachegetone"></a>([$secs2cache,] 2133 $sql,$inputarr=false), CacheGetRow<a name="cachegetrow"></a>([$secs2cache,] $sql,$inputarr=false), CacheGetAll<a name="cachegetall"></a>([$secs2cache,] 2134 $sql,$inputarr=false), CacheGetCol<a name="cachegetcol"></a>([$secs2cache,] 2135 $sql,$inputarr=false,$trim=false)</b></font></p> 2136 <font> 2137 </font><p><font>Similar to above Get* functions, except that the recordset is serialized and 2138 cached in the $ADODB_CACHE_DIR directory for $secs2cache seconds. Good for speeding 2139 up queries on rarely changing data. Note that the $secs2cache parameter is optional. 2140 If omitted, we use the value in $connection->cacheSecs (default is 3600 seconds, 2141 or 1 hour).</font></p> 2142 <p><font><b>Prepare<a name="prepare"></a>($sql )</b></font></p> 2143 2144 <p><font>Prepares (compiles) an SQL query for repeated execution. Bind parameters 2145 are denoted by ?, except for the oci8 driver, which uses the traditional Oracle :varname 2146 convention. 2147 </font></p> 2148 <p><font>Returns an array containing the original sql statement 2149 in the first array element; the remaining elements of the array are driver dependent. 2150 If there is an error, or we are emulating Prepare( ), we return the original 2151 $sql string. This is because all error-handling has been centralized in Execute( 2152 ).</font></p> 2153 <p><font>Prepare( ) cannot be used with functions that use SQL 2154 query rewriting techniques, e.g. PageExecute( ) and SelectLimit( ).</font></p> 2155 <p>Example:</p> 2156 <pre><font>$stmt = $DB->Prepare('insert into table (col1,col2) values (?,?)');<br>for ($i=0; $i < $max; $i++)<br></font> $DB-><font>Execute($stmt,array((string) rand(), $i));<br></font></pre> 2157 <font> 2158 </font><p><font>Also see InParameter(), OutParameter() and PrepareSP() below. Only supported internally by interbase, 2159 oci8 and selected ODBC-based drivers, otherwise it is emulated. There is no 2160 performance advantage to using Prepare() with emulation. 2161 </font></p><p><font> Important: Due to limitations or bugs in PHP, if you are getting errors when 2162 you using prepared queries, try setting $ADODB_COUNTRECS = false before preparing. 2163 This behaviour has been observed with ODBC. 2164 </font></p><p><font><b>IfNull<a name="ifnull"></a>($field, $nullReplacementValue)</b></font></p> 2165 <p><font>Portable IFNULL function (NVL in Oracle). Returns a string that represents 2166 the function that checks whether a $field is null for the given database, and 2167 if null, change the value returned to $nullReplacementValue. Eg.</font></p> 2168 <pre><font>$sql = <font color="#993300">'SELECT '</font>.$db->IfNull('name', <font color="#993300">"'- unknown -'"</font>).<font color="#993300"> ' FROM table'</font>;</font></pre> 2169 2170 <p><font><b>length<a name="length"></a></b></font></p> 2171 <p><font>This is not a function, but a property. Some databases have "length" and others "len" 2172 as the function to measure the length of a string. To use this property: 2173 </font></p><pre><font> $sql = <font color="#993300">"SELECT "</font>.$db->length.<font color="#993300">"(field) from table"</font>;<br> $rs = $db->Execute($sql);<br></font></pre> 2174 2175 <p><font><b>random<a name="random"></a></b></font></p> 2176 <p><font>This is not a function, but a property. This is a string that holds the sql to 2177 generate a random number between 0.0 and 1.0 inclusive. 2178 2179 </font></p><p><font><b>substr<a name="substr"></a></b></font></p> 2180 <p><font>This is not a function, but a property. Some databases have "substr" and others "substring" 2181 as the function to retrieve a sub-string. To use this property: 2182 </font></p><pre><font> $sql = <font color="#993300">"SELECT "</font>.$db->substr.<font color="#993300">"(field, $offset, $length) from table"</font>;<br> $rs = $db->Execute($sql);<br></font></pre> 2183 <p><font>For all databases, the 1st parameter of <i>substr</i> is the field, the 2nd is the 2184 offset (1-based) to the beginning of the sub-string, and the 3rd is the length of the sub-string. 2185 2186 2187 </font></p><p><font><b>Param<a name="param"></a>($name)</b></font></p> 2188 <p><font>Generates a bind placeholder portably. For most databases, the bind placeholder 2189 is "?". However some databases use named bind parameters such as Oracle, eg 2190 ":somevar". This allows us to portably define an SQL statement with bind parameters: 2191 </font></p><pre><font>$sql = <font color="#993300">'insert into table (col1,col2) values ('</font>.$DB->Param('a').<font color="#993300">','</font>.$DB->Param('b').<font color="#993300">')'</font>;<br><font color="#006600"># generates 'insert into table (col1,col2) values (?,?)'<br># or 'insert into table (col1,col2) values (:a,:b)</font>'<br>$stmt = $DB->Prepare($sql);<br>$stmt = $DB->Execute($stmt,array('one','two'));<br></font></pre> 2192 <font> </font> 2193 <p></p> 2194 <p><font><b>PrepareSP</b><b><a name="preparesp"></a></b><b>($sql, 2195 $cursor=false )</b></font></p> 2196 <p><font>When calling stored procedures in mssql and oci8 (oracle), 2197 and you might want to directly bind to parameters that return values, or 2198 for special LOB handling. PrepareSP() allows you to do so. </font></p> 2199 <p><font>Returns the same array or $sql string as Prepare( ) 2200 above. If you do not need to bind to return values, you should use Prepare( 2201 ) instead.</font></p> 2202 <p><font>The 2nd parameter, $cursor is not used except with oci8. 2203 Setting it to true will force OCINewCursor to be called; this is to support 2204 output REF CURSORs. </font></p> 2205 <p><font>For examples of usage of PrepareSP( ), see InParameter( 2206 ) below. </font></p> 2207 <p><font>Note: in the mssql driver, preparing stored procedures 2208 requires a special function call, mssql_init( ), which is called by this 2209 function. PrepareSP( ) is available in all other drivers, and is emulated 2210 by calling Prepare( ). </font></p> 2211 <p><font><b> InParameter<a name="inparameter"></a>($stmt, $var, 2212 $name, $maxLen = 4000, $type = false )</b></font></p> 2213 <font>Binds a PHP variable as input to a stored procedure variable. 2214 The parameter <i>$stmt</i> is the value returned by PrepareSP(), <i>$var</i> is 2215 the PHP variable you want to bind, $name is the name of the stored procedure 2216 variable. Optional is <i>$maxLen</i>, the maximum length of the data to bind, 2217 and $type which is database dependant. Consult <a href="http://php.net/mssql_bind">mssql_bind</a> and <a href="http://php.net/ocibindbyname">ocibindbyname</a> docs 2218 at php.net for more info on legal values for $type. </font> 2219 <p> 2220 <font>InParameter() is a wrapper function that calls Parameter() 2221 with $isOutput=false. The advantage of this function is that it is self-documenting, 2222 because the $isOutput parameter is no longer needed. Only for mssql and oci8 2223 currently. </font></p> 2224 <p><font>Here is an example using oci8: </font></p> 2225 <pre><font><font color="green"># For oracle, Prepare and PrepareSP are identical</font> 2226 $stmt = $db->PrepareSP( 2227 <font color="#993300">"declare RETVAL integer; <br> begin<br> :RETVAL := </font><font color="#993300">SP_RUNSOMETHING</font><font color="#993300">(:myid,:group);<br> end;"</font>);<br>$db->InParameter($stmt,$id,'myid');<br>$db->InParameter($stmt,$group,'group',64);<br>$db->OutParameter($stmt,$ret,'RETVAL');<br>$db->Execute($stmt);<br></font></pre> 2228 <p><font> The same example using mssql:</font></p> 2229 <font> 2230 </font><pre><font><font color="green"># @RETVAL = SP_RUNSOMETHING @myid,@group</font> 2231 $stmt = $db->PrepareSP(<font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font>); <br><font color="green"># note that the parameter name does not have @ in front!</font> 2232 $db->InParameter($stmt,$id,'myid'); 2233 $db->InParameter($stmt,$group,'group',64); 2234 <font color="green"># return value in mssql - RETVAL is hard-coded name</font> <br>$db->OutParameter($stmt,$ret,'RETVAL');<br>$db->Execute($stmt); </font></pre> 2235 2236 <p><font>Note that the only difference between the oci8 and mssql implementations is $sql.</font></p> 2237 <p> 2238 <font> If $type parameter is set to false, in mssql, $type will be dynamicly determined 2239 based on the type of the PHP variable passed <font face="Courier New, Courier, mono">(string 2240 => SQLCHAR, boolean =>SQLINT1, integer =>SQLINT4 or float/double=>SQLFLT8)</font>. 2241 </font></p><p><font> 2242 In oci8, $type can be set to OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File), 2243 OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID). To 2244 pass in a null, use<font face="Courier New, Courier, mono"> $db->Parameter($stmt, 2245 $null=null, 'param')</font>. 2246 </font></p><p><font><b> OutParameter<a name="outparameter"></a>($stmt, $var, $name, 2247 $maxLen = 4000, $type = false )</b></font></p> 2248 <font> Binds a PHP variable as output from a stored procedure variable. The parameter <i>$stmt</i> 2249 is the value returned by PrepareSP(), <i>$var</i> is the PHP variable you want to bind, <i>$name</i> 2250 is the name of the stored procedure variable. Optional is <i>$maxLen</i>, the maximum length of the 2251 data to bind, and <i>$type</i> which is database dependant. 2252 </font><p> 2253 <font> OutParameter() is a wrapper function that calls Parameter() with $isOutput=true. 2254 The advantage of this function is that it is self-documenting, because 2255 the $isOutput parameter is no longer needed. Only for mssql 2256 and oci8 currently. 2257 </font></p><p> 2258 <font>For an example, see <a href="#inparameter">InParameter</a>. 2259 2260 </font></p><p><font><b> Parameter<a name="parameter"></a>($stmt, $var, $name, $isOutput=false, 2261 $maxLen = 4000, $type = false )</b></font></p> 2262 <p><font>Note: This function is deprecated, because of the new InParameter() and OutParameter() functions. 2263 These are superior because they are self-documenting, unlike Parameter(). 2264 </font></p><p><font>Adds a bind parameter suitable for return values or special data handling (eg. 2265 LOBs) after a statement has been prepared using PrepareSP(). Only for mssql 2266 and oci8 currently. The parameters are:<br> 2267 <br> 2268 $<i><b>stmt</b></i> Statement returned by Prepare() or PrepareSP().<br> 2269 $<i><b>var</b></i> PHP variable to bind to. Make sure you pre-initialize it!<br> 2270 $<i><b>name</b></i> Name of stored procedure variable name to bind to.<br> 2271 [$<i><b>isOutput</b></i>] Indicates direction of parameter 0/false=IN 1=OUT 2272 2= IN/OUT. This is ignored in oci8 as this driver auto-detects the direction.<br> 2273 [$<b>maxLen</b>] Maximum length of the parameter variable.<br> 2274 [$<b>type</b>] Consult <a href="http://php.net/mssql_bind">mssql_bind</a> and 2275 <a href="http://php.net/ocibindbyname">ocibindbyname</a> docs at php.net for 2276 more info on legal values for type.</font></p> 2277 <p><font>Lastly, in oci8, bind parameters can be reused without calling PrepareSP( ) 2278 or Parameters again. This is not possible with mssql. An oci8 example:</font></p> 2279 <pre><font>$id = 0; $i = 0;<br>$stmt = $db->PrepareSP( <font color="#993300">"update table set val=:i where id=:id"</font>);<br>$db->Parameter($stmt,$id,'id');<br>$db->Parameter($stmt,$i, 'i');<br>for ($cnt=0; $cnt < 1000; $cnt++) {<br> $id = $cnt; <br> $i = $cnt * $cnt; <font color="green"># works with oci8!</font> 2280 $db->Execute($stmt); <br>}</font></pre> 2281 <p><font><b>Bind<a name="bind"></a>($stmt, $var, $size=4001, $type=false, $name=false)</b></font></p> 2282 2283 <p><font>This is a low-level function supported only by the oci8 2284 driver. <b>Avoid using</b> unless you only want to support Oracle. The Parameter( 2285 ) function is the recommended way to go with bind variables.</font></p> 2286 <p><font>Bind( ) allows you to use bind variables in your sql 2287 statement. This binds a PHP variable to a name defined in an Oracle sql statement 2288 that was previously prepared using Prepare(). Oracle named variables begin with 2289 a colon, and ADOdb requires the named variables be called :0, :1, :2, :3, etc. 2290 The first invocation of Bind() will match :0, the second invocation will match 2291 :1, etc. Binding can provide 100% speedups for insert, select and update statements. 2292 </font></p> 2293 <p>The other variables, $size sets the buffer size for data storage, $type is 2294 the optional descriptor type OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File), 2295 OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID). 2296 Lastly, instead of using the default :0, :1, etc names, you can define your 2297 own bind-name using $name. 2298 </p><p><font>The following example shows 3 bind variables being used: 2299 p1, p2 and p3. These variables are bound to :0, :1 and :2.</font></p> 2300 <pre>$stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:0, :1, :2)");<br>$DB->Bind($stmt, $p1);<br>$DB->Bind($stmt, $p2);<br>$DB->Bind($stmt, $p3);<br>for ($i = 0; $i < $max; $i++) { <br> $p1 = ?; $p2 = ?; $p3 = ?;<br> $DB->Execute($stmt);<br>}</pre> 2301 <p>You can also use named variables:</p> 2302 <pre>$stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:name0, :name1, :name2)");<br>$DB->Bind($stmt, $p1, "name0");<br>$DB->Bind($stmt, $p2, "name1");<br>$DB->Bind($stmt, $p3, "name2");<br>for ($i = 0; $i < $max; $i++) { <br> $p1 = ?; $p2 = ?; $p3 = ?;<br> $DB->Execute($stmt);<br>}</pre> 2303 <p><b>LogSQL($enable=true)<a name="logsql"></a></b></p> 2304 Call this method to install a SQL logging and timing function (using fnExecute). 2305 Then all SQL statements are logged into an adodb_logsql table in a database. If 2306 the adodb_logsql table does not exist, ADOdb will create the table if you have 2307 the appropriate permissions. Returns the previous logging value (true for enabled, 2308 false for disabled). Here are samples of the DDL for selected databases: 2309 <p> 2310 </p><pre> <b>mysql:</b> 2311 CREATE TABLE adodb_logsql ( 2312 created datetime NOT NULL, 2313 sql0 varchar(250) NOT NULL, 2314 sql1 text NOT NULL, 2315 params text NOT NULL, 2316 tracer text NOT NULL, 2317 timer decimal(16,6) NOT NULL 2318 ) 2319 2320 <b>postgres:</b> 2321 CREATE TABLE adodb_logsql ( 2322 created timestamp NOT NULL, 2323 sql0 varchar(250) NOT NULL, 2324 sql1 text NOT NULL, 2325 params text NOT NULL, 2326 tracer text NOT NULL, 2327 timer decimal(16,6) NOT NULL 2328 ) 2329 2330 <b>mssql:</b> 2331 CREATE TABLE adodb_logsql ( 2332 created datetime NOT NULL, 2333 sql0 varchar(250) NOT NULL, 2334 sql1 varchar(4000) NOT NULL, 2335 params varchar(3000) NOT NULL, 2336 tracer varchar(500) NOT NULL, 2337 timer decimal(16,6) NOT NULL 2338 ) 2339 2340 <b>oci8:</b> 2341 CREATE TABLE adodb_logsql ( 2342 created date NOT NULL, 2343 sql0 varchar(250) NOT NULL, 2344 sql1 varchar(4000) NOT NULL, 2345 params varchar(4000), 2346 tracer varchar(4000), 2347 timer decimal(16,6) NOT NULL 2348 ) 2349 </pre> 2350 Usage: 2351 <pre> $conn->LogSQL(); // turn on logging<br> :<br> $conn->Execute(...);<br> :<br> $conn->LogSQL(false); // turn off logging<br> <br> # output summary of SQL logging results<br> $perf = NewPerfMonitor($conn);<br> echo $perf->SuspiciousSQL();<br> echo $perf->ExpensiveSQL();<br></pre> 2352 <p>One limitation of logging is that rollback also prevents SQL from being logged. 2353 </p><p> 2354 If you prefer to use another name for the table used to store the SQL, you can override it by calling 2355 adodb_perf::table($tablename), where $tablename is the new table name (you will still need to manually 2356 create the table yourself). An example: 2357 </p><pre> include ('adodb.inc.php');<br> include('adodb-perf.inc.php');<br> adodb_perf::table('my_logsql_table');<br></pre> 2358 Also see <a href="docs-perf.htm">Performance Monitor</a>. 2359 <p><font><b>fnExecute and fnCacheExecute properties<a name="fnexecute" id="fnexecute"></a></b></font></p> 2360 <p>These two properties allow you to define bottleneck functions for all sql statements 2361 processed by ADOdb. This allows you to perform statistical analysis and query-rewriting 2362 of your sql. 2363 </p><p><b>Examples of fnExecute</b></p> 2364 <p>Here is an example of using fnExecute, to count all cached queries and non-cached 2365 queries, you can do this:</p> 2366 <pre><font color="#006600"># $db is the connection object</font> 2367 function &CountExecs($db, $sql, $inputarray) 2368 { 2369 global $EXECS; 2370 2371 if (!is_array(inputarray)) $EXECS++; 2372 <font color="#006600"># handle 2-dimensional input arrays</font> 2373 else if (is_array(reset($inputarray))) $EXECS += sizeof($inputarray); 2374 else $EXECS++; 2375 2376 <font color="#006600"># in PHP4.4 and PHP5, we need to return a value by reference</font> 2377 $null = null; 2378 return $null; 2379 } 2380 2381 <font color="#006600"># $db is the connection object</font> 2382 function CountCachedExecs($db, $secs2cache, $sql, $inputarray) 2383 {<br>global $CACHED; $CACHED++;<br>}<br><br>$db = NewADOConnection('mysql');<br>$db->Connect(...);<br>$db-><strong>fnExecute</strong> = 'CountExecs';<br>$db-><strong>fnCacheExecute</strong> = 'CountCachedExecs';<br> :<br> :<br><font color="#006600"># After many sql statements:</font>`<br>printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED);<br></pre> 2384 <p>The fnExecute function is called before the sql is parsed and executed, so 2385 you can perform a query rewrite. If you are passing in a prepared statement, 2386 then $sql is an array (see <a href="#prepare">Prepare</a>). The fnCacheExecute 2387 function is only called if the recordset returned was cached.<font> 2388 The function parameters match the Execute and CacheExecute functions respectively, 2389 except that $this (the connection object) is passed as the first parameter.</font></p> 2390 <p>Since ADOdb 3.91, the behaviour of fnExecute varies depending on whether the 2391 defined function returns a value. If it does not return a value, then the $sql 2392 is executed as before. This is useful for query rewriting or counting sql queries. 2393 </p><p> On the other hand, you might want to replace the Execute function with one 2394 of your own design. If this is the case, then have your function return a value. 2395 If a value is returned, that value is returned immediately, without any further 2396 processing. This is used internally by ADOdb to implement LogSQL() functionality. 2397 </p> 2398 <p> 2399 </p><hr /> 2400 <h3><font>ADOConnection Utility Functions</font></h3> 2401 <p><font><b>BlankRecordSet<a name="blankrecordset"></a>([$queryid])</b></font></p> 2402 <p><font>No longer available - removed since 1.99.</font></p> 2403 <p><font><b>Concat<a name="concat"></a>($s1,$s2,....)</b></font></p> 2404 <p><font>Generates the sql string used to concatenate $s1, $s2, etc together. Uses the 2405 string in the concat_operator field to generate the concatenation. Override 2406 this function if a concatenation operator is not used, eg. MySQL.</font></p> 2407 <p><font>Returns the concatenated string.</font></p> 2408 <p><font><b>DBDate<a name="dbdate"></a>($date)</b></font></p> 2409 <p><font>Format the $<b>date</b> in the format the database accepts - the return string is also quoted. This is used 2410 when you are sending dates to the database (eg INSERT, UPDATE or where clause of SELECT statement). 2411 The $<b>date</b> parameter can be a Unix integer timestamp or an ISO format 2412 Y-m-d. Uses the fmtDate field, which holds the format to use. If null or false 2413 or '' is passed in, it will be converted to an SQL null.</font></p> 2414 <p><font>Returns the date as a quoted string.</font></p> 2415 <pre> 2416 $sql = "select * from atable where created > ".$db->DBDate("$year-$month-$day"); 2417 $db->Execute($sql); 2418 </pre> 2419 <p>Note to retrieve a date column in a specific format, use <a href="#sqldate">SQLDate</a>. </p> 2420 <p><font><b>BindDate<a name="binddate"></a>($date)</b></font></p> 2421 <p><font>Format the $<b>date</b> in the bind format the database accepts. Normally 2422 this means that the date string is not quoted, unlike DBDate, which quotes the string. 2423 <pre> 2424 $sql = "select * from atable where created > ".$db->Param('0'); 2425 // or 2426 $sql = "select * from atable where created > ?"; 2427 $db->Execute($sql,array($db->BindDate("$year-$month-$day")); 2428 </pre> 2429 <p><font><b>DBTimeStamp<a name="dbtimestamp"></a>($ts)</b></font></p> 2430 <p><font>Format the timestamp $<b>ts</b> in the format the database accepts; this can 2431 be a Unix integer timestamp or an ISO format Y-m-d H:i:s. Uses the fmtTimeStamp 2432 field, which holds the format to use. If null or false or '' is passed in, it 2433 will be converted to an SQL null.</font></p> 2434 <p><font>Returns the timestamp as a quoted string.</font></p> 2435 <pre> 2436 $sql = "select * from atable where created > ".$db->DBTimeStamp("$year-$month-$day $hr:$min:$secs"); 2437 $db->Execute($sql); 2438 </pre> 2439 <p><font><b>BindTimeStamp<a name="bindtimestamp"></a>($ts)</b></font></p> 2440 <p><font>Format the timestamp $<b>ts</b> in the bind format the database accepts. Normally 2441 this means that the timestamp string is not quoted, unlike DBTimeStamp, which quotes the string. 2442 <pre> 2443 $sql = "select * from atable where created > ".$db->Param('0'); 2444 // or 2445 $sql = "select * from atable where created > ?"; 2446 $db->Execute($sql,array($db->BindTimeStamp("$year-$month-$day $hr:$min:$secs")); 2447 </pre> 2448 <p><font><b>qstr<a name="qstr"></a>($s,[$magic_quotes_enabled</b>=false]<b>)</b></font></p> 2449 <p><font>Quotes a string to be sent to the database. The $<b>magic_quotes_enabled</b> 2450 parameter may look funny, but the idea is if you are quoting a string extracted 2451 from a POST/GET variable, then pass get_magic_quotes_gpc() as the second parameter. 2452 This will ensure that the variable is not quoted twice, once by <i>qstr</i> 2453 and once by the <i>magic_quotes_gpc</i>.</font></p> 2454 <p><font>Eg.<font face="Courier New, Courier, mono"> $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());</font></font></p> 2455 <p><font>Returns the quoted string.</font></p> 2456 <p><font><b>Quote<a name="quote"></a>($s)</b></font></p> 2457 <p><font>Quotes the string $s, escaping the database specific quote character as appropriate. 2458 Formerly checked magic quotes setting, but this was disabled since 3.31 for 2459 compatibility with PEAR DB. 2460 </font></p><p><font><b>Affected_Rows<a name="affected_rows"></a>( )</b></font></p> 2461 <p><font>Returns the number of rows affected by a update or delete statement. Returns 2462 false if function not supported.</font></p> 2463 <p><font>Not supported by interbase/firebird currently. </font></p> 2464 <p><font><b>Insert_ID<a name="inserted_id"></a>( )</b></font></p> 2465 <p><font>Returns the last autonumbering ID inserted. Returns false if function not supported. 2466 </font></p> 2467 <p><font>Only supported by databases that support auto-increment or object id's, such 2468 as PostgreSQL, MySQL and MS SQL Server currently. PostgreSQL returns the OID, which 2469 can change on a database reload.</font></p> 2470 <p><font><b>RowLock<a name="rowlock"></a>($table,$where)</b></font></p> 2471 <p><font>Lock a table row for the duration of a transaction. For example to lock record $id in table1: 2472 </font></p><pre><font> $DB->StartTrans();<br> $DB->RowLock("table1","rowid=$id");<br> $DB->Execute($sql1);<br> $DB->Execute($sql2);<br> $DB->CompleteTrans();<br></font></pre> 2473 <p><font>Supported in db2, interbase, informix, mssql, oci8, postgres, sybase. 2474 </font></p><p><font><b>MetaDatabases<a name="metadatabases"></a>()</b></font></p> 2475 <p><font>Returns a list of databases available on the server as an array. You have to 2476 connect to the server first. Only available for ODBC, MySQL and ADO.</font></p> 2477 <p><font><b>MetaTables<a name="metatables"></a>($ttype = false, $showSchema = false, 2478 $mask=false)</b></font></p> 2479 <p><font>Returns an array of tables and views for the current database as an array. 2480 The array should exclude system catalog tables if possible. To only show tables, 2481 use $db->MetaTables('TABLES'). To show only views, use $db->MetaTables('VIEWS'). 2482 The $showSchema parameter currently works only for DB2, and when set to true, 2483 will add the schema name to the table, eg. "SCHEMA.TABLE". </font></p> 2484 <p><font>You can define a mask for matching. For example, setting $mask = 'TMP%' will 2485 match all tables that begin with 'TMP'. Currently only mssql, oci8, odbc_mssql 2486 and postgres* support $mask. 2487 </font></p><p><font><b>MetaColumns<a name="metacolumns"></a>($table,$notcasesensitive=true)</b></font></p> 2488 <p><font>Returns an array of ADOFieldObject's, one field object for every column of 2489 $table. A field object is a class instance with (name, type, max_length) defined. 2490 Currently Sybase does not recognise date types, and ADO cannot identify 2491 the correct data type (so we default to varchar). 2492 </font></p><p><font> The $notcasesensitive parameter determines whether we uppercase or lowercase the table name to normalize it 2493 (required for some databases). Does not work with MySQL ISAM tables. 2494 </font></p><p><font>For schema support, pass in the $table parameter, "$schema.$tablename". This is only 2495 supported for selected databases. 2496 </font></p><p><font><b>MetaColumnNames<a name="metacolumnames"></a>($table,$numericIndex=false)</b></font></p> 2497 <p><font>Returns an array of column names for $table. Since ADOdb 4.22, this is an associative array, with the 2498 keys in uppercase. Set $numericIndex=true if you want the old behaviour of numeric indexes (since 4.23). 2499 </font></p><p> 2500 <font>e.g. array('FIELD1' => 'Field1', 'FIELD2'=>'Field2') 2501 </font></p><p> 2502 </p><p><font><b>MetaPrimaryKeys<a name="metaprimarykeys"></a>($table, 2503 $owner=false)</b></font> 2504 </p> 2505 <p><font>Returns an array containing column names that are the 2506 primary keys of $table. Supported by mysql, odbc (including db2, odbc_mssql, 2507 etc), mssql, postgres, interbase/firebird, oci8 currently. </font></p> 2508 <p><font>Views (and some tables) have primary keys, but sometimes this information is not available from the 2509 database. You can define a function ADODB_View_PrimaryKeys($databaseType, $database, $view, $owner) that 2510 should return an array containing the fields that make up the primary key. If that function exists, 2511 it will be called when MetaPrimaryKeys() cannot find a primary key for a table or view. 2512 </font></p><pre><font>// In this example: dbtype = 'oci8', $db = 'mydb', $view = 'dataView', $owner = false <br>function ADODB_View_PrimaryKeys($dbtype,$db,$view,$owner)<br>{<br> switch(strtoupper($view)) {<br> case 'DATAVIEW': return array('DATAID');<br> default: return false;<br> }<br>}<br><br>$db = NewADOConnection('oci8');<br>$db->Connect('localhost','root','','mydb'); <br>$db->MetaPrimaryKeys('dataView');<br></font></pre> 2513 <p><font><b>ServerInfo<a name="serverinfo" id="serverinfo"></a>()</b></font> 2514 </p> 2515 <p><font>Returns an array of containing two elements 'description' 2516 and 'version'. The 'description' element contains the string description of 2517 the database. The 'version' naturally holds the version number (which is also 2518 a string).</font></p> 2519 <p><font><b>MetaForeignKeys<a name="metaforeignkeys"></a>($table, $owner=false, $upper=false)</b> 2520 </font></p><p><font>Returns an associate array of foreign keys, or false if not supported. For 2521 example, if table employee has a foreign key where employee.deptkey points to 2522 dept_table.deptid, and employee.posn=posn_table.postionid and employee.poscategory=posn_table.category, 2523 then $conn->MetaForeignKeys('employee') will return 2524 </font></p><pre><font> array(<br> 'dept_table' => array('deptkey=deptid'),<br> 'posn_table' => array('posn=positionid','poscategory=category')<br> )<br></font></pre> 2525 <p><font>The optional schema or owner can be defined in $owner. If $upper is true, then 2526 the table names (array keys) are upper-cased. 2527 </font></p><hr /> 2528 <h2><font>ADORecordSet<a name="adorecordset"></a></font></h2> 2529 <p><font>When an SQL statement successfully is executed by <font face="Courier New, Courier, mono">ADOConnection->Execute($sql),</font>an 2530 ADORecordSet object is returned. This object contains a virtual cursor so we 2531 can move from row to row, functions to obtain information about the columns 2532 and column types, and helper functions to deal with formating the results to 2533 show to the user.</font></p> 2534 <h3><font>ADORecordSet Fields</font></h3> 2535 <p><font><b>fields: </b>Array containing the current row. This is not associative, but 2536 is an indexed array from 0 to columns-1. See also the function <b><a href="#fields">Fields</a></b>, 2537 which behaves like an associative array.</font></p> 2538 <p><font><b>dataProvider</b>: The underlying mechanism used to connect to the database. 2539 Normally set to <b>native</b>, unless using <b>odbc</b> or <b>ado</b>.</font></p> 2540 <p><font><b>blobSize</b>: Maximum size of a char, string or varchar object before it 2541 is treated as a Blob (Blob's should be shown with textarea's). See the <a href="#metatype">MetaType</a> 2542 function.</font></p> 2543 <p><font><b>sql</b>: Holds the sql statement used to generate this record set.</font></p> 2544 <p><font><b>canSeek</b>: Set to true if Move( ) function works.</font></p> 2545 <p><font><b>EOF</b>: True if we have scrolled the cursor past the last record.</font></p> 2546 <h3><font>ADORecordSet Functions</font></h3> 2547 <p><font><b>ADORecordSet( )</b></font></p> 2548 <p><font>Constructer. Normally you never call this function yourself.</font></p> 2549 <p><font><b>GetAssoc<a name="getassoc"></a>([$force_array])</b></font></p> 2550 <p><font>Generates an associative array from the recordset. Note that is this function 2551 is also <a href="#getassoc1">available</a> in the connection object. More details 2552 can be found there.</font></p> 2553 <font> </font> 2554 <p><font><b>GetArray<a name="getarray"></a>([$number_of_rows])</b></font></p> 2555 <p><font>Generate a 2-dimensional array of records from the current 2556 cursor position, indexed from 0 to $number_of_rows - 1. If $number_of_rows 2557 is undefined, till EOF.</font></p> 2558 <p><font><b>GetRows<a name="getrows"></a>([$number_of_rows])</b></font></p> 2559 <font>Generate a 2-dimensional array of records from the current 2560 cursor position. Synonym for GetArray() for compatibility with Microsoft ADO. </font> 2561 <p><font> <b>GetMenu<a name="getmenu"></a>($name, [$default_str=''], 2562 [$blank1stItem=true], [$multiple_select=false], [$size=0], [$moreAttr=''])</b></font></p> 2563 <p><font>Generate a HTML menu (<select><option><option></select>). 2564 The first column of the recordset (fields[0]) will hold the string to display 2565 in the option tags. If the recordset has more than 1 column, the second column 2566 (fields[1]) is the value to send back to the web server.. The menu will be 2567 given the name $<i>name</i>. </font></p> 2568 <p><font> If $<i>default_str</i> is defined, then if $<i>default_str</i> == 2569 fields[0], that field is selected. If $<i>blank1stItem</i> is true, the first 2570 option is empty. You can also set the first option strings by setting $blank1stItem 2571 = "$value:$text".</font></p> 2572 <p><font>$<i>Default_str</i> can be array for a multiple select 2573 listbox.</font></p> 2574 <p><font>To get a listbox, set the $<i>size</i> to a non-zero 2575 value (or pass $default_str as an array). If $<i>multiple_select</i> is true 2576 then a listbox will be generated with $<i>size</i> items (or if $size==0, 2577 then 5 items) visible, and we will return an array to a server. Lastly use 2578 $<i>moreAttr </i> to add additional attributes such as javascript or styles. </font></p> 2579 <p><font>Menu Example 1: <code>GetMenu('menu1','A',true)</code> will 2580 generate a menu: 2581 <select name="menu1"><option> </option><option value="1" selected="selected">A </option><option value="2">B </option><option value="3">C </option></select> 2582 for the data (A,1), (B,2), (C,3). Also see <a href="#ex5">example 5</a>.</font></p> 2583 <p><font>Menu Example 2: For the same data, <code>GetMenu('menu1',array('A','B'),false)</code> will 2584 generate a menu with both A and B selected: <br> 2585 <select name="menu1" multiple="multiple" size="3"><option value="1" selected="selected">A </option><option value="2" selected="selected">B </option><option value="3">C </option></select> 2586 </font></p> 2587 <p><font> <b>GetMenu2<a name="getmenu2"></a>($name, [$default_str=''], 2588 [$blank1stItem=true], [$multiple_select=false], [$size=0], [$moreAttr=''])</b></font></p> 2589 <p><font>This is nearly identical to GetMenu, except that the 2590 $<i>default_str</i> is matched to fields[1] (the option values).</font></p> 2591 <p><font>Menu Example 3: Given the data in menu example 2, <code>GetMenu2('menu1',array('1','2'),false)</code> will 2592 generate a menu with both A and B selected in menu example 2, but this time 2593 the selection is based on the 2nd column, which holds the values to return 2594 to the Web server. </font></p> 2595 <p><font><b>UserDate<a name="userdate"></a>($str, [$fmt])</b></font></p> 2596 <p><font>Converts the date string $<i>str</i> to another format. 2597 The date format is Y-m-d, or Unix timestamp format. The default $<i>fmt</i> is 2598 Y-m-d.</font></p> 2599 <p><font><b>UserTimeStamp<a name="usertimestamp"></a>($str, [$fmt])</b></font></p> 2600 <p><font>Converts the timestamp string $<b>str</b> to another 2601 format. The timestamp format is Y-m-d H:i:s, as in '2002-02-28 23:00:12', 2602 or Unix timestamp format. UserTimeStamp calls UnixTimeStamp to parse $<i>str</i>, 2603 and $<i>fmt</i> defaults to Y-m-d H:i:s if not defined. </font></p> 2604 <p><font><b>UnixDate<a name="unixdate"></a>($str)</b></font></p> 2605 <p><font>Parses the date string $<b>str</b> and returns it in 2606 unix mktime format (eg. a number indicating the seconds after January 1st, 2607 1970). Expects the date to be in Y-m-d H:i:s format, except for Sybase and 2608 Microsoft SQL Server, where M d Y is also accepted (the 3 letter month strings 2609 are controlled by a global array, which might need localisation).</font></p> 2610 <p><font>This function is available in both ADORecordSet and 2611 ADOConnection since 1.91.</font></p> 2612 <p><font><b>UnixTimeStamp<a name="unixtimestamp"></a>($str)</b></font></p> 2613 <p><font>Parses the timestamp string $<b>str</b> and returns 2614 it in unix mktime format (eg. a number indicating the seconds after January 2615 1st, 1970). Expects the date to be in "Y-m-d, H:i:s" (1970-12-24, 00:00:00) 2616 or "Y-m-d H:i:s" (1970-12-24 00:00:00) or "YmdHis" (19701225000000) format, 2617 except for Sybase and Microsoft SQL Server, where "M d Y h:i:sA" (Dec 25 2618 1970 00:00:00AM) is also accepted (the 3 letter month strings are controlled 2619 by a global array, which might need localisation).</font></p> 2620 <font> 2621 </font><p><font>This function is available in both ADORecordSet 2622 and ADOConnection since 1.91. </font></p> 2623 <p><font><b>OffsetDate<a name="OffsetDate"></a>($dayFraction, 2624 $basedate=false)</b></font></p> 2625 <p><font>Returns a string with the native SQL functions to calculate 2626 future and past dates based on $basedate in a portable fashion. If $basedate 2627 is not defined, then the current date (at 12 midnight) is used. Returns the 2628 SQL string that performs the calculation when passed to Execute(). </font></p> 2629 <p><font>For example, in Oracle, to find the date and time that 2630 is 2.5 days from today, you can use:</font></p> 2631 <pre><font># get date one week from now<br>$fld = $conn->OffsetDate(7); // returns "(trunc(sysdate)+7")</font></pre> 2632 <pre><font># get date and time that is 60 hours from current date and time<br>$fld = $conn->OffsetDate(2.5, $conn->sysTimeStamp); // returns "(sysdate+2.5)"<br><br>$conn->Execute("UPDATE TABLE SET dodate=$fld WHERE ID=$id");</font></pre> 2633 <p><font> This function is available for mysql, mssql, oracle, oci8 and postgresql drivers 2634 since 2.13. It might work with other drivers provided they allow performing 2635 numeric day arithmetic on dates.</font></p> 2636 <font> </font> 2637 <p><font><b>SQLDate<a name="sqldate"></a>($dateFormat, $basedate=false)</b></font></p> 2638 <font>Returns a string which contains the native SQL functions 2639 to format a date or date column $basedate. This is used when retrieving date columns in SELECT statements. 2640 For sending dates to the database (eg. in UPDATE, INSERT or the where clause of SELECT statements) 2641 use <a href="#dbdate">DBDate</a>. It uses a case-sensitive 2642 $dateFormat, which supports: </font> 2643 <pre><font> 2644 Y: 4-digit Year 2645 Q: Quarter (1-4) 2646 M: Month (Jan-Dec) 2647 m: Month (01-12) 2648 d: Day (01-31) 2649 H: Hour (00-23) 2650 h: Hour (1-12) 2651 i: Minute (00-59) 2652 s: Second (00-60) 2653 A: AM/PM indicator 2654 w: day of week (0-6 or 1-7 depending on DB) 2655 l: day of week (as string - lowercase L) 2656 W: week in year (0..53 for MySQL, 1..53 for PostgreSQL and Oracle) 2657 </font></pre> 2658 <p><font>All other characters are treated as strings. You can 2659 also use \ to escape characters. Available on selected databases, including 2660 mysql, postgresql, mssql, oci8 and DB2. </font></p> 2661 <p><font>This is useful in writing portable sql statements that 2662 GROUP BY on dates. For example to display total cost of goods sold broken 2663 by quarter (dates are stored in a field called postdate): </font></p> 2664 <pre><font> $sqlfn = $db->SQLDate('Y-\QQ','postdate'); # get sql that formats postdate to output 2002-Q1<br> $sql = "SELECT $sqlfn,SUM(cogs) FROM table GROUP BY $sqlfn ORDER BY 1 desc";<br> </font></pre> 2665 <p><font><b>MoveNext<a name="movenext"></a>( )</b></font></p> 2666 <p><font>Move the internal cursor to the next row. The <i>$this->fields</i> array 2667 is automatically updated. Returns false if unable to do so (normally because 2668 EOF has been reached), otherwise true. </font></p> 2669 <p><font> If EOF is reached, then the $this->fields array 2670 is set to false (this was only implemented consistently in ADOdb 3.30). For 2671 the pre-3.30 behaviour of $this->fields (at EOF), set the global variable 2672 $ADODB_COMPAT_FETCH = true.</font></p> 2673 <p><font>Example:</font></p> 2674 <pre><font>$rs = $db->Execute($sql);<br>if ($rs) <br> while (!$rs->EOF) {<br> ProcessArray($rs->fields); <br> $rs->MoveNext();<br> } </font></pre> 2675 <p><font><b>Move<a name="move"></a>($to)</b></font></p> 2676 <p><font>Moves the internal cursor to a specific row $<b>to</b>. 2677 Rows are zero-based eg. 0 is the first row. The <b>fields</b> array is automatically 2678 updated. For databases that do not support scrolling internally, ADOdb will 2679 simulate forward scrolling. Some databases do not support backward scrolling. 2680 If the $<b>to</b> position is after the EOF, $<b>to</b> will move to the 2681 end of the RecordSet for most databases. Some obscure databases using odbc 2682 might not behave this way.</font></p> 2683 <p><font>Note: This function uses <i>absolute positioning</i>, 2684 unlike Microsoft's ADO.</font></p> 2685 <p><font>Returns true or false. If false, the internal cursor 2686 is not moved in most implementations, so AbsolutePosition( ) will return 2687 the last cursor position before the Move( ). </font></p> 2688 <p><font><b>MoveFirst<a name="movefirst"></a>()</b></font></p> 2689 <p><font>Internally calls Move(0). Note that some databases do 2690 not support this function.</font></p> 2691 <p><font><b>MoveLast<a name="movelast"></a>()</b></font></p> 2692 <p><font>Internally calls Move(RecordCount()-1). Note that some 2693 databases do not support this function.</font></p> 2694 <p><font><b>GetRowAssoc</b><a name="getrowassoc"></a>($toUpper=true)</font></p> 2695 <p><font>Returns an associative array containing the current 2696 row. The keys to the array are the column names. The column names are upper-cased 2697 for easy access. To get the next row, you will still need to call MoveNext(). </font></p> 2698 <p><font>For example:<br> 2699 Array ( [ID] => 1 [FIRSTNAME] => Caroline [LASTNAME] => Miranda [CREATED] 2700 => 2001-07-05 ) </font></p> 2701 <p><font>Note: do not use GetRowAssoc() with $ADODB_FETCH_MODE 2702 = ADODB_FETCH_ASSOC. Because they have the same functionality, they will 2703 interfere with each other.</font></p> 2704 <font> 2705 </font><p><font><b>AbsolutePage<a name="absolutepage"></a>($page=-1) </b></font></p> 2706 <p><font>Returns the current page. Requires PageExecute()/CachePageExecute() to be called. 2707 See <a href="#ex8">Example 8</a>.</font></p> 2708 <font> 2709 <p><b>AtFirstPage<a name="atfirstpage">($status='')</a></b></p> 2710 <p>Returns true if at first page (1-based). Requires PageExecute()/CachePageExecute() 2711 to be called. See <a href="#ex8">Example 8</a>.</p> 2712 <p><b>AtLastPage<a name="atlastpage">($status='')</a></b></p> 2713 <p>Returns true if at last page (1-based). Requires PageExecute()/CachePageExecute() 2714 to be called. See <a href="#ex8">Example 8</a>.</p> 2715 <p><b>Fields</b><a name="fields"></a>(<b>$colname</b>)</p> 2716 <p>Returns the value of the associated column $<b>colname</b> for the current 2717 row. The column name is case-insensitive.</p> 2718 <p>This is a convenience function. For higher performance, use <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>. </p> 2719 <p><b>FetchRow</b><a name="fetchrow"></a>()</p> 2720 </font><p><font>Returns array containing current row, or false 2721 if EOF. FetchRow( ) internally moves to the next record after returning the 2722 current row. </font></p> 2723 <p><font>Warning: Do not mix using FetchRow() with MoveNext().</font></p> 2724 <p><font>Usage:</font></p> 2725 <pre><font>$rs = $db->Execute($sql);<br>if ($rs)<br> while ($arr = $rs->FetchRow()) {<br> # process $arr <br> }</font></pre> 2726 <p><font><b>FetchInto</b><a name="fetchinto"></a>(<b>&$array</b>)</font></p> 2727 <p><font> Sets $array to the current row. Returns PEAR_Error 2728 object if EOF, 1 if ok (DB_OK constant). If PEAR is undefined, false is returned 2729 when EOF. FetchInto( ) internally moves to the next record after returning 2730 the current row. </font></p> 2731 <p><font> FetchRow() is easier to use. See above.</font></p> 2732 <font> </font> 2733 <p><font><b>FetchField<a name="fetchfield"></a>($column_number)</b></font></p> 2734 <p><font>Returns an object containing the <b>name</b>, <b>type</b> and <b>max_length</b> of 2735 the associated field. If the max_length cannot be determined reliably, it 2736 will be set to -1. The column numbers are zero-based. See <a href="#ex2">example 2737 2.</a></font></p> 2738 <p><font><b>FieldCount<a name="fieldcount"></a>( )</b></font></p> 2739 <p><font>Returns the number of fields (columns) in the record 2740 set.</font></p> 2741 <p><font><b>RecordCount<a name="recordcount"></a>( )</b></font></p> 2742 <p><font>Returns the number of rows in the record set. If the 2743 number of records returned cannot be determined from the database driver 2744 API, we will buffer all rows and return a count of the rows after all the 2745 records have been retrieved. This buffering can be disabled (for performance 2746 reasons) by setting the global variable $ADODB_COUNTRECS = false. When disabled, 2747 RecordCount( ) will return -1 for certain databases. See the supported databases 2748 list above for more details. </font></p> 2749 <p><font> RowCount is a synonym for RecordCount.</font></p> 2750 <p><font><b>PO_RecordCount<a name="po_recordcount"></a>($table, 2751 $where)</b></font></p> 2752 <p><font>Returns the number of rows in the record set. If the 2753 database does not support this, it will perform a SELECT COUNT(*) on the 2754 table $table, with the given $where condition to return an estimate of the 2755 recordset size.</font></p> 2756 <p><font>$numrows = $rs->PO_RecordCount("articles_table", "group=$group");</font></p> 2757 <font><b> NextRecordSet<a name="nextrecordset" id="nextrecordset"></a>()</b> </font> 2758 <p><font>For databases that allow multiple recordsets to be returned 2759 in one query, this function allows you to switch to the next recordset. Currently 2760 only supported by mssql driver.</font></p> 2761 <pre><font>$rs = $db->Execute('execute return_multiple_rs');<br>$arr1 = $rs->GetArray();<br>$rs->NextRecordSet();<br>$arr2 = $rs->GetArray();</font></pre> 2762 <p><font><b>FetchObject<a name="fetchobject"></a>($toupper=true)</b></font></p> 2763 <p><font>Returns the current row as an object. If you set $toupper 2764 to true, then the object fields are set to upper-case. Note: The newer FetchNextObject() 2765 is the recommended way of accessing rows as objects. See below.</font></p> 2766 <p><font><b>FetchNextObject<a name="fetchnextobject"></a>($toupper=true)</b></font></p> 2767 <p><font>Gets the current row as an object and moves to the next 2768 row automatically. Returns false if at end-of-file. If you set $toupper to 2769 true, then the object fields are set to upper-case. Note that for some drivers such as mssql, you need to SetFetchMode(ADODB_FETCH_ASSOC) or SetFetchMode(ADODB_FETCH_BOTH).</font></p> 2770 <pre><font>$rs = $db->Execute('select firstname,lastname from table');<br>if ($rs) {<br> while ($o = $rs->FetchNextObject()) {<br> print "$o->FIRSTNAME, $o->LASTNAME<BR>";<br> }<br>}<br></font></pre> 2771 <p><font>There is some trade-off in speed in using FetchNextObject(). 2772 If performance is important, you should access rows with the <code>fields[]</code> array. <b>FetchObj<a name="fetchobj" id="fetchobj"></a>()</b> </font></p> 2773 <p><font>Returns the current record as an object. Fields are 2774 not upper-cased, unlike FetchObject. 2775 </font></p> 2776 <p><font><b>FetchNextObj<a name="fetchnextobj" id="fetchnextobj"></a>()</b> </font></p> 2777 <p><font>Returns the current record as an object and moves to 2778 the next record. If EOF, false is returned. Fields are not upper-cased, unlike 2779 FetctNextObject. </font></p> 2780 <font> 2781 <p><b>CurrentRow<a name="currentrow"></a>( )</b></p> 2782 <p>Returns the current row of the record set. 0 is the first row.</p> 2783 <p><b>AbsolutePosition<a name="abspos"></a>( )</b></p> 2784 <p>Synonym for <b>CurrentRow</b> for compatibility with ADO. Returns the current 2785 row of the record set. 0 is the first row.</p> 2786 <p><b>MetaType<a name="metatype"></a>($nativeDBType[,$field_max_length],[$fieldobj])</b></p> 2787 <p>Determine what <i>generic</i> meta type a database field type is given its 2788 native type $<b>nativeDBType</b> as a string and the length of the field $<b>field_max_length</b>. 2789 Note that field_max_length can be -1 if it is not known. The field object returned 2790 by FetchField() can be passed in $<b>fieldobj</b> or as the 1st parameter <b>$nativeDBType</b>. 2791 This is useful for databases such as <i>mysql</i> which has additional properties 2792 in the field object such as <i>primary_key</i>. </p> 2793 <p>Uses the field <b>blobSize</b> and compares it with $<b>field_max_length</b> to 2794 determine whether the character field is actually a blob.</p> 2795 For example, $db->MetaType('char') will return 'C'. 2796 <p>Returns:</p> 2797 <ul> 2798 <li><b>C</b>: Character fields that should be shown in a <input type="text"> tag. </li> 2799 <li><b>X</b>: Clob (character large objects), or large text fields that should 2800 be shown in a <textarea></li> 2801 <li><b>D</b>: Date field</li> 2802 <li><b>T</b>: Timestamp field</li> 2803 <li><b>L</b>: Logical field (boolean or bit-field)</li> 2804 <li><b>N</b>: Numeric field. Includes decimal, numeric, floating point, and 2805 real. </li> 2806 <li><b>I</b>: Integer field. </li> 2807 <li><b>R</b>: Counter or Autoincrement field. Must be numeric.</li> 2808 <li><b>B</b>: Blob, or binary large objects. </li> 2809 </ul> 2810 </font><p><font> Since ADOdb 3.0, MetaType accepts $fieldobj 2811 as the first parameter, instead of $nativeDBType. </font></p> 2812 <font> </font> 2813 <p><font><b>Close( )<a name="rsclose"></a></b></font></p> 2814 <p><font>Closes the recordset, cleaning all memory and resources 2815 associated with the recordset. </font></p> 2816 <p> 2817 <font>If memory management is not an issue, you do not need to 2818 call this function as recordsets are closed for you by PHP at the end of the 2819 script. SQL statements such as INSERT/UPDATE/DELETE do not really return a recordset, 2820 so you do not have to call Close() for such SQL statements.</font></p> 2821 <hr /> 2822 <h3><font>function rs2html<a name="rs2html"></a>($adorecordset,[$tableheader_attributes], 2823 [$col_titles])</font></h3> 2824 <p><font>This is a standalone function (rs2html = recordset to 2825 html) that is similar to PHP's <i>odbc_result_all</i> function, it prints 2826 a ADORecordSet, $<b>adorecordset</b> as a HTML table. $<b>tableheader_attributes</b> allow 2827 you to control the table <i>cellpadding</i>, <i>cellspacing</i> and <i>border</i> attributes. 2828 Lastly you can replace the database column names with your own column titles 2829 with the array $<b>col_titles</b>. This is designed more as a quick debugging 2830 mechanism, not a production table recordset viewer.</font></p> 2831 <p><font>You will need to include the file <i>tohtml.inc.php</i>.</font></p> 2832 <p><font>Example of rs2html:<b><font color="#336600"><a name="exrs2html"></a></font></b></font></p> 2833 <pre><font><b><font color="#336600"><?<br>include('tohtml.inc.php')</font></b>; # load code common to ADOdb <br><b>include</b>('adodb.inc.php'); # load code common to ADOdb <br>$<font color="#663300">conn</font> = &ADONewConnection('mysql'); # create a connection <br>$<font color="#663300">conn</font>->PConnect('localhost','userid','','agora');# connect to MySQL, agora db<br>$<font color="#663300">sql</font> = 'select CustomerName, CustomerID from customers'; <br>$<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute($sql); <br><font color="#336600"><b>rs2html</b></font><b>($<font color="#663300">rs</font>,'<i>border=2 cellpadding=3</i>',array('<i>Customer Name','Customer ID</i>'));<br>?></b></font></pre> 2834 <hr /> 2835 <h3><font>Differences between this ADOdb library and Microsoft 2836 ADO<a name="adodiff"></a></font></h3> 2837 <ol> 2838 <font> 2839 <li>ADOdb only supports recordsets created by a connection object. Recordsets 2840 cannot be created independently.</li> 2841 <li>ADO properties are implemented as functions in ADOdb. This makes it easier 2842 to implement any enhanced ADO functionality in the future.</li> 2843 <li>ADOdb's <font face="Courier New, Courier, mono">ADORecordSet->Move()</font> uses 2844 absolute positioning, not relative. Bookmarks are not supported.</li> 2845 <li><font face="Courier New, Courier, mono">ADORecordSet->AbsolutePosition() </font>cannot 2846 be used to move the record cursor.</li> 2847 <li>ADO Parameter objects are not supported. Instead we have the ADOConnection::<a href="#parameter">Parameter</a>( 2848 ) function, which provides a simpler interface for calling preparing parameters 2849 and calling stored procedures.</li> 2850 <li>Recordset properties for paging records are available, but implemented as 2851 in <a href="#ex8">Example 8</a>.</li> 2852 </font></ol> 2853 <hr /> 2854 <h1><font>Database Driver Guide<a name="driverguide"></a></font></h1> 2855 <p><font>This describes how to create a class to connect to a 2856 new database. To ensure there is no duplication of work, kindly email me 2857 at jlim#natsoft.com.my if you decide to create such a class.</font></p> 2858 <p><font>First decide on a name in lower case to call the database 2859 type. Let's say we call it xbase. </font></p> 2860 <p><font>Then we need to create two classes ADODB_xbase and ADORecordSet_xbase 2861 in the file adodb-xbase.inc.php.</font></p> 2862 <p><font>The simplest form of database driver is an adaptation 2863 of an existing ODBC driver. Then we just need to create the class <i>ADODB_xbase 2864 extends ADODB_odbc</i> to support the new <b>date</b> and <b>timestamp</b> formats, 2865 the <b>concatenation</b> operator used, <b>true</b> and <b>false</b>. For 2866 the<i> ADORecordSet_xbase extends ADORecordSet_odbc </i>we need to change 2867 the <b>MetaType</b> function. See<b> adodb-vfp.inc.php</b> as an example.</font></p> 2868 <p><font>More complicated is a totally new database driver that 2869 connects to a new PHP extension. Then you will need to implement several 2870 functions. Fortunately, you do not have to modify most of the complex code. 2871 You only need to override a few stub functions. See <b>adodb-mysql.inc.php</b> for 2872 example.</font></p> 2873 <p><font>The default date format of ADOdb internally is YYYY-MM-DD 2874 (Ansi-92). All dates should be converted to that format when passing to an 2875 ADOdb date function. See Oracle for an example how we use ALTER SESSION to 2876 change the default date format in _pconnect _connect.</font></p> 2877 <p><font><b>ADOConnection Functions to Override</b></font></p> 2878 <p><font>Defining a constructor for your ADOConnection derived 2879 function is optional. There is no need to call the base class constructor.</font></p> 2880 <p><font>_<b>connect</b>: Low level implementation of Connect. 2881 Returns true or false. Should set the _<b>connectionID</b>.</font></p> 2882 <p><font>_<b>pconnect:</b> Low level implemention of PConnect. 2883 Returns true or false. Should set the _<b>connectionID</b>.</font></p> 2884 <p><font>_<b>query</b>: Execute a query. Returns the queryID, 2885 or false.</font></p> 2886 <p><font>_<b>close: </b>Close the connection -- PHP should clean 2887 up all recordsets. </font></p> 2888 <p><font><b>ErrorMsg</b>: Stores the error message in the private 2889 variable _errorMsg. </font></p> 2890 <p><font><b>ADOConnection Fields to Set</b></font></p> 2891 <p><font>_<b>bindInputArray</b>: Set to true if binding of parameters 2892 for SQL inserts and updates is allowed using ?, eg. as with ODBC.</font></p> 2893 <p><font><b>fmtDate</b></font></p> 2894 <p><font><b>fmtTimeStamp</b></font></p> 2895 <p><font><b>true</b></font></p> 2896 <p><font><b>false</b></font></p> 2897 <p><font><b>concat_operator</b></font></p> 2898 <p><font><b>replaceQuote</b></font></p> 2899 <p><font><b>hasLimit</b> support SELECT * FROM TABLE LIMIT 10 2900 of MySQL.</font></p> 2901 <p><font><b>hasTop</b> support Microsoft style SELECT TOP 10 2902 * FROM TABLE.</font></p> 2903 <p><font><b>ADORecordSet Functions to Override</b></font></p> 2904 <p><font>You will need to define a constructor for your ADORecordSet 2905 derived class that calls the parent class constructor.</font></p> 2906 <p><font><b>FetchField: </b> as documented above in ADORecordSet</font></p> 2907 <p><font>_<b>initrs</b>: low level initialization of the recordset: 2908 setup the _<b>numOfRows</b> and _<b>numOfFields</b> fields -- called by the 2909 constructor.</font></p> 2910 <p><font>_<b>seek</b>: seek to a particular row. Do not load 2911 the data into the fields array. This is done by _fetch. Returns true or false. 2912 Note that some implementations such as Interbase do not support seek. Set 2913 canSeek to false.</font></p> 2914 <p><font>_<b>fetch</b>: fetch a row using the database extension 2915 function and then move to the next row. Sets the <b>fields</b> array. If 2916 the parameter $ignore_fields is true then there is no need to populate the <b>fields</b> array, 2917 just move to the next row. then Returns true or false.</font></p> 2918 <p><font>_<b>close</b>: close the recordset</font></p> 2919 <p><font><b>Fields</b>: If the array row returned by the PHP 2920 extension is not an associative one, you will have to override this. See 2921 adodb-odbc.inc.php for an example. For databases such as MySQL and MSSQL 2922 where an associative array is returned, there is no need to override this 2923 function.</font></p> 2924 <p><font><b>ADOConnection Fields to Set</b></font></p> 2925 <p><font>canSeek: Set to true if the _seek function works.</font></p> 2926 <h2><font>Optimizing PHP</font></h2> 2927 For info on tuning PHP, read this article on <a href="http://phplens.com/lens/php-book/optimizing-debugging-php.php">Optimizing 2928 PHP</a>. </font></p> 2929 2930 <h2><font>Change Log<a name="Changes"></a><a name="changes"></a><a name="changelog"></a></font></h2> 2931 2932 <p><a name="4.96"></a><b>4.96/5.02 ? ? 2007</b> 2933 <p>Fix adodb count optimisation. Preg_match did not work properly. 2934 <p>SelectLimit for oci8 not optimal for large recordsets when offset=0. Changed $nrows check. 2935 <p>Rewrote the ORDER BY stripping code in _adodb_getcount(), adodb-lib.inc.php. 2936 <p>Now GetOne returns null if EOF (no records found), and false if error occurs. Use ErrorMsg()/ErrorNo() to get the error. 2937 <p>Added BIT data type support to adodb-ado.inc.php and adodb-ado5.inc.php. 2938 <p>Ldap driver did not return actual ldap error messages. Fixed. 2939 <p>Implemented GetRandRow($sql, $inputarr). Optimized for Oci8. 2940 <p>Changed adodb5 active record to use static SetDatabaseAdapter() and removed php4 constructor. Bas van Beek bas.vanbeek#gmail.com. 2941 <p>Also in adodb5, changed adodb-session2 to use static function declarations in class. Thx Daniel Berlin. 2942 <p>Added "Clear SQL Log" to bottom of Performance screen. 2943 <p>Sessions2 code echo'ed directly to the screen in debug mode. Now uses ADOConnection::outp(). 2944 <p>In mysql/mysqli, qstr(null) will return the string "null" instead of empty quoted string "''". 2945 <p>postgresql optimizeTable in perf-postgres.inc.php added by Daniel Berlin (mail#daniel-berlin.de) 2946 <p>Added 5.2.1 compat code for oci8. 2947 <p>Changed @@identity to SCOPE_IDENTITY() for multiple mssql drivers. Thx Stefano Nari. 2948 <p>Code sanitization introduced in 4.95 caused problems in European locales (as float 3.2 was typecast to 3,2). Now we only sanitize if is_numeric fails. 2949 <p>Added support for customizing ADORecordset_empty using $this->rsPrefix.'empty'. By Josh Truwin. 2950 <p>Added proper support for ALterColumnSQL for Postgresql in datadict code. Thx. Josh Truwin. 2951 <p>Added better support for MetaType() in mysqli when using an array recordset. 2952 <p><a name="4.95"></a><b>4.95/5.01 17 May 2007</b> 2953 <p>CacheFlush debug outp() passed in invalid parameters. Fixed. 2954 <p>Added Thai language file for adodb. Thx Trirat Petchsingh rosskouk#gmail.com and Marcos Pont</p> 2955 <p>Added zerofill checking support to MetaColumns for mysql and mysqli. 2956 <p>CacheFlush no longer deletes all files/directories. Only *.cache files deleted.</p> 2957 <p>DB2 timestamp format changed to var $fmtTimeStamp = "'Y-m-d-H:i:s'";</p> 2958 <p>Added some code sanitization to AutoExecute in adodb-lib.inc.php.</p> 2959 <p>Due to typo, all connections in adodb-oracle.inc.php would become persistent, even non-persistent ones. Fixed.</p> 2960 <P>Oci8 DBTimeStamp uses 24 hour time for input now, so you can perform string comparisons between 2 DBTimeStamp values.</P> 2961 <p>Some PHP4.4 compat issues fixed in adodb-session2.inc.php</p> 2962 <p>For ADOdb 5.01, fixed some adodb-datadict.inc.php MetaType compat issues with PHP5. 2963 <p>The $argHostname was wiped out in adodb-ado5.inc.php. Fixed. 2964 <p>Adodb5 version, added iterator support for adodb_recordset_empty. 2965 <p>Adodb5 version,more error checking code now will use exceptions if available. 2966 <p><a name="4.94"></a><b>4.94 23 Jan 2007</b> 2967 <p>Active Record: $ADODB_ASSOC_CASE=2 did not work properly. Fixed. Thx gmane#auxbuss.com. 2968 <p>mysqli had bugs in BeginTrans() and EndTrans(). Fixed.</p> 2969 <p>Improved error handling when no database is connected for oci8. Thx Andy Hassall.</p> 2970 <p>Names longer than 30 chars in oci8 datadict will be changed to random name. Thx Eugenio. http://phplens.com/lens/lensforum/msgs.php?id=16182 2971 <p>Added var $upperCase = 'ucase' to access and ado_access drivers. Thx Renato De Giovanni renato#cria.org.br</p> 2972 <p>Postgres64 driver, if preparing plan failed in _query, did not handle error properly. Fixed. See http://phplens.com/lens/lensforum/msgs.php?id=16131. 2973 <p>Fixed GetActiveRecordsClass() reference bug. See http://phplens.com/lens/lensforum/msgs.php?id=16120 2974 <p> 2975 2976 Added handling of nulls in adodb-ado_mssql.inc.php for qstr(). Thx to Felix Rabinovich. 2977 <p> 2978 2979 Adodb-dict contributions by Gaetano: 2980 <br> 2981 + Support for INDEX in data-dict. Example: 2982 idx_ev1. The ability to define indexes using the INDEX keyword was added in ADOdb 4.94. The following example features mutiple indexes, including a compound index idx_ev1. 2983 <pre> 2984 event_id I(11) NOTNULL AUTOINCREMENT PRIMARY, 2985 event_type I(4) NOTNULL <b>INDEX idx_evt</b>, 2986 event_start_date T DEFAULT NULL <b>INDEX id_esd</b>, 2987 event_end_date T DEFAULT '0000-00-00 00:00:00' <b>INDEX id_eted</b>, 2988 event_parent I(11) UNSIGNED NOTNULL DEFAULT 0 <b>INDEX id_evp</b>, 2989 event_owner I(11) DEFAULT 0 <b>INDEX idx_ev1</b>, 2990 event_project I(11) DEFAULT 0 <b>INDEX idx_ev1</b>, 2991 event_times_recuring I(11) UNSIGNED NOTNULL DEFAULT 0, 2992 event_icon C(20) DEFAULT 'obj/event', 2993 event_description X 2994 </pre> 2995 <br> 2996 + Prevents the generated SQL from including double drop-sequence statements for REPLACE case of tables with autoincrement columns (on those dbs that emulate it via sequences) 2997 <br> 2998 + makes any date defined as DEFAULT value for D and T columns work cross-database, not just the "sysdate" value (as long as it is specified using adodb standard format). See above example. 2999 <p>Fixed pdo's GetInsertID() support. Thx Ricky Su. 3000 <p>oci8 Prepare() now sets error messages if an error occurs. 3001 <p>Added 'PT_BR' to SetDateLocale() -- brazilian portugese. 3002 <p>charset in oci8 was not set correctly on *Connect() 3003 <p>ADOConnection::Transpose() now appends as first column the field names. 3004 <p>Added $ADODB_QUOTE_FIELDNAMES. If set to true, will autoquote field names in AutoExecute(),GetInsertSQL(), GetUpdateSQL(). 3005 <p>Transpose now adds the field names as the first column after transposition. 3006 <p>Added === check in ADODB_SetDatabaseAdapter for $db, adodb-active-record.inc.php. Thx Christian Affolter. 3007 <p>Added ErrorNo() to adodb-active-record.inc.php. Thx ante#novisplet.com. 3008 3009 3010 3011 <p><a name="4.93"></a><b>4.93 10 Oct 2006</b> 3012 <p>Added support for multiple database connections in performance monitoring code (adodb-perf.inc.php). Now all sql in multiple database connections can be saved into one database ($ADODB_LOG_CONN). 3013 <p>Added MetaIndexes() to odbc_mssql. 3014 <p>Added connection property $db->null2null = 'null'. In autoexecute/getinsertsql/getupdatesql, this value will be converted to a null. Set this to a funny invalid value if you do not want null conversion. See http://phplens.com/lens/lensforum/msgs.php?id=15902. 3015 <p>Path disclosure problem in mysqli fixed. Thx Andy. 3016 <p>Fixed typo in session_schema2.xml. 3017 <p>Changed INT in oci8 to return correct precision in $fld->max_length, MetaColumns(). Thx Eloy Lafuente Plaza. 3018 <p>Patched postgres64 _connect to handle serverinfo(). see http://phplens.com/lens/lensforum/msgs.php?id=15887. 3019 <p>Added pdo fix for null columns. See http://phplens.com/lens/lensforum/msgs.php?id=15889 3020 <p>For stored procedures, missing connection id now passed into mssql_query(). Thx Ecsy (ecsy#freemail.hu). 3021 3022 <p><a name="4.92a"></a><b>4.92a 30 Aug 2006</b> 3023 <p>Syntax error in postgres7 driver. Thx Eloy Lafuente Plaza. 3024 <p>Minor bug fixes - adodb informix 10 types added to adodb.inc.php. Thx Fernando Ortiz. 3025 3026 <p><a name="4.92"></a><b>4.92 29 Aug 2006</b> 3027 3028 <p>Better odbtp date support. 3029 <P>Added IgnoreErrors() to bypass default error handling. 3030 <p>The _adodb_getcount() function in adodb-lib.inc.php, some ORDER BY bug fixes. 3031 <p>For ibase and firebird, set $sysTimeStamp = "CURRENT_TIMESTAMP". 3032 <p>Fixed postgres connection bug: http://phplens.com/lens/lensforum/msgs.php?id=11057. 3033 <p>Changed CacheSelectLimit() to flush cache when $secs2cache==-1 due to complaints from other users. 3034 <p>Added support for using memcached with CacheExecute/CacheSelectLimit. Requires memcache module PECL extension. Usage: 3035 <pre> 3036 $db = NewADOConnection($driver); 3037 $db->memCache = true; /// should we use memCache instead of caching in files 3038 $db->memCacheHost = 126.0.1.1; /// memCache host 3039 $db->memCachePort = 11211; /// this is default memCache port 3040 $db->memCacheCompress = false; /// Use 'true' to store the item compressed (uses zlib) 3041 3042 $db->Connect(...); 3043 $db->CacheExecute($sql); 3044 </pre> 3045 <p>Implemented Transpose() for recordsets. Recordset must be retrieved using ADODB_FETCH_NUM. First column becomes the 3046 column name. 3047 <pre> 3048 $DB = NewADOConnection('mysql'); 3049 $DB->Connect(...); 3050 $DB->SetFetchMode(ADODB_FETCH_NUM); 3051 $rs = $DB->Execute('select productname,productid,unitprice from products limit 10'); 3052 $rs2 = $DB->Transpose($rs); 3053 rs2html($rs2); 3054 </pre> 3055 <p><a name="4.91"></a><b>4.91 2 Aug 2006</b> 3056 <p>Major session code rewrite .... See session docs. 3057 <p>PDO bindinputarray was not set properly for MySQL (changed from true to false). 3058 <p>Changed CacheSelectLimit() to re-cache when $secs2cache==0. This is one way to flush the cache when SelectLimit is called. 3059 <p>Added to quotes to mysql and mysqli: "SHOW COLUMNS FROM `%s`"; 3060 <p>Removed accidental optgroup handling in GetMenu(). 3061 <a>Fixed ibase _BlobDecode for php5 compat, and also mem alloc issues for small blobs, thx salvatori#interia.pl 3062 <p>Mysql driver OffsetDate() speedup, useful for adodb-sessions. 3063 <p>Fix for GetAssoc() PHP5 compat. See http://phplens.com/lens/lensforum/msgs.php?id=15425 3064 <p>Active Record - If inserting a record and the value of a primary key field is null, then we do not insert that field in as we assume it is an auto-increment field. Needed by mssql. 3065 <p>Changed postgres7 MetaForeignKeys() see http://phplens.com/lens/lensforum/msgs.php?id=15531 3066 <p>DB2 will now return db2_conn_errormsg() when it is a connection error. 3067 <p><a name="4.90"></a><b>4.90 8 June 2006</b> 3068 <p>Changed adodb_countrec() in adodb-lib.inc.php to allow LIMIT to be used as a speedup to reduce no of records counted. 3069 <p>Added support for transaction modes for postgres and oci8 with SetTransactionMode(). 3070 These transaction modes affect all subsequent transactions of that connection. 3071 <p>Thanks to Halmai Csongor for suggestion. 3072 <p>Removed $off = $fieldOffset - 1 line in db2 driver, FetchField(). Tx Larry Menard. 3073 <p>Added support for PHP5 objects as Execute() bind parameters using __toString (eg. Simple-XML). Thx Carl-Christian Salvesen. 3074 <p>Rounding in tohtml.inc.php did not work properly. Fixed. 3075 <p>MetaIndexes in postgres fails when fields are deleted then added in again because the attnum has gaps in it. 3076 See http://sourceforge.net/tracker/index.php?func=detail&aid=1451245&group_id=42718&atid=433976. Fixed. 3077 <p>MetaForeignkeys in mysql and mysqli did not work when fetchMode==ADODB_FETCH_ASSOC used. Fixed. 3078 <p>Reference error in AutoExecute() fixed. 3079 <p>Added macaddr postgres type to MetaType. Maps to 'C'. 3080 <p>Added to _connect() in adodb-ado5.inc.php support for $database and $dataProvider parameters. Thx Larry Menard. 3081 <p>Added support for sequences in adodb-ado_mssql.inc.php. Thx Larry Menard. 3082 <p>Added ADODB_SESSION_READONLY. 3083 <p>Added session expiryref support to crc32 mode, and in LOB code. 3084 <p>Clear _errorMsg in postgres7 driver, so that ErrorMsg() displays properly when no error occurs. 3085 <p>Added BindDate and BindTimeStamp 3086 <p><a name="4.81"></a><b>4.81 3 May 2006</b> 3087 <p>Fixed variable ref errors in adodb-ado5.inc.php in _query(). 3088 <p>Mysqli setcharset fix using method_exists(). 3089 <p>The adodb-perf.inc.php CreateLogTable() code now works for user-defined table names. 3090 <p>Error in ibase_blob_open() fixed. See http://phplens.com/lens/lensforum/msgs.php?id=14997 3091 <p><a name="4.80"></a><b>4.80 8 Mar 2006</b> 3092 <p>Added activerecord support. 3093 <p>Added mysql $conn->compat323 = true if you want MySQL 3.23 compat enabled. Fixes GetOne() Select-Limit problems. 3094 <p>Added adodb-xmlschema03.inc.php to support XML Schema version 3 and updated adodb-datadict.htm docs. 3095 <p>Better memory management in Execute. Thx Mike Fedyk. 3096 <p><a name="4.72"></a><b>4.72 21 Feb 2006</b> 3097 <p>Added 'new' DSN parameter for NConnect(). 3098 <p>Pager now sanitizes $PHP_SELF to protect against XSS. Thx to James Bercegay and others. 3099 <p>ADOConnection::MetaType changed to setup $rs->connection correctly. 3100 <p>New native DB2 driver contributed by Larry Menard, Dan Scott, Andy Staudacher, Bharat Mediratta. 3101 <p>The mssql CreateSequence() did not BEGIN TRANSACTION correctly. Fixed. Thx Sean Lee. 3102 <p>The _adodb_countrecs() function in adodb-lib.inc.php has been revised to handle more ORDER BY variations. 3103 <p><a name="4.71"></a><b>4.71 24 Jan 2006</b> 3104 <p>Fixes postgresql security issue related to binary strings. Thx to Andy Staudacher. 3105 <p>Several DSN bugs found: 3106 <p>1. Fix bugs in DSN connections introduced in 4.70 when underscores are found in the DSN. 3107 <p>2. DSN with _ did not work properly in PHP5 (fine in PHP4). Fixed. 3108 <p>3. Added support for PDO DSN connections in NewADOConnection(), and database parameter in PDO::Connect(). 3109 <p>The oci8 datetime flag not correctly implemented in ADORecordSet_array. Fixed. 3110 <p>Added BlobDelete() to postgres, as a counterpoint to UpdateBlobFile(). 3111 <p>Fixed GetInsertSQL() to support oci8po. 3112 <p>Fixed qstr() issue with postgresql with \0 in strings. 3113 <p>Fixed some datadict driver loading issues in _adodb_getdriver(). 3114 <p>Added register shutdown function session_write_close in adodb-session.inc.php for PHP 5 compat. See http://phplens.com/lens/lensforum/msgs.php?id=14200. 3115 <p><a name="4.70"></a><b>4.70 6 Jan 2006</b> 3116 <p>Many fixes from Danila Ulyanov to ibase, oci8, postgres, mssql, odbc_oracle, odbtp, etc drivers. 3117 <p>Changed usage of binary hint in adodb-session.inc.php for mysql. See 3118 http://phplens.com/lens/lensforum/msgs.php?id=14160 3119 <p>Fixed invalid variable reference problem in undomq(), adodb-perf.inc.php. 3120 <p>Fixed http://phplens.com/lens/lensforum/msgs.php?id=14254 in adodb-perf.inc.php, _DBParameter() settings of fetchmode was wrong. 3121 <p>Fixed security issues in server.php and tmssql.php discussed by Andreas Sandblad in a Secunia security advisory. Added $ACCEPTIP = 127.0.0.1 3122 and changed suggested root password to something more secure. 3123 <p>Changed pager to close recordset after RenderLayout(). 3124 <p><a name="4.68"></a><b>4.68 25 Nov 2005</b> 3125 <p>PHP 5 compat for mysqli. MetaForeignKeys repeated twice and MYSQLI_BINARY_FLAG missing. 3126 <p>PHP 5.1 support for postgresql bind parameters using ? did not work if >= 10 parameters. Fixed. Thx to Stanislav Shramko. 3127 <p>Lots of PDO improvements. 3128 <p>Spelling error fixed in mysql MetaForeignKeys, $associative parameter. 3129 <p><a name="4.67"></a><b>4.67 16 Nov 2005</b> 3130 <p>Postgresql not_null flag not set to false correctly. Thx Cristian MARIN. 3131 <p>We now check in Replace() if key is in fieldArray. Thx Sébastien Vanvelthem. 3132 <p>_file_get_contents() function was missing in xmlschema. fixed. 3133 <p>Added week in year support to SQLDate(), using 'W' flag. Thx Spider. 3134 <p>In sqlite metacolumns was repeated twice, causing PHP 5 problems. Fixed. 3135 <p>Made debug output XHTML compliant. 3136 <p><a name="4.66"></a><b>4.66 28 Sept 2005</b> 3137 <p>ExecuteCursor() in oci8 did not clean up properly on failure. Fixed. 3138 <p>Updated xmlschema.dtd, by "Alec Smecher" asmecher#smecher.bc.ca 3139 <p>Hardened SelectLimit, typecasting nrows and offset to integer. 3140 <p>Fixed misc bugs in AutoExecute() and GetInsertSQL(). 3141 <p>Added $conn->database as the property holding the database name. The older $conn->databaseName is retained for backward 3142 compat. 3143 <p>Changed _adodb_backtrace() compat check to use function_exists(). 3144 <p>Bug in postgresql MetaIndexes fixed. Thx Kevin Jamieson. 3145 <p>Improved OffsetDate for MySQL, reducing rounding error. 3146 <p>Metacolumns added to sqlite. Thx Mark Newnham. 3147 <p>PHP 4.4 compat fixes for GetAssoc(). 3148 <p>Added postgresql bind support for php 5.1. Thx Cristiano da Cunha Duarte 3149 <p>OffsetDate() fixes for postgresql, typecasting strings to date or timestamp. 3150 <p>DBTimeStamp formats for mssql, odbc_mssql and postgresql made to conform with other db's. 3151 <p>Changed PDO constants from PDO_ to PDO:: to support latest spec. 3152 <p><a name="4.65"></a><b>4.65 22 July 2005</b> 3153 <p>Reverted 'X' in mssql datadict to 'TEXT' to be compat with mssql driver. However now you can 3154 set $datadict->typeX = 'varchar(4000)' or 'TEXT' or 'CLOB' for mssql and oci8 drivers. 3155 <p>Added charset support when using DSN for Oracle. 3156 <p>_adodb_getmenu did not use fieldcount() to get number of fields. Fixed. 3157 <p>MetaForeignKeys() for mysql/mysqli contributed by Juan Carlos Gonzalez. 3158 <p>MetaDatabases() now correctly returns an array for mysqli driver. Thx Cristian MARIN. 3159 <p>CompleteTrans(false) did not return false. Fixed. Thx to JMF. 3160 <p>AutoExecute() did not work with Oracle. Fixed. Thx José Moreira. 3161 <p>MetaType() added to connection object. 3162 <p>More PHP 4.4 reference return fixes. Thx Ryan C Bonham and others. 3163 3164 <p><a name="4.64"></a><b>4.64 20 June 2005</b> 3165 <p>In datadict, if the default field value is set to '', then it is not applied when the field is created. Fixed by Eugenio. 3166 <p>MetaPrimaryKeys for postgres did not work because of true/false change in 4.63. Fixed. 3167 <p>Tested ocifetchstatement in oci8. Rejected at the end. 3168 <p>Added port to dsn handling. Supported in postgres, mysql, mysqli,ldap. 3169 <p>Added 'w' and 'l' to mysqli SQLDate(). 3170 <p>Fixed error handling in ldap _connect() to be more consistent. Also added ErrorMsg() handling to ldap. 3171 <p>Added support for union in _adodb_getcount, adodb-lib.inc.php for postgres and oci8. 3172 <p>rs2html() did not work with null dates properly. 3173 <p>PHP 4.4 reference return fixes. 3174 3175 <p><a name="4.63"></a><b>4.63 18 May 2005</b> 3176 <p>Added $nrows<0 check to mysqli's SelectLimit(). 3177 <p>Added OptimizeTable() and OptimizeTables() in adodb-perf.inc.php. By Markus Staab. 3178 <p>PostgreSQL inconsistencies fixed. true and false set to TRUE and FALSE, and boolean type in datadict-postgres.inc.php set 3179 to 'L' => 'BOOLEAN'. Thx Kevin Jamieson. 3180 <p>New adodb_session_create_table() function in adodb-session.inc.php. By Markus Staab. 3181 <p>Added null check to UserTimeStamp(). 3182 <p>Fixed typo in mysqlt driver in adorecordset. Thx to Andy Staudacher. 3183 <p>GenID() had a bug in the raiseErrorFn handling. Fixed. Thx Marcos Pont. 3184 <p>Datadict name quoting now handles ( ) in index fields correctly - they aren't part of the index field. 3185 <p>Performance monitoring: (1) oci8 Ixora checks moved down; (2) expensive sql changed so that only those sql with 3186 count(*)>1 are shown; (3) changed sql1 field to a length+crc32 checksum - this breaks backward compat. 3187 <p>We remap firebird15 to firebird in data dictionary. 3188 3189 <p><a name="4.62"></a><b>4.62 2 Apr 2005</b> 3190 <p>Added 'w' (dow as 0-6 or 1-7) and 'l' (dow as string) for SQLDate for oci8, postgres and mysql. 3191 <p>Rolled back MetaType() changes for mysqli done in prev version. 3192 <p>Datadict change by chris, cblin#tennaxia.com data mappings from: 3193 <pre> 3194 oci8: X->varchar(4000) XL->CLOB 3195 mssql: X->XL->TEXT 3196 mysql: X->XL->LONGTEXT 3197 fbird: X->XL->varchar(4000) 3198 </pre> 3199 <p>to: 3200 <pre> 3201 oci8: X->varchar(4000) XL->CLOB 3202 mssql: X->VARCHAR(4000) XL->TEXT 3203 mysql: X->TEXT XL->LONGTEXT 3204 fbird: X->VARCHAR(4000) XL->VARCHAR(32000) 3205 </pre> 3206 <p>Added $connection->disableBlobs to postgresql to improve performance when no bytea is used (2-5% improvement). 3207 <p>Removed all HTTP_* vars. 3208 <p>Added $rs->tableName to be set before calling AutoExecute(). 3209 <p>Alex Rootoff rootoff#pisem.net contributed ukrainian language file. 3210 <p>Added new mysql_option() support using $conn->optionFlags array. 3211 <p>Added support for ldap_set_option() using the $LDAP_CONNECT_OPTIONS global variable. Contributed by Josh Eldridge. 3212 <p>Added LDAP_* constant definitions to ldap. 3213 <p>Added support for boolean bind variables. We use $conn->false and $conn->true to hold values to set false/true to. 3214 <p>We now do not close the session connection in adodb-session.inc.php as other objects could be using this connection. 3215 <p>We now strip off \0 at end of Ixora SQL strings in $perf->tohtml() for oci8. 3216 <p><a name="4.61"></a><b>4.61 23 Feb 2005</b> 3217 <p>MySQLi added support for mysqli_connect_errno() and mysqli_connect_error(). 3218 <p>Massive improvements to alpha PDO driver. 3219 <p>Quote string bind parameters logged by performance monitor for easy type checking. Thx Jason Judge. 3220 <p>Added support for $role when connecting with Interbase/firebird. 3221 <p>Added support for enum recognition in MetaColumns() mysql and mysqli. Thx Amedeo Petrella. 3222 <p>The sybase_ase driver contributed by Interakt Online. Thx Cristian Marin cristic#interaktonline.com. 3223 <p>Removed not_null, has_default, and default_value from ADOFieldObject. 3224 <p>Sessions code, fixed quoting of keys when handling LOBs in session write() function. 3225 <p>Sessions code, added adodb_session_regenerate_id(), to reduce risk of session hijacking by changing session cookie dynamically. Thx Joe Li. 3226 <p>Perf monitor, polling for CPU did not work for PHP 4.3.10 and 5.0.0-5.0.3 due to PHP bugs, so we special case these versions. 3227 <p>Postgresql, UpdateBlob() added code to handle type==CLOB. 3228 <p><a name="4.60"></a><b>4.60 24 Jan 2005</b> 3229 <p>Implemented PEAR DB's autoExecute(). Simplified design because I don't like using constants when 3230 strings work fine. 3231 <p>_rs2serialize will now update $rs->sql and $rs->oldProvider. 3232 <p>Added autoExecute(). 3233 <p>Added support for postgres8 driver. Currently just remapped to postgres7 driver. 3234 <p>Changed oci8 _query(), so that OCIBindByName() sets the length to -1 if element size is > 4000. This provides better support 3235 for LONGs. 3236 <p>Added SetDateLocale() support for netherlands (Nl). 3237 <p>Spelling error in pivot code ($iff should be $iif). 3238 </p><p>mysql insert_id() did not work with mysql 3.x. Fixed. 3239 </p><p>"\r\n" not converted to spaces correctly in exporting data. Fixed. 3240 </p><p>_nconnect() in mysqli did not return value correctly. Fixed. 3241 </p><p>Arne Eckmann contributed danish language file. 3242 </p><p>Added clone() support to FetchObject() for PHP5.<br> 3243 </p> 3244 <p>Removed SQL_CUR_USE_ODBC from odbc_mssql.<br> 3245 </p> 3246 <p><a name="4.55"></a><b>4.55 5 Jan 2005</b> 3247 </p><p>Found bug in Execute() with bind params for db's that do not support binding natively. 3248 </p><p>DropSequence() now correctly uses default parameter. 3249 </p><p>Now Execute() ignores locale for floats, so 1.23 is NEVER converted to 1,23. 3250 </p><p>SetFetchMode() not properly saved in adodb-perf, suspicious sql and expensive sql. Fixed. 3251 </p><p>Added INET to postgresql metatypes. Thx motzel. 3252 </p><p>Allow oracle hints to work when counting with _adodb_getcount in adodb-lib.inc.php. Thx Chris Wrye. 3253 </p><p>Changed mysql insert_id() to use SELECT LAST_INSERT_ID(). 3254 </p><p>If alter col in datadict does not modify col type/size of actual 3255 col, then it is removed from alter col code. By Mark Newham. Not 3256 perfect as MetaType() !== ActualType(). 3257 </p><p>Added handling of view fields in metacolumns() for postgresql. Thx Renato De Giovanni. 3258 </p><p>Added to informix MetaPrimaryKeys and MetaColumns fixes for null bit. Thx to Cecilio Albero. 3259 </p><p>Removed obsolete connection_timeout() from perf code. 3260 </p><p>Added support for arrayClass in adodb-csv.inc.php. 3261 </p><p>RSFilter now accepts methods of the form $array($obj, 'methodname'). Thx to blake#near-time.com. 3262 </p><p>Changed CacheFlush to $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/'; 3263 </p><p>For better cursor concurrency, added code to free ref cursors in 3264 oci8 when $rs->Close() is called. Note that CLose() is called 3265 internally by the Get* functions too. 3266 </p><p>Added IIF support for access when pivoting. Thx Volodia Krupach. 3267 </p><p>Added mssql datadict support for timestamp. Thx Alexios. 3268 </p><p>Informix pager fix. By Mario Ramirez. 3269 </p><p>ADODB_TABLE_REGEX now includes ':'. By Mario Ramirez. 3270 </p><p>Mark Newnham contributed MetaIndexes for oci8 and db2. 3271 </p><p><a name="4.54"></a><b>4.54 5 Nov 2004</b> 3272 </p><p> 3273 Now you can set $db->charSet = ?? before doing a Connect() in oci8. 3274 </p><p> 3275 Added adodbFetchMode to sqlite. 3276 </p><p> 3277 Perf code, added a string typecast to substr in adodb_log_sql(). 3278 </p><p> 3279 Postgres: Changed BlobDecode() to use po_loread, added new $maxblobsize parameter, and now it returns the blob instead 3280 of sending it to stdout - make sure to mention that as a compat warning. 3281 Also added $db->IsOID($oid) function; uses a heuristic, not guaranteed to work 100%. 3282 </p><p> 3283 Contributed arabic language file by "El-Shamaa, Khaled" k.el-shamaa#cgiar.org 3284 </p><p> 3285 PHP5 exceptions did not handle @ protocol properly. Fixed. 3286 </p><p> 3287 Added ifnull handling for postgresql (using coalesce). 3288 </p><p> 3289 Added metatables() support for Postgresql 8.0 (no longer uses pg_% dictionary tables). 3290 </p><p> 3291 Improved Sybase ErrorMsg() function. By Gaetano Giunta. 3292 </p><p> 3293 Improved oci8 SelectLimit() to use Prepare(). By Cristiano Duarte. 3294 </p><p> 3295 Type-cast $row parameter in ifx_fetch_row() to int. Thx stefan bodgan. 3296 </p><p>Ralf becker contributed improvements in postgresql, sapdb, mysql data dictionary handling:<br> 3297 - MySql and Postgres MetaType was reporting every int column which was 3298 part of a primary key and unique as serial<br> 3299 - Postgres was not reporting the scale of decimal types<br> 3300 - MaxDB was padding the defaults of none-string types with spaces<br> 3301 - MySql now correctly converts enum columns to varchar 3302 </p><p> 3303 Ralf also changed Postgresql datadict:<br> 3304 - you cant add NOT NULL columns in postgres in one go, they need to be 3305 added as NULL and then altered to NOT NULL<br> 3306 - AlterColumnSQL could not change a varchar column with numbers into an 3307 integer column, postgres need an explicit conversation<br> 3308 - a re-created sequence was not set to the correct value, if the name 3309 was the old name (no implicit sequence), now always the new name of the 3310 implicit sequence is used<br> 3311 </p><p>Sergio Strampelli added extra $intoken check to Lens_ParseArgs() in datadict code. 3312 </p><p><a name="4.53"></a><b>4.53 28 Sept 2004</b> 3313 </p><p>FetchMode cached in recordset is sometimes mapped to native db fetchMode. Normally this does not matter, 3314 but when using cached recordsets, we need to switch back to using adodb fetchmode. So we cache this 3315 in $rs->adodbFetchMode if it differs from the db's fetchMode. 3316 </p><p>For informix we now set canSeek = false driver because stefan bodgan tells me that seeking doesn't work. 3317 </p><p>SetDateLocale() never worked till now ;-) Thx david#tomato.it 3318 </p><p>Set $_bindInputArray = true in sapdb driver. Required for clob support. 3319 </p><p>Fixed some PEAR::DB emulation issues with isError() and isWarning. Thx to Gert-Rainer Bitterlich. 3320 </p><p>Empty() used in getupdatesql without strlen() check. Fixed.</p> 3321 <p>Added unsigned detection to mysql and mysqli drivers. Thx to dan cech. 3322 </p><p>Added hungarian language file. Thx to Halászvári Gábor. 3323 </p><p>Improved fieldname-type formatting of datadict SQL generated (adding $widespacing parameter to _GenField). 3324 </p><p>Datadict oci8 DROP CONSTRAINTS misspelt. Fixed. Thx Mark Newnham. 3325 </p><p>Changed odbtp to dynamically change databaseType based on connection, eg. from 'odbtp' to 'odbtp_mssql' when connecting 3326 to mssql database. 3327 </p><p>In datadict, MySQL I4 was wrongly mapped to MEDIUMINT, which is actually I3. Fixed. 3328 </p><p>Fixed mysqli MetaType() recognition. Mysqli returns numeric types unlike mysql extension. Thx Francesco Riosa. 3329 </p><p>VFP odbc driver curmode set wrongly, causing problems with memo fields. Fixed. 3330 </p><p>Odbc driver did not recognize odbc version 2 driver date types properly. Fixed. Thx Bostjan. 3331 </p><p>ChangeTableSQL() fixes to datadict-db2.inc.php by Mark Newnham. 3332 </p><p>Perf monitoring with odbc improved. Now we try in perf code to manually set the sysTimeStamp using date() if sysTimeStamp 3333 is empty. 3334 </p><p>All ADO errors are thrown as exceptions in PHP5. 3335 So we added exception handling to ado in PHP5 by creating new adodb-ado5.inc.php driver. 3336 </p><p>Added IsConnected(). Returns true if connection object connected. By Luca.Gioppo. 3337 </p><p>"Ralf Becker" 3338 RalfBecker#digitalROCK.de contributed new sapdb data-dictionary driver 3339 and a large patch that implements field and table renaming for oracle, 3340 mssql, postgresql, mysql and sapdb. See the new RenameTableSQL() and 3341 RenameColumnSQL() functions. 3342 </p><p>We now check ExecuteCursor to see if PrepareSP was initially called. 3343 </p><p>Changed oci8 datadict to use MODIFY for $dd->alterCol. Thx Mark Newnham. 3344 </p><p><a name="4.52"></a><b>4.52 10 Aug 2004</b> 3345 </p><p>Bug found in Replace() when performance logging enabled, introduced in ADOdb 4.50. Fixed. 3346 </p><p>Replace() checks update stmt. If update stmt fails, we now return immediately. Thx to alex. 3347 </p><p>Added support for $ADODB_FORCE_TYPE in GetUpdateSQL/GetInsertSQL. Thx to niko. 3348 </p><p>Added ADODB_ASSOC_CASE support to postgres/postgres7 driver. 3349 </p><p>Support for DECLARE stmt in oci8. Thx Lochbrunner. 3350 </p><p><a name="4.51"></a><b>4.51 29 July 2004</b> 3351 </p><p>Added adodb-xmlschema 1.0.2. Thx dan and richard. 3352 </p><p>Added new adorecordset_ext_* classes. If ADOdb extension installed for mysql, mysqlt and oci8 3353 (but not oci8po), we use the superfast ADOdb extension code for movenext. 3354 </p><p>Added schema support to mssql and odbc_mssql MetaPrimaryKeys(). 3355 </p><p>Patched MSSQL driver to support PHP NULL and Boolean values 3356 while binding the input array parameters in the _query() function. By Stephen Farmer. 3357 </p><p>Added support for clob's for mssql, UpdateBlob(). Thx to gfran#directa.com.br 3358 </p><p>Added normalize support for postgresql (true=lowercase table name, or false=case-sensitive table names) 3359 to MetaColumns($table, $normalize=true). 3360 </p><p>PHP5 variant dates in ADO not working. Fixed in adodb-ado.inc.php. 3361 </p><p>Constant ADODB_FORCE_NULLS was not working properly for many releases (for GetUpdateSQL). Fixed. 3362 Also GetUpdateSQL strips off ORDER BY now - thx Elieser Leão. 3363 </p><p>Perf Monitor for oci8 now dynamically highlights optimizer_* params if too high/low. 3364 </p><p>Added dsn support to NewADOConnection/ADONewConnection. 3365 </p><p>Fixed out of page bounds bug in _adodb_pageexecute_all_rows() Thx to "Sergio Strampelli" sergio#rir.it 3366 </p><p>Speedup of movenext for mysql and oci8 drivers. 3367 </p><p>Moved debugging code _adodb_debug_execute() to adodb-lib.inc.php. 3368 </p><p>Fixed postgresql bytea detection bug. See http://phplens.com/lens/lensforum/msgs.php?id=9849. 3369 </p><p>Fixed ibase datetimestamp typo in PHP5. Thx stefan. 3370 </p><p>Removed whitespace at end of odbtp drivers. 3371 </p><p>Added db2 metaprimarykeys fix. 3372 </p><p>Optimizations to MoveNext() for mysql and oci8. Misc speedups to Get* functions. 3373 </p><p><a name="4.50"></a><b>4.50 6 July 2004</b> 3374 </p><p>Bumped it to 4.50 to avoid confusion with PHP 4.3.x series. 3375 </p><p>Added db2 metatables and metacolumns extensions. 3376 </p><p>Added alpha PDO driver. Very buggy, only works with odbc. 3377 </p><p>Tested mysqli. Set poorAffectedRows = true. Cleaned up movenext() and _fetch(). 3378 </p><p>PageExecute does not work properly with php5 (return val not a variable). Reported Dmytro Sychevsky sych#php.com.ua. Fixed. 3379 </p><p>MetaTables() for mysql, $showschema parameter was not backward compatible with older versions of adodb. Fixed. 3380 </p><p>Changed mysql GetOne() to work with mysql 3.23 when using with non-select stmts (e.g. SHOW TABLES). 3381 </p><p>Changed TRIG_ prefix to a variable in datadict-oci8.inc.php. Thx to Luca.Gioppo#csi.it. 3382 </p><p>New to adodb-time code. We allow you to define your own daylights savings function, 3383 adodb_daylight_sv for pre-1970 dates. If the function is defined 3384 (somewhere in an include), then you can correct 3385 for daylights savings. See http://phplens.com/phpeverywhere/node/view/16#daylightsavings 3386 for more info. 3387 </p><p>New sqlitepo driver. This is because assoc mode does not work like other drivers in sqlite. 3388 Namely, when selecting (joining) multiple tables, in assoc mode the table 3389 names are included in the assoc keys in the "sqlite" driver. 3390 In "sqlitepo" driver, the table names are stripped from the returned column names. 3391 When this results in a conflict, the first field get preference. 3392 Contributed by Herman Kuiper herman#ozuzo.net 3393 </p><p>Added $forcenull parameter to GetInsertSQL/GetUpdateSQL. Idea by Marco Aurelio Silva. 3394 </p><p>More XHTML changes for GetMenu. By Jeremy Evans. 3395 </p><p>Fixes some ibase date issues. Thx to stefan bogdan. 3396 </p><p>Improvements to mysqli driver to support $ADODB_COUNTRECS. 3397 </p><p>Fixed adodb-csvlib.inc.php problem when reading stream from socket. We need to poll stream continiously. 3398 </p><p><a name="4.23"></a><b>4.23 16 June 2004</b> 3399 </p><p> 3400 New interbase/firebird fixes thx to Lester Caine. 3401 Driver fixes a problem with getting field names in the result array, and 3402 corrects a couple of data conversions. Also we default to dialect3 for firebird. 3403 Also ibase sysDate property was wrong. Changed to cast as timestamp. 3404 </p><p> 3405 The datadict driver is set up to give quoted tables and fields as this 3406 was the only way round reserved words being used as field names in 3407 TikiWiki. TikiPro is tidying that up, and I hope to be able to produce a 3408 build of THAT which uses what I consider proper UPPERCASE field and 3409 table names. The conversion of TikiWiki to ADOdb helped in that, but 3410 until the database is completely tidied up in TikiPro ... 3411 </p><p>Modified _gencachename() to include fetchmode in name hash. 3412 This means you should clear your cache directory after installing this release as the 3413 cache name algorithm has changed. 3414 </p><p>Now Cache* functions work in safe 3415 mode, because we do not create sub-directories in the $ADODB_CACHE_DIR 3416 in safe mode. In non-safe mode we still create sub-directories. Done by 3417 modifying _gencachename(). 3418 </p><p>Added $gmt parameter (true/false) 3419 to UserDate and UserTimeStamp in connection class, to force conversion 3420 of input (in local time) to be converted to UTC/GMT. 3421 </p><p>Mssql datadict did not support INT types properly (no size param allowed). 3422 Added _GetSize() to datadict-mssql.inc.php. 3423 </p><p>For borland_ibase, BeginTrans(), changed:<br> 3424 </p><pre> $this->_transactionID = $this->_connectionID;</pre> 3425 to<br> 3426 <pre> $this->_transactionID = ibase_trans($this->ibasetrans, $this->_connectionID);</pre> 3427 3428 <p>Fixed typo in mysqi_field_seek(). Thx to Sh4dow (sh4dow#php.pl). 3429 </p><p>LogSQL did not work with Firebird/Interbase. Fixed. 3430 </p><p>Postgres: made errorno() handling more consistent. Thx to Michael Jahn, Michael.Jahn#mailbox.tu-dresden.de. 3431 </p><p>Added informix patch to better support metatables, metacolumns by "Cecilio Albero" c-albero#eos-i.com 3432 </p><p>Cyril Malevanov contributed patch to oci8 to support passing of LOB parameters: 3433 </p><pre> $text = 'test test test';<br> $sql = "declare rs clob; begin :rs := lobinout(:sa0); end;";<br> $stmt = $conn -> PrepareSP($sql);<br> $conn -> InParameter($stmt,$text,'sa0', -1, OCI_B_CLOB);<br> $rs = '';<br> $conn -> OutParameter($stmt,$rs,'rs', -1, OCI_B_CLOB);<br> $conn -> Execute($stmt);<br> echo "return = ".$rs."<br>";<br></pre> 3434 As he says, the LOBs limitations are: 3435 <pre> - use OCINewDescriptor before binding<br> - if Param is IN, uses save() before each execute. This is done automatically for you.<br> - if Param is OUT, uses load() after each execute. This is done automatically for you.<br> - when we bind $var as LOB, we create new descriptor and return it as a<br> Bind Result, so if we want to use OUT parameters, we have to store<br> somewhere &$var to load() data from LOB to it.<br> - IN OUT params are not working now (should not be a big problem to fix it)<br> - now mass binding not working too (I've wrote about it before)<br></pre> 3436 <p>Simplified Connect() and PConnect() error handling. 3437 </p><p>When extension not loaded, Connect() and PConnect() will return null. On connect error, the fns will return false. 3438 </p><p>CacheGetArray() added to code. 3439 </p><p>Added Init() to adorecordset_empty(). 3440 </p><p>Changed postgres64 driver, MetaColumns() to not strip off quotes in default value if :: detected (type-casting of default). 3441 </p><p>Added test: if (!defined('ADODB_DIR')) die(). Useful to prevent hackers from detecting file paths. 3442 </p><p>Changed metaTablesSQL to ignore Postgres 7.4 information schemas (sql_*). 3443 </p><p>New polish language file by Grzegorz Pacan 3444 </p><p>Added support for UNION in _adodb_getcount(). 3445 </p><p>Added security check for ADODB_DIR to limit path disclosure issues. Requested by postnuke team. 3446 </p><p>Added better error message support to oracle driver. Thx to Gaetano Giunta. 3447 </p><p>Added showSchema support to mysql. 3448 </p><p>Bind in oci8 did not handle $name=false properly. Fixed. 3449 </p><p>If extension not loaded, Connect(), PConnect(), NConnect() will return null. 3450 </p><p><b>4.22 15 Apr 2004</b> 3451 </p><p>Moved docs to own adodb/docs folder. 3452 </p><p>Fixed session bug when quoting compressed/encrypted data in Replace(). 3453 </p><p>Netezza Driver and LDAP drivers contributed by Josh Eldridge. 3454 </p><p>GetMenu now uses rtrim() on values instead of trim(). 3455 </p><p>Changed MetaColumnNames to return an associative array, keys being the field names in uppercase. 3456 </p><p>Suggested fix to adodb-ado.inc.php affected_rows to support PHP5 variants. Thx to Alexios Fakos. 3457 </p><p>Contributed bulgarian language file by Valentin Sheiretsky valio#valio.eu.org. 3458 </p><p>Contributed romanian language file by stefan bogdan. 3459 </p><p>GetInsertSQL now checks for table name (string) in $rs, and will create a recordset for that 3460 table automatically. Contributed by Walt Boring. Also added OCI_B_BLOB in bind on Walt's request - hope 3461 it doesn't break anything :-) 3462 </p><p>Some minor postgres speedups in _initrs(). 3463 </p><p> ChangeTableSQL checks now if MetaColumns returns empty. Thx Jason Judge. 3464 </p><p>Added ADOConnection::Time(), returns current database time in unix timestamp format, or false. 3465 </p><p><b>4.21 20 Mar 2004</b> 3466 </p><p>We no longer in SelectLimit for VFP driver add SELECT TOP X unless an ORDER BY exists. 3467 </p><p>Pim Koeman contributed dutch language file adodb-nl.inc.php. 3468 </p><p>Rick Hickerson added CLOB support to db2 datadict. 3469 </p><p>Added odbtp driver. Thx to "stefan bogdan" sbogdan#rsb.ro. 3470 </p><p>Changed PrepareSP() 2nd parameter, $cursor, to default to true (formerly false). Fixes oci8 backward 3471 compat problems with OUT params. 3472 </p><p>Fixed month calculation error in adodb-time.inc.php. 2102-June-01 appeared as 2102-May-32. 3473 </p><p>Updated PHP5 RC1 iterator support. API changed, hasMore() renamed to valid(). 3474 </p><p>Changed internal format of serialized cache recordsets. As we store a version number, this should be 3475 backward compatible. 3476 </p><p>Error handling when driver file not found was flawed in ADOLoadCode(). Fixed. 3477 </p><p><b>4.20 27 Feb 2004</b> 3478 </p><p>Updated to AXMLS 1.01. 3479 </p><p>MetaForeignKeys for postgres7 modified by Edward Jaramilla, works on pg 7.4. 3480 </p><p>Now numbers accepts function calls or sequences for GetInsertSQL/GetUpdateSQL numeric fields. 3481 </p><p>Changed quotes of 'delete from $perf_table' to "". Thx Kehui (webmaster#kehui.net) 3482 </p><p>Added ServerInfo() for ifx, and putenv trim fix. Thx Fernando Ortiz. 3483 </p><p>Added addq(), which is analogous to addslashes(). 3484 </p><p>Tested with php5b4. Fix some php5 compat problems with exceptions and sybase. 3485 </p><p>Carl-Christian Salvesen added patch to mssql _query to support binds greater than 4000 chars. 3486 </p><p>Mike suggested patch to PHP5 exception handler. $errno must be numeric. 3487 </p><p>Added double quotes (") to ADODB_TABLE_REGEX. 3488 </p><p>For oci8, Prepare(...,$cursor), 3489 $cursor's meaning was accidentally inverted in 4.11. This causes 3490 problems with ExecuteCursor() too, which calls Prepare() internally. 3491 Thx to William Lovaton. 3492 </p><p>Now dateHasTime property in connection object renamed to datetime for consistency. This could break bc. 3493 </p><p>Csongor Halmai reports that db2 SelectLimit with input array is not working. Fixed.. 3494 </p><p><b>4.11 27 Jan 2004</b> 3495 </p><p>Csongor Halmai reports db2 binding not working. Reverted back to emulated binding. 3496 </p><p>Dan Cech modifies datadict code. Adds support for DropIndex. Minor cleanups. 3497 </p><p>Table misspelt in perf-oci8.inc.php. Changed v$conn_cache_advice to v$db_cache_advice. Reported by Steve W. 3498 </p><p>UserTimeStamp and DBTimeStamp did not handle YYYYMMDDHHMMSS format properly. Reported by Mike Muir. Fixed. 3499 </p><p>Changed oci8 Prepare(). Does not auto-allocate OCINewCursor automatically, unless 2nd param is set to true. 3500 This will break backward compat, if Prepare/Execute is used instead of ExecuteCursor. Reported by Chris Jones. 3501 </p><p>Added InParameter() and OutParameter(). Wrapper functions to Parameter(), but nicer because they 3502 are self-documenting. 3503 </p><p>Added 'R' handling in ActualType() to datadict-mysql.inc.php 3504 </p><p>Added ADOConnection::SerializableRS($rs). Returns a recordset that can be serialized in a session. 3505 </p><p>Added "Run SQL" to performance UI(). 3506 </p><p>Misc spelling corrections in adodb-mysqli.inc.php, adodb-oci8.inc.php and datadict-oci8.inc.php, from Heinz Hombergs. 3507 </p><p>MetaIndexes() for ibase contributed by Heinz Hombergs. 3508 </p><p><b>4.10 12 Jan 2004</b> 3509 </p><p>Dan Cech contributed extensive changes to data dictionary to support name quoting (with `), and drop table/index. 3510 </p><p>Informix added cursorType property. Default remains IFX_SCROLL, but you can change to 0 (non-scrollable cursor) for performance. 3511 </p><p>Added ADODB_View_PrimaryKeys() for returning view primary keys to MetaPrimaryKeys(). 3512 </p><p>Simplified chinese file, adodb-cn.inc.php from cysoft. 3513 </p><p>Added check for ctype_alnum in adodb-datadict.inc.php. Thx to Jason Judge. 3514 </p><p>Added connection parameter to ibase Prepare(). Fix by Daniel Hassan. 3515 </p><p>Added nameQuote for quoting identifiers and names to connection obj. Requested by Jason Judge. Also the 3516 data dictionary parser now detects `field name` and generates column names with spaces correctly. 3517 </p><p>BOOL type not recognised correctly as L. Fixed. 3518 </p><p>Fixed paths in ADODB_DIR for session files, and back-ported it to 4.05 (15 Dec 2003) 3519 </p><p>Added Schema to postgresql MetaTables. Thx to col#gear.hu 3520 </p><p>Empty postgresql recordsets that had blob fields did not set EOF properly. Fixed. 3521 </p><p>CacheSelectLimit internal parameters to SelectLimit were wrong. Thx to Nio. 3522 </p><p>Modified adodb_pr() and adodb_backtrace() to support command-line usage (eg. no html). 3523 </p><p>Fixed some fr and it lang errors. Thx to Gaetano G. 3524 </p><p>Added contrib directory, with adodb rs to xmlrpc convertor by Gaetano G. 3525 </p><p>Fixed array recordset bugs when _skiprow1 is true. Thx to Gaetano G. 3526 </p><p>Fixed pivot table code when count is false. 3527 </p><p> 3528 3529 </p><p><b>4.05 13 Dec 2003 </b> 3530 </p><p>Added MetaIndexes to data-dict code - thx to Dan Cech. 3531 </p><p>Rewritten session code by Ross Smith. Moved code to adodb/session directory. 3532 </p><p>Added function exists check on connecting to most drivers, so we don't crash with the unknown function error. 3533 </p><p>Smart Transactions failed with GenID() when it no seq table has been created because the sql 3534 statement fails. Fix by Mark Newnham. 3535 </p><p>Added $db->length, which holds name of function that returns strlen. 3536 </p><p>Fixed error handling for bad driver in ADONewConnection - passed too few params to error-handler. 3537 </p><p>Datadict did not handle types like 16.0 properly in _GetSize. Fixed. 3538 </p><p>Oci8 driver SelectLimit() bug &= instead of =& used. Thx to Swen Thümmler. 3539 </p><p>Jesse Mullan suggested not flushing outp when output buffering enabled. Due to Apache 2.0 bug. Added. 3540 </p><p>MetaTables/MetaColumns return ref bug with PHP5 fixed in adodb-datadict.inc.php. 3541 </p><p>New mysqli driver contributed by Arjen de Rijke. Based on adodb 3.40 driver. 3542 Then jlim added BeginTrans, CommitTrans, RollbackTrans, IfNull, SQLDate. Also fixed return ref bug. 3543 </p><p>$ADODB_FLUSH added, if true then force flush in debugging outp. Default is false. In earlier 3544 versions, outp defaulted to flush, which is not compat with apache 2.0. 3545 </p><p>Mysql driver's GenID() function did not work when when sql logging is on. Fixed. 3546 </p><p>$ADODB_SESSION_TBL not declared as global var. Not available if adodb-session.inc.php included in function. Fixed. 3547 </p><p>The input array not passed to Execute() in _adodb_getcount(). Fixed. 3548 </p><p><b>4.04 13 Nov 2003 </b> 3549 </p><p>Switched back to foreach - faster than list-each. 3550 </p><p>Fixed bug in ado driver - wiping out $this->fields with date fields. 3551 </p><p>Performance Monitor, View SQL, Explain Plan did not work if strlen($SQL)>max($_GET length). Fixed. 3552 </p><p>Performance monitor, oci8 driver added memory sort ratio. 3553 </p><p>Added random property, returns SQL to generate a floating point number between 0 and 1; 3554 </p><p><b>4.03 6 Nov 2003 </b> 3555 </p><p>The path to adodb-php4.inc.php and adodb-iterators.inc.php was not setup properly. 3556 </p><p>Patched SQLDate in interbase to support hours/mins/secs. Thx to ari kuorikoski. 3557 </p><p>Force autorollback for pgsql persistent connections - 3558 apparently pgsql did not autorollback properly before 4.3.4. See http://bugs.php.net/bug.php?id=25404 3559 </p><p><b>4.02 5 Nov 2003 </b> 3560 </p><p>Some errors in adodb_error_pg() fixed. Thx to Styve. 3561 </p><p>Spurious Insert_ID() error was generated by LogSQL(). Fixed. 3562 </p><p>Insert_ID was interfering with Affected_Rows() and Replace() when LogSQL() enabled. Fixed. 3563 </p><p>More foreach loops optimized with list/each. 3564 </p><p>Null dates not handled properly in ADO driver (it becomes 31 Dec 1969!). 3565 </p><p>Heinz Hombergs contributed patches for mysql MetaColumns - adding scale, made 3566 interbase MetaColumns work with firebird/interbase, and added lang/adodb-de.inc.php. 3567 </p><p>Added INFORMIXSERVER environment variable. 3568 </p><p>Added $ADODB_ANSI_PADDING_OFF for interbase/firebird. 3569 </p><p>PHP 5 beta 2 compat check. Foreach (Iterator) support. Exceptions support. 3570 </p><p><b>4.01 23 Oct 2003 </b> 3571 </p><p>Fixed bug in rs2html(), tohtml.inc.php, that generated blank table cells. 3572 </p><p>Fixed insert_id() incorrectly generated when logsql() enabled. 3573 </p><p>Modified PostgreSQL _fixblobs to use list/each instead of foreach. 3574 </p><p>Informix ErrorNo() implemented correctly. 3575 </p><p>Modified several places to use list/each, including GetRowAssoc(). 3576 </p><p>Added UserTimeStamp() to connection class. 3577 </p><p>Added $ADODB_ANSI_PADDING_OFF for oci8po. 3578 </p><p><b>4.00 20 Oct 2003 </b> 3579 </p><p>Upgraded adodb-xmlschema to 1 Oct 2003 snapshot. 3580 </p><p>Fix to rs2html warning message. Thx to Filo. 3581 </p><p>Fix for odbc_mssql/mssql SQLDate(), hours was wrong. 3582 </p><p>Added MetaColumns and MetaPrimaryKeys for sybase. Thx to Chris Phillipson. 3583 </p><p>Added autoquoting to datadict for MySQL and PostgreSQL. Suggestion by Karsten Dambekalns 3584 </p><p><b>3.94 11 Oct 2003 </b> 3585 </p><p>Create trigger in datadict-oci8.inc.php did not work, because all cr/lf's must be removed. 3586 </p><p>ErrorMsg()/ErrorNo() did not work for many databases when logging enabled. Fixed. 3587 </p><p>Removed global variable $ADODB_LOGSQL as it does not work properly with multiple connections. 3588 </p><p>Added SQLDate support for sybase. Thx to Chris Phillipson 3589 </p><p>Postgresql checking of pgsql resultset resource was incorrect. Fix by Bharat Mediratta bharat#menalto.com. 3590 Same patch applied to _insertid and _affectedrows for adodb-postgres64.inc.php. 3591 </p><p>Added support for NConnect for postgresql. 3592 </p><p>Added Sybase data dict support. Thx to Chris Phillipson 3593 </p><p>Extensive improvements in $perf->UI(), eg. Explain now opens in new window, we show scripts 3594 which call sql, etc. 3595 </p><p>Perf Monitor UI works with magic quotes enabled. 3596 </p><p>rsPrefix was declared twice. Removed. 3597 </p><p>Oci8 stored procedure support, eg. "begin func(); end;" was incorrect in _query. Fixed. 3598 </p><p>Tiraboschi Massimiliano contributed italian language file. 3599 </p><p>Fernando Ortiz, fortiz#lacorona.com.mx, contributed informix performance monitor. 3600 </p><p>Added _varchar (varchar arrays) support for postgresql. Reported by PREVOT Stéphane.<hr /> 3601 <p><strong>0.10 Sept 9 2000</strong> First release 3602 </p><h3><strong>Old change log history moved to <a href="old-changelog.htm">old-changelog.htm</a>. 3603 </strong></h3> 3604 <p> </p> 3605 <p> 3606 </p></body></html>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce ŕ PHPXref 0.7 |
![]() |