Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:49:19+00:00 2026-06-02T00:49:19+00:00

How can I recognize a fetch error or empty result from a execute error

  • 0

How can I recognize a fetch error or empty result from a execute error with php PDO mysql driver?

  $sql = ' SELECT * ';
  $sql .= ' FROM test ';
  $sql .= ' WHERE id = 432 ';

  $statement = $this->_db->prepare($sql);
  $status = $statement->execute();

  var_dump($status);

  $result = $statement->fetch(\PDO::FETCH_ASSOC);

  var_dump($result);

  output:
  bool(true)
  bool(false)

So, I prepare statement with pdo, then execute sql, and status is true because there aren’t error. Then I fetch result, and in this specific case a row with id = 432 isn’t exist. So fetch method return false. My problem is that fetch method return false also when there is a error!.

How can I sure that fetch “false” result is a error or empty result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:49:20+00:00Added an answer on June 2, 2026 at 12:49 am

    If there’s an error then PDO will throw an exception which you can catch. Wrap your code with a try catch and that should catch any exceptions.

    try {
        $rs = $db->prepare('SELECT * FROM foo');
        $rs->execute();
        $foo = $rs->fetchAll();
    } catch (Exception $e) {
        echo 'Error: '.$e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't get PHP to recognize the ImageMagick (Imagick) class. Everything else works, the
$result = mysql_query(SELECT * FROM photos WHERE accountID = '{$accID}' GROUP BY album_name ORDER
How can I recognize (.NET 2 ) a generic class? Class A(Of T) End
1) How can the processor recognize the device requesting the interrupt? 2) Given that
Can node.js be setup to recognize a proxy (like Fiddler for example) and route
can I add BehaviorID attribute for asp.net textbox and use it to be recognize
Is there a javascript library the can recognize phone numbers in a web page?
I want to build a program that can recognize typical playing cards. is there
I am writing some application logic which can recognize malformed or malicious http post
Is there a vocabulary library that can recognize different forms as one word? Like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.