我目前正在使用一个完全适用于MySQL的PDO类。但是当谈到MSSQL时,当我尝试通过bindValue()
函数插入数据时出现错误。
我正在使用此方法进行数据绑定:
bindValue(":param",$value)
$counter = 0;
foreach($fields as $cols)
{
$fieldBind[$counter] = ":".$cols;
$new_f = $new_f ."". $cols;
$counter ++;
if($counter!=count($fields))
{
$new_f = $new_f.",";
}
}
output : (
[0] => :field1
[1] => :field2
[2] => :field3
)
$counter2 = 0;
foreach($data as $cols)
{
$dataBind[$counter2] = $cols;
$new_d = $new_d."'".$cols."'";
$counter2 ++;
if($counter2!=count($data))
{
$new_d = $new_d.",";
}
}
output : ( [0] => value1 [1] => value2 [2] => value3 )
query
功能parent::query("INSERT INTO $table($new_f) VALUES($new_d)");
for($i=0;$i<count($data);$i++){
parent::bind($fieldBind[$i],$dataBind[$i]);
}
查询如下所示:
INSERT INTO table(field1,field2,field3) values(':value1',':value2',':value3')
try {
parent::execute();
return parent::rowCount();
}
catch(PDOException $e) {
echo $e->getMessage();
}
这种方法在MySQL上完美运行,但是当我尝试在SQL Server上执行此方法时,我收到此错误:
SQLSTATE [IMSSP]:尝试绑定参数编号0. SQL Server最多支持2100个参数。
答案 0 :(得分:0)
尝试删除撇号&#39;
来自:
INSERT INTO table(field1,field2,field3) values(':value1',':value2',':value3')
以下内容:
INSERT INTO table(field1,field2,field3) values(:value1,:value2,:value3)