PDO::quote

(no version information, might be only in CVS)

PDO::quote --  Quotes a string for use in a query.

Beschreibung

string PDO::quote ( string string [, int parameter_type] )

Warnung

Diese Funktion ist EXPERIMENTELL. Das Verhalten, der Funktionsname und alles Andere was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohne Ankündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion auf eigenes Risiko.

PDO::quote() places quotes around the input string and escapes and single quotes within the input string, using a quoting style appropriate to the underlying driver.

If you're using this function to build SQL, it is recommended that you using prepared statements and bound parameters instead, as it is not only more convenient, but often much faster.

Not all PDO drivers implement this method (notably PDO_ODBC). Consider using prepared statements instead.

Parameter Liste

string

The string to be quoted.

parameter_type

Provides a data type hint for drivers that have alternate quoting styles. The default value is PDO_PARAM_STR.

Rückgabewerte

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

Beispiele

Beispiel 1. Quoting a normal 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";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Unquoted string: Nice
Quoted string: 'Nice'

Beispiel 2. Quoting a dangerous 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";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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

Beispiel 3. Quoting a complex string

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

/* Complex string */
$string = "Co'mpl''ex \"st'\"ring";
print
"Unquoted string: $string\n";
print
"Quoted string: " . $conn->quote($string) . "\n";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Unquoted string: Co'mpl''ex "st'"ring
Quoted string: 'Co''mpl''''ex "st''"ring'

Siehe auch

PDO::prepare()
PDOStatement::execute()

Hosting by: Hurra Communications GmbH
Generated: 2007-01-26 17:57:07