PDO::quote讲解
作者:php参考手册 时间:2023-06-03 21:14:37
PDO::quote
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,pdo,quote
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何基于线程池提升request模块效率
2023-06-12 11:13:44
JavaScript对象学习经验整理
2024-04-17 10:09:50
Python SDK实现私服上传下载的示例
2021-11-22 08:14:42
python 存储json数据的操作
2022-10-02 13:14:14
![](https://img.aspxhome.com/file/2023/2/82672_0s.png)
SQL Server 排序函数 ROW_NUMBER和RANK 用法总结
2024-01-20 17:16:36
python数据分析之员工个人信息可视化
2023-08-05 02:32:26
![](https://img.aspxhome.com/file/2023/4/64704_0s.png)
不用加载Include文件也能生成选择列表吗?
2009-10-29 12:30:00
浅谈MySQL中的子查询优化技巧
2024-01-19 12:01:45
[多图] Google Chrome 试用 Tips
2009-12-09 15:49:00
![](https://img.aspxhome.com/file/UploadPic/200912/9/202939796-42s.gif)
Python3 hashlib密码散列算法原理详解
2021-07-06 12:59:55
![](https://img.aspxhome.com/file/2023/9/65869_0s.png)
python 实现网上商城,转账,存取款等功能的信用卡系统
2022-05-26 15:19:36
![](https://img.aspxhome.com/file/2023/0/135060_0s.png)
3行Python代码实现图像照片抠图和换底色的方法
2021-12-11 04:57:35
![](https://img.aspxhome.com/file/2023/1/99611_0s.jpg)
mysql 时间转换函数的使用方法第1/2页
2024-01-21 22:09:40
全透视:CSS Z-index 属性
2009-09-21 12:52:00
![](https://img.aspxhome.com/file/UploadPic/up/2009092113092072.gif)
Python将一个Excel拆分为多个Excel
2021-02-04 06:00:53
![](https://img.aspxhome.com/file/2023/8/125058_0s.jpg)
Python基于Tkinter开发一个爬取B站直播弹幕的工具
2023-06-21 21:53:12
![](https://img.aspxhome.com/file/2023/7/68867_0s.png)
CentOS 7 安装python3.7.1的方法及注意事项
2023-03-10 21:23:53
成功的用户界面的八个特性[译]
2009-04-20 20:36:00
![](https://img.aspxhome.com/file/UploadPic/20094/20/01-77s.jpg)
将数据插入到MySQL表中的详细教程
2024-01-12 22:01:21
详解vue组件开发脚手架
2024-05-09 15:15:34
![](https://img.aspxhome.com/file/2023/4/126514_0s.jpg)