How to process an array in a function

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

kellyzhu
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Feb 18, 2014 9:27 am

How to process an array in a function

Postby kellyzhu » Wed Feb 19, 2014 8:31 am

I cannot find any problems in the following code. Though the array contains just one element, it still should work, right? But I got Oracle Error Code: 900
Oracle Error Message: ORA-00900: invalid SQL statement

$sql = array("select * from dept");

$result_array = execute_sql_in_oracle ($sql);

function execute_sql_in_oracle($sql) {

$connection = oci_connect ("", "", "");

for ($i=0; $i < count($sql); $i++) {

$cursor = oci_parse($connection, $sql[$i]);

$result[] = oci_execute($cursor);
}

// close the connection with oracle
oci_close ($connection);

$return_array["flag"] = $result;
$return_array["cursor"] = $cursor;

return $return_array;
}

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to process an array in a function

Postby seandisanti » Thu Feb 27, 2014 10:15 am

Assuming that you've removed db credentials from the $connection = line, but are passing them when required to make the connection, the code looks like it should work. Try outputting $sql[$i] to verify the sql that you're trying to execute

kellyzhu
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Feb 18, 2014 9:27 am

Re: How to process an array in a function

Postby kellyzhu » Thu Feb 27, 2014 11:44 am

when I do:

<?php
$sql = array('="select * from dept");

echo $sql[$i];
?>

It gives me a blank page.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest