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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:52:15+00:00 2026-05-25T18:52:15+00:00

It seems to be a bug or problem when I use PHP PDO fetchOject

  • 0

It seems to be a bug or problem when I use PHP PDO fetchOject with the query below,

Query:

SELECT 
    p.*,
    t.*

FROM root_pages AS p

LEFT JOIN root_templates AS t
ON p.tmp_id = t.tmp_id

WHERE p.pg_url = ?
AND ? IS NOT NULL

OR p.pg_url = ? 
AND p.pg_hide != ?

called from a PHP PDO db class,

$page = $this->database->fetch_object($sql,array(
            $pg_url,
            NULL,
            $pg_url,
            1
        ));

result:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables
does not match number of tokens

PHP PDO FetchOject method from the PDO db class,

# return the current row of a result set as an object
    public function fetch_object($query, $params = array())
    {
        try
        {
            # prepare the query
            $stmt = $this->connection->prepare($query);

            # if $params is not an array, let's make it array with one value of former $params
            if (!is_array($params)) $params = array($params);

            # execute the query
            $stmt->execute($params);

            # return the result
            return $stmt->fetchObject();
            //return $stmt->fetch(PDO::FETCH_OBJ);
        }
        catch (PDOException $e) 
        {
            # call the get_error function
            $this->get_error($e);
        }
    }

It only will be fine if I call the method like this,

$page = $this->database->fetch_object($sql,array(
            $pg_url,
            1,
            $pg_url,
            1
        ));

But I can get the result without any error when I test one of the query below with phpMyAdmin,

SELECT 
    p.*,
    t.*

FROM root_pages AS p

LEFT JOIN root_templates AS t
ON p.tmp_id = t.tmp_id

WHERE p.pg_url = 'exhibition sample 6' 
AND '1' IS NOT NULL

OR p.pg_url = 'exhibition sample 6' 
AND p.pg_hide != '1'

or

SELECT 
    p.*,
    t.*

FROM root_pages AS p

LEFT JOIN root_templates AS t
ON p.tmp_id = t.tmp_id

WHERE p.pg_url = 'exhibition sample 6' 
AND NULL IS NOT NULL

OR p.pg_url = 'exhibition sample 6' 
AND p.pg_hide != '1'

Any ideas what I have missed when using fetchOject?

EDIT:

$sql ="
SELECT 
    p.*,
    t.*

FROM root_pages AS p

LEFT JOIN root_templates AS t
ON p.tmp_id = t.tmp_id


WHERE p.pg_url = 'exhibition sample 6' 
AND ? IS NOT NULL

OR p.pg_url = 'exhibition sample 6' 
AND p.pg_hide != '1'
";

No error with

$item = $connection->fetch_assoc($sql,1);

or

$item = $connection->fetch_assoc($sql,NULL);

the fetch_assoc method,

    # fetch a single row of result as an array ( =  one dimensional array)
public function fetch_assoc($query, $params = array())
{
    try
    {
        # prepare the query
        $stmt = $this->connection->prepare($query);

        # if $params is not an array, let's make it array with one value of former $params
        if (!is_array($params)) $params = array($params);

        # execute the query
        $stmt->execute($params);

        # return the result
        return $stmt->fetch();
    }
    catch (PDOException $e) 
    {
        # call the get_error function
        $this->get_error($e);
    }


}
  • 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-05-25T18:52:15+00:00Added an answer on May 25, 2026 at 6:52 pm

    What you are trying to do (pass in null as a parameter to execute) is not possible. As the documentation states:

    input_parameters

    An array of values with as many elements as there are bound parameters
    in the SQL statement being executed. All values are treated as
    PDO::PARAM_STR
    .

    If you want to pass in a null, you have to bind the parameters with

    $stmt->bindValue(1, null, PDO::PARAM_NULL);
    

    or use the equivalent syntax for named parameters.

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

Sidebar

Related Questions

Today I stumbled about a Problem which seems to be a bug in the
There seems to be a bug in a Wordpress PHP function that leaves whitespace
UPDATED I used below solutions (loading Image from stream), but get new problem. img
Seems like a simple problem: I have an SVN repo inside our firewall. I
Seems that requirements on safety do not seem to like systems that use AI
The page having problems is... http://schnell.dreamhosters.com/index.php?page=gallery# I use Firebug to debug my jQuery and
Can someone please confirm that the following is a bug with PHP 5.2.13: (thank
I tried to use PHP APC to upload files on wamp, windows2003. But when
When I use the FLV::Info module to extract metadata from or merge multiple FLV
I recently upgraded my XAMPP from PHP 5.2 to 5.3.1 I seem to be

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.