PHP错误oci_bind_by_name():用于绑定的变量无效
我有一个PHP文件,它将从RSS提要中提取数据并将其插入数据库。通常我用一个自定义函数包装每个字段以替换引号,但不再需要它(因为需求发生了变化)。出于某种原因,当我使用下面的逻辑时,我会得到一个错误“error oci_bind_by_name():用于绑定的变量无效”,但如果我像这样包装自定义函数中的每个字段:PHP错误oci_bind_by_name():用于绑定的变量无效,php,rss,Php,Rss,我有一个PHP文件,它将从RSS提要中提取数据并将其插入数据库。通常我用一个自定义函数包装每个字段以替换引号,但不再需要它(因为需求发生了变化)。出于某种原因,当我使用下面的逻辑时,我会得到一个错误“error oci_bind_by_name():用于绑定的变量无效”,但如果我像这样包装自定义函数中的每个字段: $guid = customfunction($item->guid); 它有效,为什么 多谢各位 foreach($rss->channel->item as
$guid = customfunction($item->guid);
它有效,为什么
多谢各位
foreach($rss->channel->item as $item) {
print '<a href="'.$item->link.'">'.$item->title.'</a><br />';
$guid = $item->guid;
$title = $item->title;
$link = $item->link;
$pubDate = $item->pubDate;
$description = $item->description;
$content = $item->content;
$stid = oci_parse($spConn,"INSERT INTO table123
(sku, title, link, pubDate, field1, field2)
VALUES(:guid_bv, :title_bv, :link_bv, :pubDate_bv, :description_bv, :content_bv)");
oci_bind_by_name($stid, ":guid_bv", $guid);
oci_bind_by_name($stid, ":title_bv", $title);
oci_bind_by_name($stid, ":link_bv", $link);
oci_bind_by_name($stid, ":pubDate_bv", $pubDate);
oci_bind_by_name($stid, ":description_bv", $description);
oci_bind_by_name($stid, ":content_bv", $content);
oci_execute($stid);
foreach($rss->channel->item as$item){
打印“
”;
$guid=$item->guid;
$title=$item->title;
$link=$item->link;
$pubDate=$item->pubDate;
$description=$item->description;
$content=$item->content;
$stid=oci_parse($spConn,“插入表123
(sku、标题、链接、发布日期、字段1、字段2)
值(:guid_bv,:title_bv,:link_bv,:publidate_bv,:description_bv,:content_bv)”;
oci_bind_by_name($stid,“:guid_bv”,$guid);
oci_按名称绑定($stid,“:title_bv”,$title);
oci_bind_by_name($stid,“:link_bv”,$link);
oci_按名称绑定($stid,“:pubDate_bv”,$pubDate);
oci_按名称绑定($stid,“:description_bv”,$description);
oci_按名称绑定($stid,“:content_bv”,$content);
保监处执行($stid);
默认情况下,oci\u bind\u By\u name()只需要3个参数,并将绑定的所有变量视为字符。但是,在大多数情况下,它都可以正常工作,但如果您尝试添加浮点、二进制数据或整数,它可能会向您发出尖叫,并抱怨使用了无效的变量。要解决此问题,您需要为oci_bind_by_name提供另一组参数,例如:
if(is_numeric($v2)){
oci_bind_by_name($stmth, $bvar, $v2, 8, OCI_B_INT);
}else{
$v2 = (string) $v2;
oci_bind_by_name($stmth, $bvar, $v2, -1, SQLT_CHR);
}
或者像这样简单地将变量包装在strval()中
oci_bind_by_name($stid, ":description_bv", strval($description));
oci_bind_by_name($stid, ":content_bv", strval($content));
虽然我强烈建议创建/使用一个自定义类来为您处理所有变量绑定,但对变量使用strval()应该可以消除所有“用于绑定的无效变量”传递整数、双精度或其他格式时出错。这些值中是否有空值?请阅读示例3@Dimi它们肯定都不是空的。@u\u mulder不确定这有什么帮助?我知道这有点奇怪,但请尝试将您绑定的所有值像strval($guid)一样包装在strval中在你的bind命令中,看看这是否有效……我前一段时间不得不这么做过一次,不知道为什么,但当时它解决了我的问题