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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:07:26+00:00 2026-06-09T04:07:26+00:00

I would like to have the last query (for debugging purposes) from the PDOStatement.

  • 0

I would like to have the last query (for debugging purposes) from the PDOStatement. But I can’t override the bindParam and bindValue methods. When I tried the code below, I got:

Fatal error: Default value for parameters with a class type hint can only be NULL

Then I replaced the PDO::PARAM_STR to null in the parameter list of bindParam/bindValue, so I got:

Strict Standards: Declaration of DBStatement::bindParam() should be compatible with that of PDOStatement::bindParam()

I then deleted int before the $data_type parameter and set the default value to PDO::PARAM_STR. Then I got:

Strict Standards: Declaration of DBStatement::bindParam() should be compatible with that of PDOStatement::bindParam() in D:\www\pdotest.php on line 73

(interestingly, the bindValue is okay now).

So, what can I do now?

class DBConnection extends PDO
{
    public function __construct($dsn, $username = null, $password = null, $driver_options = array())
    {
        parent::__construct($dsn, $username, $password, $driver_options);

        $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DBStatement', array($this)));
        $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
}

class DBException extends PDOException
{
    private $query_string;
    private $parameters;

    public function __construct($message = '', $code = 0, $previous = null, $query_string = '', $parameters = array())
    {
        parent::__construct($message, $code, $previous);        

        $this->query_string = $query_string;
        $this->parameters = $parameters;
    }

    public function getQueryString()
    {
        return $this->query_string;
    }   

    public function getParameters()
    {
        return $this->parameters;
    }
}

class DBStatement extends PDOStatement
{
    private $conn;
    private $parameters = array();

    protected function __construct($conn)
    {
        $this->conn = $conn;
    }

    public function bindParam($parameter, &$variable, int $data_type = PDO::PARAM_STR, int $length = null, $driver_options = null)
    {
        $this->parameters[$parameter] = $variable;

        parent::bindParam($parameter, $variable, $data_type, $length, $driver_options);
    }

    public function bindValue($parameter, $value, int $data_type = PDO::PARAM_STR)
    {
        $this->parameters[$parameter] = $value;

        parent::bindValue($parameter, $value, $data_type);
    }

    public function execute($input_parameters = null)
    {
        try
        {
            parent::execute($input_parameters);
        }
        catch (PDOException $e)
        {
            throw new DBException($e->getMessage(), $e->getCode(), $e->getPrevious(), $this->queryString, $this->parameters);
        }
    }
}

$id = 1;

try
{
    $conn = new DBConnection('mysql:host=localhost;dbname=test', 'root', '');
    $stmt = $conn->prepare('select * from foo where id = :id');
    $stmt->bindParam(':id', $id);
    $stmt->execute();
}
catch (DBException $e)
{
    echo "Query string was: ".$e->getQueryString()."\n";
    echo "Parameters was: ".print_r($e->getParameters(), true);
}

I also recieve te following when I throw a DBException (because of $code parameter):

Notice: A non well formed numeric value encountered in D:\www\pdotest.php on line 21

  • 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-09T04:07:27+00:00Added an answer on June 9, 2026 at 4:07 am

    Don’t need to use the “int” type of the $data_type variable, then it works.

    public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null)
    {
        $this->parameters[$parameter] = $variable;
    
        parent::bindParam($parameter, $variable, $data_type, $length, $driver_options);
    }
    
    public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
    {
        $this->parameters[$parameter] = $value;
    
        parent::bindValue($parameter, $value, $data_type);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string would like everything after the last / to be returned.
I have the following String First Last <first.last@email.com> I would like to extract first.last
I have the following query where I would like to return two result sets.
I have a query like this: SELECT tm.first_name, tm.last_name, tm.id, i.thumb FROM team_members tm,
I have a lab values table that I would like to query and get
I have a somewhat simple query in SQL that I would like to convert
I have a problem. I would like to get only 300 rows from table
I have a java application and I would like to get some data from
I would like to ask about the query to select the last record in
I have the following query in SQL which I would like to convert 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.