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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:27:38+00:00 2026-06-04T21:27:38+00:00

Here is my somewhat broken strategy If it is a query with no input

  • 0

Here is my somewhat broken strategy

  • If it is a query with no input ( always the same ), just use query();

    $results = $this->database_top->query( $query );
    
  • If a single row is returned and there is input, do the prep (not shown here) and use

    $results = $pdoStatement->fetch(PDO::FETCH_ASSOC); 
    
  • If multiple rows are returned and there is input,do the prep (not shown here) and use:

    $results = $pdoStatement->fetchAll(); 
    

Problem I’m facing is that I need the first method to return an array or array of arrays like the second and third.

Prep looks like this FYI

$this->database_top->quote($query);  // quote it
$pdoStatement = $this->database_top->prepare($query);  // prepare it
$results = $pdoStatement->execute($parameterArray); // execute it

How can I modify my code so that all 3 methods return arrays or array of arrays?

Iterating over query()

$result_array = $this->DatabaseObject->_pdoQuery( 'multiple', 'tweet_model' );
foreach( $result_array as $array_1d )
{
    $array_2d[]=$array_1d; 
}
  • 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-04T21:27:39+00:00Added an answer on June 4, 2026 at 9:27 pm

    query does not return results, so I’m not sure what you meant on the first example. query returns a PDOStatement. It’s basically the same as:

    $qry = $db->query("...");
    //equiv:
    $qry = $db->prepare("...");
    $qry->execute();
    

    As vicTROLLA noted, the simplest solution is to just use:

    $results = $stmt->fetch(PDO::FETCH_ASSOC);
    

    However, if you need to process the results as you go for some reason, you could always loop over them manually.

    $stmt = ...;
    $results = array();
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
        $results[] = $row;
    }
    //use or return $results
    

    $results will thus always be an array with 0 or more arrays inside of it.

    I find it useful to build arrays where the array key is the primary key of the record:

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
        $results[$row['id']] = $row;
    }
    

    Also, I suspect that you’ve misunderstood the purpose and functionality of quote. It is used for escaping strings that you are going to interpolate into a query, not for magically escaping all values in a query (hence $db->quote($query) makes no sense).

    Even worse is that drivers are not required to support quote. (Though it does at least return false if there’s no support.)

    prepare is massively preferred over quote.

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

Sidebar

Related Questions

This is somewhat related to my question here . Basically it is trivial to
This is somewhat of a followup to related question I found here . In
This is somewhat of a follow-up to an answer here . I have a
Forgive my somewhat-lacking ASP.NET knowledge for this question :) Here's the scenario: I'm playing
I realize there is a somewhat related thread on this here: Loading assemblies and
I am probably at the edge of etiquette here since the question is somewhat
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
I'm new here and somewhat inexperienced with C#. I've been searching through the MSDN
somewhat open ended question here as I am mostly looking for opinions. I am
so I know there are somewhat similar questions on here, but I haven't been

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.