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

  • Home
  • SEARCH
  • 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 8550571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:58:47+00:00 2026-06-11T13:58:47+00:00

I have a quick question that I hope has a quick and clear answer.

  • 0

I have a quick question that I hope has a quick and clear answer.

On php.com’s manual, it states that execute() after binding the values to a prepared query will return true on success and false on failure. Simple enough.

I just wanted to make sure I had this clear. The values returned on execute() correspond to direct errors. For instance, if the database somehow went down after a successful connect, and the query could not be executed – or some other extraordinary issue.

Consider some code:

    protected function territoryCheck($numberOut)
    {
        $this->numberOut = $numberOut;

        //Execute test
        $this->checkConnect();
        $stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1")
        $stmt->bindParam(':param1', $this->numberOut);
        $stmt->execute();

        //Determine value of test
        if($stmt == FALSE)
        {
            return FALSE;
        }   
    }

I am rather sure that this will not operate as I want. The point is to see if t_id exists in the database based on whether there is a corresponding value to the parameter. In that case, I need to use $stmt->fetch(). Am I correct in saying that?

Any help is appreciated.

Edit: Along the same lines, would it be prudent – or I should say best practice – to put

//Execute test
        $this->checkConnect();
        $stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1")
        $stmt->bindParam(':param1', $this->numberOut);
        $stmt->execute();

within a try-catch since PDO returns exceptions?

  • 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-11T13:58:48+00:00Added an answer on June 11, 2026 at 1:58 pm

    Yes, you are right. $stmt->execute() return false only when it failed to execute the query. It won’t return false with empty result set. So you need to use fetch() to check the result, fetch() return false for empty result set.

    And for the exceptions, PDO will throw exception only when you set the exception mode for the methods execute() etc. But new PDO(...) will throw exception no matter whether the exception mode is set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a question that needs a quick answer, I have a Action, lets say,
I have quick question about jQuery plugins, hope somebody out there has some advice.
I have a quick question i hope you guys can answer, i've got a
I hope that this is a quick question to answer. I am developing a
I have a quick and hopefully simple question that I hope someone can help
I have a quick question that hopefully someone has worked through before. In the
Really quick question - (I hope!) I have a div that doesnt display until
I have a quick question that I can't seem to find online. I am
I have a quick question here. I know that the cakePHP find('first') function returns
I have a question that should be quick and easy for you guys to

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.