Jump to content

PEAR DB Error Handling


F1Fan

Recommended Posts

Hello. I've been using PEAR for a while, but I'm just now getting in deeper. I have a (hopefully) simple question; How can I simply check so see if a data manipulation query successfully executed? I'm looking for just a TRUE/FALSE determination.

 

I'm sorry if this is a duplicate post, but I couldn't find anything on this. I'm not looking to find an error, or display the error, I just want to know if there was one. Nothing more.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/128596-pear-db-error-handling/
Share on other sites

Do you mean something like

 

if (!mysql_query)
  	{
  	die(' Error: ' . mysql_error("False"));
  	}
echo "True";

 

or something like

 

public function DbQuery($queryString)           
  {                                               
    $result = $this->db->query($queryString);     
    if (DB::isError($result))                     
       trigger_error($result->getMessage(), E_USER_ERROR);
    return $result;                               
  }  

Yes. My company uses PostgreSQL, but it would be almost exactly the same as the "mysql_query()" function that returns TRUE on success, and FALSE on error. I found some documentation that led me to something close to your second suggestion:

 

<?php
// $db is my PEAR DB Object
$result = $db->query($query);
return DB::isError($db);
?>

As you can see, I'm checking the object itself for the error, which is how the PEAR manual shows it:

http://pear.php.net/manual/en/package.database.db.db-error.php

Should it be the $result variable instead?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.