PHP PDO bindParam/bindValue 多次

PHP PDO bindParam/bindValue Multiple times(PHP PDO bindParam/bindValue 多次)
本文介绍了PHP PDO bindParam/bindValue 多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在使用 ODBC 的 PDO 语句时遇到问题.

I'm having an issue with the PDO statements for ODBC.

我在 Windows Server 2003 和 PHP 5.4.x 中使用 SQL SERVER 7

I'm using SQL SERVER 7 in Windows Server 2003 and PHP 5.4.x

例如:

我有查询:

(这不是实际的查询,但它适用于示例)

(this is not the actual query but it serves right for the example)

$query = SELECT * FROM table WHERE number = :number OR number = :number

在我的 php 中:

$conn = new PDO($connectionString);

$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$statement = $conn->prepare($query);

$statement->bindParam(':number', $someNumber);

$statement->execute();

这会引发错误

COUNT field incorrect or syntax error

问题是,bindParam 只绑定了 :number 的第一次出现......并且再次尝试绑定它也不起作用.

The thing is, bindParam is only binding the FIRST occurrence of :number ... AND trying to bind it again doesn't work either.

有没有办法绑定多个同名的命名参数?

Is there a way to bind multiple named params with the same name?

我试图不使用位置参数使用 ?代替

I'm trying not to use positional params using the ? instead

推荐答案

理论上你可以打开准备语句的模拟.

Theoretical you could turn on emulation of prepared statements.

您必须为您希望的每个值包含一个唯一的参数标记当您调用 PDOStatement::execute() 时传入语句.你不能多次使用同名的命名参数标记准备好的语句,除非启用了仿真模式.

You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.

http://www.php.net/manual/en/pdo.准备.php

这篇关于PHP PDO bindParam/bindValue 多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)