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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:16:16+00:00 2026-06-14T10:16:16+00:00

This is a part of PHP & MySQL Novice to Ninja, 5th Edition by

  • 0

This is a part of
PHP & MySQL Novice to Ninja, 5th Edition by Kevin Yank

Normally when we perform a SELECT query , we use the condition of a
while loop or a foreach loop to retrieve each row of the results, one
at a time:

while ($row = $result->fetch()) foreach ($result as $row)

When we process the result of a query this way, PHP actually retrieves
each row from the database as the loop requests it, and throws it away
when it moves on to the next row . This saves PHP from having to use a
lot of memory to hold onto all the rows of results at once.

Most of
the time, we developers have no need to know that PHP is taking this
clever shortcut. But every once in a while, we’ll want to send another
SQL query to the MySQL server before we’ve worked through all the
results of the previous query .

That’ s exactly what’ s about to
happen in this code if we aren’t careful: we’ve just run a SELECT
query to ask for a list of all jokes belonging to a particular author,
and as we work through that list, we’d like to perform a DELETE query
for each one. The problem is, as far as MySQL knows, it will still be
busy sending us the results of the SELECT query; we can’t just
interrupt it and ask for it to start running DELETEs! Doing so would
cause our DELETEs to fail with an error .

That’ s where the fetchAll
method comes in. By calling this method on our prepared statement
($s), we ask PHP to retrieve the entire set of results for the query
and store them in a PHP array ($result):

My question is Why I can execute MYSQL statements while I have one or more PDOStatement result sets being used in my PHP code?
even I can delete all rows being referenced in those result sets

<?php
    include_once $_SERVER["DOCUMENT_ROOT"] . '/DBconnection.inc.php';

        $pds1 = $dbi->query("SELECT name FROM tbl1");
        $row = $pds1->fetch();
        var_dump($row['name']);

        $pds2 =  $dbi->query("SELECT user FROM tbl2");
        $row = $pds2->fetch();
        var_dump($row['user']);

        $row = $pds1->fetch();
        var_dump($row['name']);

        $row = $pds2->fetch();
        var_dump($row['user']);

        $pds3= $dbi->prepare("DELETE FROM tbl1;");
        $pds3->execute();

        $row = $pds1->fetch();
        var_dump($row['name']);

        $row = $pds2->fetch();
        var_dump($row['user']);



?>
  • 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-14T10:16:17+00:00Added an answer on June 14, 2026 at 10:16 am

    This is an area where the behavior of PDO is going to depend on the database you’re using and the PDO driver implementation. You might be able to execute new queries while you’re still fetching the results of a select statement, or you might not.

    In general, the safest and most compatible way to use PDO connections is:

    1. execute your SELECT statement
    2. fetch all of the rows you need
    3. close the cursor (eg: with $pds1->closeCursor())
    4. execute your next query
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I have my website built on PHP & Mysql. Consider this like a
I have this PHP code : $query = SELECT * FROM news WHERE news_active
For this particular project I will be using PHP 5.3 & MySQL with parameterized
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I need a fix for this. here is just part of my code <?php
I've made this php code for filtering the results from a mysql database. It
I'm trying to make a search in a table, something like this: http://www.phpjabbers.com/free-scripts/mysql-search-table/search.php I
I am developing a forum in php & MySQL for intranet.I started my development
I have a string &168491968426|mobile|3|100|1&185601651932|mobile|3|120|1&114192088691|mobile|3|555|5& and i have to delete, say, this part &
I am writing a stock market trading game base on yahoo using php/mysql &

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.