PDO::quote

PHP 教程 · 2019-01-28 18:14:49

PDO::quote — 为SQL语句中的字符串添加引号。(PHP 5 >= 5.1.0, PECL pdo >= 0.2.1)

说明

语法

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

PDO::quote() 为SQL语句中的字符串添加引号或者转义特殊字符串。

参数

string
要添加引号的字符串。

parameter_type
为驱动程序提供数据类型。

返回值

返回一个带引号的字符串,理论上可以安全的传递到SQL语句中并执行。如果该驱动程序不支持则返回FALSE。

实例

为普通字符串添加引号

<?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'

转义特殊字符串

<?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'

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Object-Oriented Design Heuristics

Object-Oriented Design Heuristics

Arthur J. Riel / Addison-Wesley Professional / 1996-05-10 / USD 64.99

Product Description Here is the first object-oriented development book to provide specific experience-based guidelines to help developers make the right design decisions. This book offers the next ......一起来看看 《Object-Oriented Design Heuristics》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具