Craig, (but it's more a question to and Tim and Mac)

> I need to be able to determine if a value is not found within a
> database and if so, report that the data and or row is not available
> back to the browser.
> 
> Here is my script that I am using to retrieve the data:
> 
> >>>>>> SNIP >>>>>>>>>
> 
> $dbh = DBI->connect("DBI:Informix:domain",
>                     {
>                       RaiseError => 1,
>                       AutoCommit => 0
>                     }
>                     );
> 
> $sth = $dbh->prepare("update reg_info set active = ? where domain_name = ?"); 
> $sth->bind_param( 1, $postInputs{'active'} ); 
> $sth->bind_param( 2, $postInputs{'domain_name'} ); 
> $sth->execute();

1. Besides that the above should be in an eval block anyways, is it a 
trappable (via eval and die/RaiseError) error at all if domain_name 
does not exist? Or is it just a 'normal' situation with just zero 
rows updated? Or is this database or driver specific?

2. Isn't this exactly the situation $sth->rows is meant for? For 
something like

if ($sth->rows == 0) {
        
        prompt_user($postInputs{domain_name} . ' does not exist!");
}

# assuming that only one row should be affected

elsif ($sth->rows > 1) { 
        panic("more than one record for domain_name 
$postInputs{domain_name}!");
}

elsif ($sth->rows == 1) {

        prompt_sucess($postInputs{'active'}, $postInputs{'domain_name'});
}

else {
        
        panic('Return value of $sth->rows cannot be handled!');
}



> $sth = $dbh->prepare("select * from reg_info where domain_name = ? and active = ?");
> $sth->bind_param( 1, $postInputs{'domain_name'} );
> $sth->bind_param( 2, $postInputs{'active'} );
> $sth->execute();
> 
> @row=$sth->fetchrow_array();
> 
> print "<h3><center>You have successfully updated the following
> information!</center></h3>"; print "<center>Domain Name:
> $row[0]</center>"; print "<center>Active: $row[5]</center>"; print
> "</body></html>"; print "&nbsp";
> 
> >>>>>> SNIP >>>>>>>>>
> 
> If the update statement cannot run due to the domain_name not existing
> in the database I need to send an error back to the browser.  A
> similar thing would be if the user was searching for a domain such as:
> 
> select * from reg_info where domain_name = "mydomain.com"
> 
> and the domain cannot be found in the table.
> 
> Thanks,
> 
> Craig A. Sharp
> Unix Systems Administrator
> DNS Administrator
> Roush Industries
> Office: 734-466-6286
> Cell: 734-231-6769
> Fax: 734-466-6939
> [EMAIL PROTECTED]
> ====================================================
> I have not lost my mind, it's backed up on tape somewhere!
> ====================================================
> 

Bodo


Reply via email to