Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用通用ODBC驱动程序的占位符_Php_Sql_Odbc_Insert Update_Placeholder - Fatal编程技术网

Php 使用通用ODBC驱动程序的占位符

Php 使用通用ODBC驱动程序的占位符,php,sql,odbc,insert-update,placeholder,Php,Sql,Odbc,Insert Update,Placeholder,目前,我正在用提交的表格来解释单引号和其他垃圾 $form_field_value= str_replace("'", "''", stripslashes($form_field_value)); 使用以下方法准备插入值: $insert_sql = "insert into table (field) values ('".$form_field_value."')"; odbc_exec($conn, $insert_sql); 基本上,我想为这些insert/update语句使

目前,我正在用提交的表格来解释单引号和其他垃圾

 $form_field_value= str_replace("'", "''", stripslashes($form_field_value));
使用以下方法准备插入值:

 $insert_sql = "insert into table (field) values ('".$form_field_value."')";
 odbc_exec($conn, $insert_sql);
基本上,我想为这些insert/update语句使用占位符

我尝试将$par1和$par2定义为文本,然后执行这个

$insert_sql = "insert into table (field,txt) values (?,?)";
odbc_exec($conn, $insert_sql, $par1, $par2);
它失败了,并给了我以下错误:

警告:odbc_exec[function.odbc exec]:SQL错误:[Microsoft][odbc SQL Server驱动程序]计数字段不正确或语法错误,test.php第10行的SQLExecDirect中的SQL状态为07001

第10行是exec语句

我找不到此odbc驱动程序中使用占位符的语法。有什么建议吗

$conn连接变量工作正常

编辑:

最后一次尝试仍然失败-odbc_execute是一个未定义的函数。我必须使用odbc_exec

$par1="eggs";
$par2="milk";

$insert_crs = "insert into table (field,txt) values (?,?)";
$stmt = odbc_prepare($conn, $insert_sql); 

odbc_exec($stmt, array($par1, $par2));
根据,您应该准备然后执行SQL语句,并且应该为dobc_execute的第三个参数提供一个新数组:

<?php $a = 1; $b = 2; $c = 3; $stmt = odbc_prepare($conn, 'CALL myproc(?,?,?)'); $success = odbc_execute($stmt, array($a, $b, $c)); ?> 这意味着您的代码应该如下所示:

$insert_sql = "insert into table (field,txt) values (?,?)"; // the following line is new, compared to your code $stmt = odbc_prepare($conn, $insert_sql); // note that the following line wraps $par1 and $par2 with array() // struck out version was incorrect - copy/paste error :( odbc_exec($stmt, $insert_sql, array($par1, $par2)); odbc_execute($stmt, array($par1, $par2));
谢谢是的,我在浏览那个网站,看到odbc_执行而不是exec时结束了浏览。。。。现在就试不好。。。我试过exec和EXECE。。。我想应该是这样的你能把你修改过的密码贴出来吗?你仍然得到完全相同的错误吗?而且,如果你复制/粘贴了我的代码,我犯了一个错误,我自己-立即更正…啊-明白了。让我想知道是否缺少库,或者我正在查看的文档是否与您使用的PHP版本不同。。。不幸的是,我对PHP非常陌生,所以我不确定该问什么问题。。。希望其他人能提供更好的信息。