Документация PHP


PDO::query

PDO::rollBack

PDO

PHP Manual


PDO::quote

(PHP 5 >= 5.1.0, PECL pdo:0.2.1-1.0.3)

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

Описание

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

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

If you are using this function to build SQL statements, you are strongly recommended to use PDO::prepare() to prepare SQL statements with bound parameters instead of using PDO::quote() to interpolate user input into a SQL statement. Prepared statements with bound parameters are not only more portable, more convenient, immune to SQL injection, but are often much faster to execute than interpolated queries, as both the server and client side can cache a compiled form of the query.

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

Список параметров

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.

Возвращаемые значения

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.

Примеры

Пример #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";
?>

Результат выполнения данного примера:

Unquoted string: Nice
Quoted string: 'Nice'

Пример #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";
?>

Результат выполнения данного примера:

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

Пример #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";
?>

Результат выполнения данного примера:

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

Смотрите также


PDO::query

PDO::rollBack

PDO

PHP Manual

SAPE все усложнил?

MainLink - простая и прибыльная продажа ссылок!

Последние поступления:

Размещена 10 августа 2020 года

Я по ТВ видел, что через 10 лет мы будем жить лучше, чем в Германии...
Я не понял, что это они с Германией сделать хотят?!

читать далее…

ТехЗадание на Землю

Размещена 14 марта 2018 года

Пpоект Genesis (из коpпоpативной пеpеписки)

читать далее…

Шпаргалка по работе с Vim

Размещена 05 декабря 2017 года

Vim довольно мощный редактор, но работа с ним не всегда наглядна.
Например если нужно отредактировать какой-то файл например при помощи crontab, без знания специфики работы с viv никак.

читать далее…

Ошибка: Error: Cannot find a valid baseurl for repo

Размещена 13 сентабря 2017 года

Если возникает ошибка на centos 5 вида
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/

читать далее…

Linux Optimization

Размещена 30 июля 2012 года

Prelink

читать далее…