Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PDO::quote

PDO::quote

PHP PDO Reference ManualPHP PDO Reference Manual

PDO::quote - Add quotes to a string in an SQL statement. (PHP 5 >= 5.1.0, PECL pdo >= 0.2.1)


Description

Syntax



public string PDO::quote ( string $string [, int $parameter_type = PDO::PARAM_STR ] )

PDO::quote() adds quotes to or escapes special strings in an SQL statement.


Parameters

string
The string to add quotes to.

parameter_type
Provides the data type for the driver.


Return Value

Returns a quoted string that can theoretically be safely passed into and executed in an SQL statement. If the driver does not support it, returns FALSE.


Example

Add quotes to a normal string



quote($string) . "\n";

?>

The output above is:



Unquoted string: Nice

Quoted string: 'Nice'

Escape special strings



quote($string) . "\n";

?>

The above example will output:



Unquoted string: Naughty ' string

Quoted string: 'Naughty '' string'

PHP PDO Reference ManualPHP PDO Reference Manual