简体   繁体   English

oci_parse使用php变量时给出错误

[英]oci_parse giving error when using php variable

I'm trying to build a string to pass an array into oracle using oci. 我正在尝试构建一个字符串,以便使用oci将数组传递给oracle。 If I write the string it works fine, but if I pass it as a variable it gives an error. 如果我写字符串,它可以正常工作,但是如果我将它作为变量传递,则会出现错误。

This works fine: 这工作正常:

$c = oci_pconnect ( $config ['db'] ['username'], $config ['db'] ['password'], $config ['db'] ['hostspec'] );


        try {
$llamado = "DECLARE V_DNA_ARRAY M6_TEMP_DNA_TAB_TYPE:=M6_TEMP_DNA_TAB_TYPE();BEGIN V_DNA_ARRAY.extend(3); V_DNA_ARRAY(1) := O_M6_TEMP_DNA('91','92','93','94','95'); V_DNA_ARRAY(2) := O_M6_TEMP_DNA('96','97','98','99','910'); V_DNA_ARRAY(3) := O_M6_TEMP_DNA('911','912','913','914','915'); SINTRA.PKG_MEDULA.P_INSERT_TEMP_DNA ( V_DNA_ARRAY );END;";
            $s = oci_parse ( $c, $llamado );
            $r = oci_execute ( $s);


        } catch ( Exception $e ) {
            var_dump ( $r );
            var_dump ( $e->$d->getMessage () );
            die ( 'STOP' );
        }

But if I do this (because values will change) it gives me: 但是如果我这样做(因为值会改变),它将给我:

Warning: oci_parse() expects parameter 1 to be resource, integer given in C:\\xampp\\htdocs\\cph_donante\\inside\\action\\gsilva\\insert.php on line 153 警告:oci_parse()期望参数1为资源,第153行的C:\\ xampp \\ htdocs \\ cph_donante \\ inside \\ action \\ gsilva \\ insert.php中给出的整数

Warning: oci_execute() expects parameter 1 to be resource, null given in C:\\xampp\\htdocs\\cph_donante\\inside\\action\\gsilva\\insert.php on line 154 警告:oci_execute()期望参数1为资源,在第154行的C:\\ xampp \\ htdocs \\ cph_donante \\ inside \\ action \\ gsilva \\ insert.php中给定null

 $c = oci_pconnect ( $config ['db'] ['username'], $config ['db'] ['password'], $config ['db'] ['hostspec'] );


        try {

        $llamado = '"DECLARE V_DNA_ARRAY M6_TEMP_DNA_TAB_TYPE:=M6_TEMP_DNA_TAB_TYPE();BEGIN ';
$llamado .= 'V_DNA_ARRAY.extend('.count($c1).'); ';
foreach ($c1 as $c => $v){
$llamado .= 'V_DNA_ARRAY('.($c + 1).') := O_M6_TEMP_DNA('.$v.'); ';
}
$llamado .= 'SINTRA.PKG_MEDULA.P_INSERT_TEMP_DNA ( V_DNA_ARRAY );END;"';


            $s = oci_parse ( $c, $llamado );
            $r = oci_execute ( $s );


        } catch ( Exception $e ) {
            var_dump ( $r );
            var_dump ( $e->$d->getMessage () );
            die ( 'STOP' );
        }

Can you tell me how it works? 你能告诉我它是如何工作的吗?

At first look it appears that you have your colons on the wrong side of the equals sign in your statement. 乍看起来,您的语句中冒号位于等号的错误一侧。

Here is the link to the php doc on oci_parse: oci_parse 这是oci_parse上php文档的链接: oci_parse

Also, you may want to take a look at oci_bind functions to bind variables to your statement before executing. 另外,您可能想看看oci_bind函数在执行之前将变量绑定到语句上。

In answer to your question of wanting to know how it works, my best answer is read the documentation. 在回答您想知道它如何工作的问题时,我最好的答案是阅读文档。 PHP docs are pretty well written (imo) and there are examples of implementation too. PHP文档写得很好(imo),也有实现示例。 I would look there for how it works. 我会在那里寻找它的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM