PHP PDO bindParam/bindValue多次 [英] PHP PDO bindParam/bindValue Multiple times

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

问题描述

我在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中,我有:

in my php i have:

$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. prepare.php

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

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