function DB_common::setOption in Flickr API 5
Sets run-time configuration options for PEAR DB
Options, their data types, default values and description: <ul> <li> <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp> <br />should results be freed automatically when there are no more rows? </li><li> <var>result_buffering</var> <kbd>integer</kbd> = <samp>500</samp> <br />how many rows of the result set should be buffered? <br />In mysql: mysql_unbuffered_query() is used instead of mysql_query() if this value is 0. (Release 1.7.0) <br />In oci8: this value is passed to ocisetprefetch(). (Release 1.7.0) </li><li> <var>debug</var> <kbd>integer</kbd> = <samp>0</samp> <br />debug level </li><li> <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp> <br />should the connection be persistent? </li><li> <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp> <br />portability mode constant (see below) </li><li> <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp> <br />the sprintf() format string used on sequence names. This format is applied to sequence names passed to createSequence(), nextID() and dropSequence(). </li><li> <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp> <br />use ssl to connect? </li> </ul>
-----------------------------------------
PORTABILITY MODES
These modes are bitwised, so they can be combined using <kbd>|</kbd> and removed using <kbd>^</kbd>. See the examples section below on how to do this.
<samp>DB_PORTABILITY_NONE</samp> turn off all portability features
This mode gets automatically turned on if the deprecated <var>optimize</var> option gets set to <samp>performance</samp>.
<samp>DB_PORTABILITY_LOWERCASE</samp> convert names of tables and fields to lower case when using <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd>
This mode gets automatically turned on in the following databases if the deprecated option <var>optimize</var> gets set to <samp>portability</samp>: + oci8
<samp>DB_PORTABILITY_RTRIM</samp> right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd>
<samp>DB_PORTABILITY_DELETE_COUNT</samp> force reporting the number of rows deleted
Some DBMS's don't count the number of rows deleted when performing simple <kbd>DELETE FROM tablename</kbd> queries. This portability mode tricks such DBMS's into telling the count by adding <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries.
This mode gets automatically turned on in the following databases if the deprecated option <var>optimize</var> gets set to <samp>portability</samp>: + fbsql + mysql + mysqli + sqlite
<samp>DB_PORTABILITY_NUMROWS</samp> enable hack that makes <kbd>numRows()</kbd> work in Oracle
This mode gets automatically turned on in the following databases if the deprecated option <var>optimize</var> gets set to <samp>portability</samp>: + oci8
<samp>DB_PORTABILITY_ERRORS</samp> makes certain error messages in certain drivers compatible with those from other DBMS's
+ mysql, mysqli: change unique/primary key constraints DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
+ odbc(access): MS's ODBC driver reports 'no such field' as code 07001, which means 'too few parameters.' When this option is on that code gets mapped to DB_ERROR_NOSUCHFIELD. DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD
<samp>DB_PORTABILITY_NULL_TO_EMPTY</samp> convert null values to empty strings in data output by get*() and fetch*(). Needed because Oracle considers empty strings to be null, while most other DBMS's know the difference between empty and null.
<samp>DB_PORTABILITY_ALL</samp> turn on all portability features
-----------------------------------------
Example 1. Simple setOption() example <code> $db->setOption('autofree', true); </code>
Example 2. Portability for lowercasing and trimming <code> $db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM); </code>
Example 3. All portability options except trimming <code> $db->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM); </code>
Parameters
string $option option name:
mixed $value value for the option:
Return value
int DB_OK on success. A DB_Error object on failure.
See also
DB_common::$options
File
- phpFlickr/
PEAR/ DB/ common.php, line 648
Class
- DB_common
- DB_common is the base class from which each database driver class extends
Code
function setOption($option, $value) {
if (isset($this->options[$option])) {
$this->options[$option] = $value;
/*
* Backwards compatibility check for the deprecated 'optimize'
* option. Done here in case settings change after connecting.
*/
if ($option == 'optimize') {
if ($value == 'portability') {
switch ($this->phptype) {
case 'oci8':
$this->options['portability'] = DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_NUMROWS;
break;
case 'fbsql':
case 'mysql':
case 'mysqli':
case 'sqlite':
$this->options['portability'] = DB_PORTABILITY_DELETE_COUNT;
break;
}
}
else {
$this->options['portability'] = DB_PORTABILITY_NONE;
}
}
return DB_OK;
}
return $this
->raiseError("unknown option {$option}");
}