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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:42:21+00:00 2026-06-04T01:42:21+00:00

EDIT : You’re not allowed to have the word question in the title. Q-mark

  • 0

EDIT: You’re not allowed to have the word “question” in the title. Q-mark means “question-mark”

EDIT 2: Realized I should remove my personal contact info from the dummy customer record

I’m trying to making some basic functions to reduce maintenance of a recent project. Among these is the following simple function so I can add columns to the database at a later date without needing to change my update queries:

function update( $table, $fields ) {
    global $db; // A slightly modified PDO object
    if( count( $fields ) > 0 ) {
        $query = "UPDATE `" . $table . "` SET ";
        foreach( $customer as $key => $value ) {
            $query .= "`" . $key . "` = ?, ";
        }
        $query = substr( $query, 0, -2 );
        $query .= " WHERE `id` = " . $_REQUEST['id'];
        $db->prepare( $query );
        $db->execute( $fields );
    } else { return true; }
}

This function was working when I passed one or two fields, but the moment I tried passing more it failed. Here’s the query, value of $fields, and error I’m receiving:

Query:

string 'UPDATE `customers` SET `5v` = ?, `contactaddress` = ?, `contactaddress2` = ?, `contactcity` = ?, `contactemail` = ?, `contactname` = ?, `contactphone` = ?, `contactstate` = ?, `contactzip` = ?, `corrugated` = ?, `name` = ?, `permalok` = ?, `residential` = ?, `secureseam` = ?, `tax` = ? WHERE `id` = 1' (length=301)

$fields:

array
  '5v' => string '120' (length=3)
  'contactaddress' => string '999 Street Dr' (length=13)
  'contactaddress2' => string 'Apt 2' (length=7)
  'contactcity' => string 'City' (length=9)
  'contactemail' => string 'steven.abarnett@gmail.com' (length=25)
  'contactname' => string 'Steven Barnett' (length=14)
  'contactphone' => string '(555) 555-5555' (length=14)
  'contactstate' => string 'KY' (length=2)
  'contactzip' => string '55555' (length=5)
  'corrugated' => string '90' (length=2)
  'name' => string 'Steven's Metals' (length=15)
  'permalok' => string '130' (length=3)
  'residential' => string '100' (length=3)
  'secureseam' => string '130' (length=3)
  'tax' => string '6' (length=1)

Error:

string 'Statement execution failed: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' (length=96)

Googling this error, it sounds like an issue with named parameters, not question-mark parameters. Why am I getting this error?

UPDATE:

I’ve been continuing to debug and experiment and tracing the error I found it’s not the statement execution that fails, but attempting to fetch the result afterwards.

In my modified PDO object I have the following code within my execute() method:

    // Load from database
    try {
        $this->stmt->execute( $args );
        $this->lastid = $this->dbh->lastInsertId();
        $this->data = $this->stmt->fetchAll();
    } catch (PDOException $e) {
        $this->error = 'Statement execution failed: ' . $e->getMessage();
        return false;
    }

Placing echo statements between each line in the try{} section shows that the first two lines run without a hitch, but the third line is throwing the exception.

Is there are reason my query would fail with a general error when I call PDOStatement::fetchAll()?

FINAL UPDATE:

As it turns out PDO and Mysql haven’t been playing nicely for 6 years. The general solution seems to be to unset the PDOStatement object after each call to PDOStatement::execute(), however this didn’t work for me. The issue stems from the fact that MySQL can only have one cursor open at a time pointing to records in a record set, so another proposed solution is to use PDOStatement::fetchAll() instead of PDOStatement::fetch() OR to call PDOStatement::closeCusor(). Again, this didn’t work for me. My issue comes from certain installations of MySQL which will create a cursor during INSERT, UPDATE, and DELETE queries (all of which return no data) which can not be closed since it’s pointing to null data.

My solution was to only call PDOStatement::fetchAll() when I’m running a query that return data. I have a queryhash variable which was used in caching (the big modification I made to the PDO class) which was set to false for these three query types (since you need to send the query to the database rather than deferring to cache). I simply modified my execute() function to check this variable and only call fetchAll() if it was not set to false.

  • 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-04T01:42:23+00:00Added an answer on June 4, 2026 at 1:42 am

    you should be using an index array instead of an associative one.

    array(
        '120',
        '750 Shaker Dr',
        'Apt 505',
        'Lexington', 
        'steven.abarnett@gmail.com', 
        'Steven Barnett', 
        '(859) 402-7760', 
        'KY',
        '40504', 
        '90',
        "Steven's Metals",
        '130',
        '100',
        '130',
        '6'
    )
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit (updated question) I have a simple C program: // it is not important
EDIT: I have reworded the title question slightly, and adjusted the text to respond
EDIT: I rephrased the question because I have not explained well. Let's see if
Edit: The below question was answered by this . I have a new updated
EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
EDIT: If the question is badly written have a look at the video (
Edit : Array should be CvMat or IplImage is not an error message specific
Edit 1 Updated to make the enum not an argument to the method... Question
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when

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.