MySQL/PDO :: quote(),将单引号放在整数周围 [英] MySQL/PDO::quote(), Putting single quotes around integers

查看:98
本文介绍了MySQL/PDO :: quote(),将单引号放在整数周围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我传递给$pdo->quote($value, $type);的是哪个值/数据类型对,它都始终将其引用为字符串:

It appears no matter what value/data-type pair I pass to $pdo->quote($value, $type);, it always quotes it as a string:

echo $pdo->quote('foo', PDO::PARAM_STR); /* 'foo', as expected */

echo $pdo->quote(42, PDO::PARAM_INT);    /* '42', expected 42 unquoted */

我只是想知道这是否是预期的功能.我使用准备好的语句执行实际的查询,但是我试图 fetch create 创建最终的查询字符串(用于调试/缓存),并手动构建它们.

I'm just curious to know if this is the intended functionality. I use prepared statements for actual query execution, but I'm trying to fetch create the final querystrings (for debugging/caching), and am constructing them manually.

正如标题所示,这是使用MySQL驱动程序创建$pdo的时间.由于不可用,我没有尝试过其他人.

As the title suggests, this is when $pdo is created using the MySQL driver. I haven't tried others due to unavailability.

推荐答案

SQLite Firebird 驱动程序均引用为 PostgreSQL驱动程序仅区分二进制大对象和所有其他人. ODBC驱动程序未实现引号.您期望的(缺乏)行为是报告为错误,并以假",表示行为是设计使然.说明以下内容时,该文档可能会引起误导:

The Oracle, SQLite, MSSQL, and Firebird drivers all quote as the PDO MySQL driver, ignoring the param type. The PostgreSQL driver only distinguishes between binary large objects and all others. ODBC Driver doesn't implement a quoter. The (lack of) behavior you expect was reported as a bug and closed as "bogus", meaning the behavior is by design. Perhaps the documentation is misleading when it states:

PDO :: quote()将引号括在输入字符串周围(如果需要)

PDO::quote() places quotes around the input string (if required)

尽管这表明可能存在 实例,但这些实例的值没有被引号引起来,但并未表示肯定存在,也未说明这​​些实例是什么.如果您认为这是文档中的错误,则最好提交一个错误报告.

While this suggests there may be instances when values aren't surrounded by quotes, it doesn't say there definitely are, nor does it state what those instances are. If you feel this is a bug in documentation, submit a bug report, preferably with a fix.

这篇关于MySQL/PDO :: quote(),将单引号放在整数周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆