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 9166743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:13:20+00:00 2026-06-17T15:13:20+00:00

So I am getting this intermittent error on a call to PDO::execute(). Error is

  • 0

So I am getting this intermittent error on a call to PDO::execute(). Error is “Call to a member function execute() on a non-object”. It happens at line 117 in my db class. Here is my class below. Page loads in fine and then intermittently when I refresh this error comes back.

class db extends PDO {
    private $error;
    private $sql;
    private $bind;
    private $errorCallbackFunction;
    private $errorMsgFormat;

    public function __construct($dsn, $user="", $passwd="") {
        $options = array(
            PDO::ATTR_PERSISTENT => false, 
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        );

        try {
            parent::__construct($dsn, $user, $passwd, $options);
        } catch (PDOException $e) {
            $this->error = $e->getMessage();
        }
    }

    private function cleanup($bind) {
        if(!is_array($bind)) {
            if(!empty($bind)) {
                $bind = array($bind);
            }
            else {
                $bind = array();
            }
        }
        return $bind;
    }

    public function run($sql, $bind="") {
        $this->sql = trim($sql);
        $this->bind = $this->cleanup($bind);
        $this->error = "";

        try {
            $pdostmt = $this->prepare($this->sql);
            if($pdostmt->execute($this->bind) !== false) {
                if(preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->sql)) {
                    return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
                }
                elseif(preg_match("/^(" . implode("|", array("delete", "insert", "update")) . ") /i", $this->sql)) {
                    return $pdostmt->rowCount();
                }
            }   
        } catch (PDOException $e) {
            $this->error = $e->getMessage();    
            $this->debug();
            return false;
        }
    }

    public function select($table, $where="", $bind="", $fields="*") {
        $sql = "SELECT " . $fields . " FROM " . $table;
        if(!empty($where)) {
            $sql .= " WHERE " . $where;
        }
        $sql .= ";";

        return $this->run($sql, $bind);
    }

}   

Now whenever I change PDO::ATTR_PERSISTENT to false the problem goes away so it looks to be an issue with my construct call running over itself.

Also here is my my model that the error is showing up on.

class QuickView extends Model {

function getProduct($sku) {
    $bind = array(
        ":sku" => "$sku"
    );
    $result = $this->Quickview->db->select('`PRODUCTS`', 'PR_SKU = :sku', $bind, 'PR_SKU, PR_URLofImage, PR_UnitPrice, PR_Description');

    return $result;
}

}

And then here is the class it extends.

class Model extends DB {
    protected $_model;

    function __construct() {

        global $inflect;

        $this->db = new DB("mysql:host=localhost;dbname=dbname", "username", "password");
        $this->_limit = PAGINATE_LIMIT;
        $this->_model = get_class($this);
        $this->_table = strtolower($this->_model)."s";
    }

    function __destruct() {
    }

}
  • 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-17T15:13:21+00:00Added an answer on June 17, 2026 at 3:13 pm

    Check the docs for PDO::prepare: https://www.php.net/manual/en/pdo.prepare.php

    It does not always return a PDOStatement object. If there is an error processing the query, it will either return false or throw an exception depending on what its error handling mode is.

    In your case, you are trying to set it to throw an exception, but that is not a driver option. It is set with PDO::setAttribute, i.e:

    $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    If you fix that, you will get the exception from your error. Otherwise, you can also fix it by checking the result of PDO::prepare before you call execute on it.

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

Sidebar

Related Questions

Im getting this linker error that won't let me compile. It only happens on
I am getting this error intermittently but when it happens my automated integration testing
I am getting this intermittent error for some visitors to my site where even
Getting this error: # rails c FFI::NotFoundError: Function 'xmlRelaxNGSetParserStructuredErrors' not found in [libxml2.so, libxslt.so,
I'm getting this error intermittently when attempting to call functions in a localconnection. Error
So the problem is i keep getting this error. Its very intermittent and is
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Getting this error when try to add an item to my repositories/context: Collection has

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.