function DB_common::quoteSmart in Flickr API 5
Formats input so it can be safely used in a query
The output depends on the PHP data type of input and the database type being used.
@since Method available since Release 1.6.0
Parameters
mixed $in the data to be formatted:
Return value
mixed the formatted data. The format depends on the input's PHP type: <ul> <li> <kbd>input</kbd> -> <samp>returns</samp> </li> <li> <kbd>null</kbd> -> the string <samp>NULL</samp> </li> <li> <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number </li> <li> <kbd>bool</kbd> -> output depends on the driver in use Most drivers return integers: <samp>1</samp> if <kbd>true</kbd> or <samp>0</samp> if <kbd>false</kbd>. Some return strings: <samp>TRUE</samp> if <kbd>true</kbd> or <samp>FALSE</samp> if <kbd>false</kbd>. Finally one returns strings: <samp>T</samp> if <kbd>true</kbd> or <samp>F</samp> if <kbd>false</kbd>. Here is a list of each DBMS, the values returned and the suggested column type: <ul> <li> <kbd>dbase</kbd> -> <samp>T/F</samp> (<kbd>Logical</kbd>) </li> <li> <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp> (<kbd>BOOLEAN</kbd>) </li> <li> <kbd>ibase</kbd> -> <samp>1/0</samp> (<kbd>SMALLINT</kbd>) [1] </li> <li> <kbd>ifx</kbd> -> <samp>1/0</samp> (<kbd>SMALLINT</kbd>) [1] </li> <li> <kbd>msql</kbd> -> <samp>1/0</samp> (<kbd>INTEGER</kbd>) </li> <li> <kbd>mssql</kbd> -> <samp>1/0</samp> (<kbd>BIT</kbd>) </li> <li> <kbd>mysql</kbd> -> <samp>1/0</samp> (<kbd>TINYINT(1)</kbd>) </li> <li> <kbd>mysqli</kbd> -> <samp>1/0</samp> (<kbd>TINYINT(1)</kbd>) </li> <li> <kbd>oci8</kbd> -> <samp>1/0</samp> (<kbd>NUMBER(1)</kbd>) </li> <li> <kbd>odbc</kbd> -> <samp>1/0</samp> (<kbd>SMALLINT</kbd>) [1] </li> <li> <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp> (<kbd>BOOLEAN</kbd>) </li> <li> <kbd>sqlite</kbd> -> <samp>1/0</samp> (<kbd>INTEGER</kbd>) </li> <li> <kbd>sybase</kbd> -> <samp>1/0</samp> (<kbd>TINYINT(1)</kbd>) </li> </ul> [1] Accommodate the lowest common denominator because not all versions of have <kbd>BOOLEAN</kbd>. </li> <li> other (including strings and numeric strings) -> the data with single quotes escaped by preceeding single quotes, backslashes are escaped by preceeding backslashes, then the whole string is encapsulated between single quotes </li> </ul>
See also
2 calls to DB_common::quoteSmart()
- DB_common::executeEmulateQuery in phpFlickr/
PEAR/ DB/ common.php - Emulates executing prepared statements if the DBMS not support them
- DB_mysql::quote in phpFlickr/
PEAR/ DB/ mysql.php
1 method overrides DB_common::quoteSmart()
- DB_pgsql::quoteSmart in phpFlickr/
PEAR/ DB/ pgsql.php - Formats input so it can be safely used in a query
File
- phpFlickr/
PEAR/ DB/ common.php, line 424
Class
- DB_common
- DB_common is the base class from which each database driver class extends
Code
function quoteSmart($in) {
if (is_int($in) || is_double($in)) {
return $in;
}
elseif (is_bool($in)) {
return $in ? 1 : 0;
}
elseif (is_null($in)) {
return 'NULL';
}
else {
return "'" . $this
->escapeSimple($in) . "'";
}
}