Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.