問題描述
我在使用 ODBC 的 PDO 語句時(shí)遇到問題.
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
例如:
我有查詢:
(這不是實(shí)際的查詢,但它適用于示例)
(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();
這會(huì)引發(fā)錯(cuò)誤
COUNT field incorrect or syntax error
問題是,bindParam 只綁定了 :number 的第一次出現(xiàn)......并且再次嘗試綁定它也不起作用.
The thing is, bindParam is only binding the FIRST occurrence of :number ... AND trying to bind it again doesn't work either.
有沒有辦法綁定多個(gè)同名的命名參數(shù)?
Is there a way to bind multiple named params with the same name?
我試圖不使用位置參數(shù)使用 ?代替
I'm trying not to use positional params using the ? instead
推薦答案
理論上你可以打開準(zhǔn)備語句的模擬.
Theoretical you could turn on emulation of prepared statements.
您必須為您希望的每個(gè)值包含一個(gè)唯一的參數(shù)標(biāo)記當(dāng)您調(diào)用 PDOStatement::execute() 時(shí)傳入語句.你不能多次使用同名的命名參數(shù)標(biāo)記準(zhǔn)備好的語句,除非啟用了仿真模式.
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.準(zhǔn)備.php
這篇關(guān)于PHP PDO bindParam/bindValue 多次的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!