Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php, oracle, oci_connect, if no results found

Status
Not open for further replies.

mwpclark

Programmer
Mar 14, 2005
59
0
0
US
Hi

I am stumped with a script that works quite well to display data from an oracle db using oci_connect, oci_parse and oci_fetch.

When the script does not find a result matching the query parameters, I want to send a header 400 not found message.

I have tried lots of tests and I can't get it to work. The best I have gotten is a blank page.

Here are some relevant parts of the script:
Code:
if (!$conn = oci_connect('user', 'password', '//localhost/XE')) {
$err = oci_error();
trigger_error('Could not establish a connection: ' .
$err['message'], E_USER_ERROR);
}

$query = "select * from NPI_DATA_$state where NPI = '$in_npi'";

$stmt = oci_parse($conn, $query);
oci_define_by_name($stmt, "NPI", $NPI);
<snip DEFINE VARIABLES>

if (!oci_set_prefetch($stmt, 5)) {
trigger_error('Failed to set the number of rows to be
prefetched', E_USER_WARNING);
}
if (!oci_execute($stmt, OCI_DEFAULT)) {
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
}

while (oci_fetch($stmt)) {

<snip ALL ACTIVITY>

}

OK, after the while (oci_fetch($stmt)) { line, I want to insert something like

Code:
if ($NPI == '') {
header("HTTP/1.0 404 Not Found");
include ('notfound.html');
exit;
}
else {

and of course a trailing brace }

I have also tried (after the while (oci_fetch($stmt)) { line)

Code:
if ($NPI != '') {

This does prevent any further display and results in a blank page.

But when I trail it by

Code:
}
else {
header("HTTP/1.0 404 Not Found");
include ('notfound.html');
exit;
}

Nothing happens, still a blank page.

I have also tried a number of test phrases (echo 'foo';)

I just can't get it to recognize the IF ELSE statements.

What am I missing? Is it something to do with the way oci returns the oracle data? Am I putting this in the wrong place?

Any comments appreciated greatly.

Thanks
Mike

 
Hi

I do not really understand what are you doing there, but I would combine [tt]if[/tt] and [tt]while[/tt] like this :
PHP:
[b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]oci_fetch[/color][teal]([/teal][navy]$stmt[/navy][teal]))[/teal] [teal]{[/teal]
  [b]do[/b] [teal]{[/teal]
    [gray]// <snip ALL ACTIVITY>[/gray]
  [teal]}[/teal] [b]while[/b] [teal]([/teal][COLOR=darkgoldenrod]oci_fetch[/color][teal]([/teal][navy]$stmt[/navy][teal]));[/teal]
[teal]}[/teal] [b]else[/b] [teal]{[/teal]
  [COLOR=darkgoldenrod]header[/color][teal]([/teal][green][i]"HTTP/1.0 404 Not Found"[/i][/green][teal]);[/teal]
  [red]include[/red][teal]([/teal][green][i]'notfound.html'[/i][/green][teal]);[/teal]
  [b]exit[/b][teal];[/teal]
[teal]}[/teal]

Feherke.
 
Seems to work, thanks a bunch!

I am reading data from an oracle database, and printing to a web page. The data record is identified by the NPI column. If that record does not exist, I need the 404 header for google.

This is a huge db, the NPI Registry, 3 million lines with 314 columns, which is updated monthly from the U.S. government. If the physician contact information is incorrect, I get complaints, and I delete individual records and instruct people how to correct their info with the feds.

The problem has been that google retains the cached info and they have denied my removal requests, without giving a specific reason for the denial, rather a list of possible reasons. I am hoping this will solve that issue.

Thanks again
Mike

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top