Easy Tutorial
❮ Func Ftp Close Php Is_Resource Function ❯

PDO::quote

PHP PDO Reference Manual

PDO::quote — Adds quotes to a string for use in a 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 a string or escapes special characters for use in a SQL statement.


Parameters

string

parameter_type


Return Value

Returns a quoted string that is theoretically safe to pass into an SQL statement and execute. Returns FALSE if the driver does not support quoting.


Examples

Quoting a Simple String

<?php
$conn = new PDO('sqlite:/home/lynn/music.sql3');

/* Simple string */
$string = 'Nice';
print "Unquoted string: $string\n";
print "Quoted string: " . $conn->quote($string) . "\n";
?>

The above will output:

Unquoted string: Nice
Quoted string: 'Nice'

Escaping a Special String

<?php
$conn = new PDO('sqlite:/home/lynn/music.sql3');

/* Dangerous string */
$string = 'Naughty \' string';
print "Unquoted string: $string\n";
print "Quoted string:" . $conn->quote($string) . "\n";
?>

This example will output:

Unquoted string: Naughty ' string
Quoted string: 'Naughty '' string'

PHP PDO Reference Manual

❮ Func Ftp Close Php Is_Resource Function ❯