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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:08:56+00:00 2026-05-27T10:08:56+00:00

Ive written a pdo wrapper class with a query function to automatically take an

  • 0

Ive written a pdo wrapper class with a query function to automatically take an array and bind the values to the statement before execution.

public function query($query, $sprints = NULL)
{
    // Add query to the last query and benchmark
    $bench['query'] = $query;

    // Prepare the statement
    $this->result = $this->pdo->prepare($query);

    // Process our sprints and bind parameters
    if(is_array($sprints))
    {
        // Bind our parameters
        foreach($sprints as $key => $value)
        {
            // if we are using "?'s", then we up the keys +1
            if(is_int($key)) ++$key;

            // Bid the param based on its type
            if(is_int($value))
            {
                // Bind the param
                $this->result->bindParam($key, $value, \PDO::PARAM_INT);
                $bench['bound'][$key] = $value;
            }
            else
            {
                // Bind the param
                $this->result->bindParam($key, $value, \PDO::PARAM_STR, strlen($value));
                $bench['bound'][$key] = $value;
            }
        }
    }

    // Time, and process our query
    $start = microtime(true);
    try {
        $this->result->execute();
    }
    catch (\PDOException $e) { 
        // show error
    }
    $end = microtime(true);

    // Get our benchmark time
    $bench['time'] = round($end - $start, 5);

    // Get our number of rows
    $this->num_rows = $this->result->rowCount();

    // Add the query to the list of queries
    $this->queries[] = $bench;

    // Return
    return $this;
}

The problem is, on an Insert, its replacing all the ?’s with the last bound parameter. Here the query and results:

INSERT INTO sessions(`token`,`ip_address`,`last_seen`,`user_data`) VALUES (?, ?, ?, ?) 

The bound params are:

[bound] => Array ( [1] => test1 [2] => 0.0.0.0 [3] => test3 [4] => test4 )

And the result in the database, is all 4 columns are filled with test4. Anyone have a clue as to why its doing this?

  • 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-27T10:08:57+00:00Added an answer on May 27, 2026 at 10:08 am

    Dunno what’s your problem but why not to make it just

    $this->result = $this->pdo->prepare($query); 
    $this->result->execute($sprints); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive written a query that searches for all posts that have X as a
Ive written this if statement and it works fine but was just wondering if
Ive written a Word addin in VS 2008 thats pretty simple, just adds a
I have a photoshop plugin for a file format Ive written in c++ that
I've written PL/SQL code to denormalize a table into a much-easer-to-query form. The code
I've written this very simple function to replace a file extension using LINQ in
I've written a simple SessionItem management class to handle all those pesky null checks
ive written a quick .bat file that reads in the name of a directory
Hi ive written some code to connect to a server through the use of
Hi Ive written a simple android application with two xml pages, one has an

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.