By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,047 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,047 IT Pros & Developers. It's quick & easy.

New to OCI - double results?

P: n/a
Hello there

I'm trying to work with the example for OCI... and the $row returns 2
values, the same twice, but my query only have one... code below.

Can anyone explain?

BR
S
$query = 'select distinct(something) from a.b';

$stid = oci_parse($connX, $query);
if (!$stid) {
$e = oci_error($connX);
print htmlentities($e['message']);
exit;
}

$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
$e = oci_error($stid);
echo htmlentities($e['message']);
exit;
}

print '<table border="1">';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
{

print '<tr>';
print "<td>".(count($row))."</td>";
foreach ($row as $item) {
print '<td>'.$item.'</td>';
}
print '</tr>';
}
print '</table>';

oci_close($connX);

Jan 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Rik
Sonnich <so************@elektrobit.comwrote:
Hello there

I'm trying to work with the example for OCI... and the $row returns 2
values, the same twice, but my query only have one... code below.

Can anyone explain?

while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
http://www.php.net/oci_fetch_array

"returns an array with both associative and numeric indices."

So, tell it which one to use either associative:
oci_fetch_assoc($stid, OCI_RETURN_NULLS)

Or numerical:
oci_fetch_row($stid, OCI_RETURN_NULLS)

If you don't need the indexes, the last one seems to be the fastest.
--
Rik Wasmus
Jan 26 '07 #2

P: n/a
On 26 Jan 2007 08:52:57 -0800, "Sonnich" <so************@elektrobit.comwrote:
>I'm trying to work with the example for OCI... and the $row returns 2
values, the same twice, but my query only have one... code below.
[snip]
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
oci_fetch_array returns the values twice - once with numeric indexes, and
again with the names of the columns as keys.

http://uk.php.net/oci_fetch_array

The default mode is OCI_BOTH - you don't want that.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jan 26 '07 #3

P: n/a
I got this to work using
while ($row = oci_fetch_row ($stid))

But not I get another problem, see comment here:

$stid = oci_parse($connX, $sql2);
if (!$stid)
{
$e = oci_error($connX);
echo htmlentities($e['message'])."<br>";
}
else
{
$r = oci_execute($stid, OCI_DEFAULT);
// instead of going ahead, it still gives the error here. How do I
stop that.
// the error is correctly catched here anyway, but I'd like to have it
only. Meaning no default response when the query fails.
if(!$r)
{
$e = oci_error($stid);
if(strpos($e['message'],"CONNECT BY loop")!==false)
echo "<font class=\"error\">Loop error with item:
$Item[$i]</font><p>";
else
echo htmlentities($e['message'])."<br>";
}
else
{

On Jan 26, 6:52 pm, "Sonnich" <sonnich.jen...@elektrobit.comwrote:
Hello there

I'm trying to work with the example for OCI... and the $row returns 2
values, the same twice, but my query only have one... code below.

Can anyone explain?

BR
S
Jan 29 '07 #4

P: n/a
On Mon, 29 Jan 2007 09:03:12 -0800, Sonnich wrote:
I got this to work using
while ($row = oci_fetch_row ($stid))

But not I get another problem, see comment here:

$stid = oci_parse($connX, $sql2);
if (!$stid)
{
$e = oci_error($connX);
echo htmlentities($e['message'])."<br>";
}
else
{
$r = oci_execute($stid, OCI_DEFAULT);
// instead of going ahead, it still gives the error here. How do I
stop that.
By using the standard PHP error suppression operator:
$r = @oci_execute($stid, OCI_DEFAULT);

I would advise against doing that, but it is a possibility. OCI does
so called deferred parse, which means that parse and execute steps are
bundled into a single step. When your statement fails, it's usually a
serious situation.

--
http://www.mladen-gogala.com
Feb 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.