简体   繁体   English

PHP PDOStatement正确的占位符

[英]PHP PDOStatement correct placeholder

I would like to know if the PDOStatement object convert the placeholders according the DBMS . 我想知道PDOStatement对象是否根据DBMS转换placeholders In the examples of the documentation we can see just two kinds of placehoders : :named and with question mark , but there is more, with $ , for example. 在文档的示例中,我们只能看到两种类型的placehoders :named和带question mark ,但还有更多的例如$

bindValue bindValue

bindParam bindParam

Does this example show two options as a matter of taste or appropriateness to DBMS support? 此示例是否根据喜好或对DBMS支持的适用性显示了两个选项?

PDO will translate the syntax it understands to the query/procedural style of various databases. PDO会将其理解的语法转换为各种数据库的查询/过程样式。 This is done by every of the databases' driver. 这是由每个数据库的驱动程序完成的。 While using $ or another placeholder known to a specific database might work (if PDO will just forward the $ it doesn't understand and binding will work), this behavior is undocumented at best, it can stop working at any time. 尽管使用$或特定数据库已知的其他占位符可能有效(如果PDO将只转发它不理解的$且绑定将起作用),则此行为充其量是没有记载的,它可以随时停止工作。 The right way therefore is to use the placeholders PDO understands (the two types documented) and PDO will convert it to the format the DB needs. 因此,正确的方法是使用PDO理解的占位符(记录的两种类型),PDO会将其转换为数据库所需的格式。 This is guaranteed to work and is also portable, if at any time you will switch databases. 如果您随时切换数据库,这可以保证工作并且也可移植。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM