gpt4 book ai didi

php - PHP 中的 ODBC 准备语句

转载 作者:IT王子 更新时间:2023-10-29 00:17:11 26 4
gpt4 key购买 nike

我正尝试在 PHP 中使用 odbc_prepare 和 odbc_execute,如下所示:

$pstmt=odbc_prepare($odb_con,"select * from configured where param_name='?'");
$res=odbc_execute($pstmt,array('version'));
var_dump($res); //bool(true)
$row = odbc_fetch_array($pstmt);
var_dump($row); //bool(false)

第一个 var_dump 返回 true,因此执行成功,但没有返回任何行。 param_name = 'version' 确实存在一行。为什么没有返回行?

为了让事情变得有趣,我使用准备好的插入在 php 中运行了另一个非常简单的示例。

$pstmt=odbc_prepare($odb_con,"insert into tmp1 values(?,'?')");

这一行本身就在数据库中插入了一行!!当然这是错误的?输入的数据是第 1 列 = 空白,第 2 列 = ?

任何有关从哪里开始解决此问题的建议,我们将不胜感激,谢谢。

编辑:这是在 PHP 5.2.8 中

最佳答案

尝试从查询字符串中删除单引号并将它们添加到参数值本身:

$pstmt=odbc_prepare($odb_con,"select * from configured where param_name=?");
$res=odbc_execute($pstmt,array(" 'version'"));
var_dump($res); //bool(true)
$row = odbc_fetch_array($pstmt);
var_dump($row); //bool(false)

参数值开头的单个空格字符非常重要——如果没有空格,它会将变量视为文件路径。

来自 http://www.php.net/manual/en/function.odbc-execute.php :

If you wish to store a string which actually begins and ends with single quotes, you must add a space or other non-single-quote character to the beginning or end of the parameter, which will prevent the parameter from being taken as a file name.

关于php - PHP 中的 ODBC 准备语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5756369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com