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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:05+00:00 2026-05-14T02:38:05+00:00

// First, prepare the statement, using placeholders $query = SELECT * FROM tableName; $stmt

  • 0
// First, prepare the statement, using placeholders
$query = "SELECT * FROM tableName";
$stmt = $this->connection->prepare($query);

// Execute the statement
$stmt->execute();
var_dump($stmt->fetch(PDO::FETCH_ASSOC));

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
{
echo "Hi";
// Export every row to a file
fputcsv($data, $row);
}

Is this correct way to do and if yes than why do I get false value for var_dump and than it does not go into while loop and does not write into csv file.

Any suggestions ?

  • 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-14T02:38:06+00:00Added an answer on May 14, 2026 at 2:38 am

    One thing that is missing is that you first need to open the csv file:

    $fp = fopen('file.csv', 'w');
    

    then you can put data into it:

    fputcsv($fp, $data);
    

    As for the var_dump printing out false, you would have to provide more information about what objects you are actually using I think. (ie: what is $this->connection ?)

    I don’t know if this will help, but try to do it without the $this->connection:

    $config['database'] = 'sakila';
    $config['host'] = 'localhost';
    $config['username'] = 'root';
    $config['password'] = '';
    
    $d = new PDO('mysql:dbname='.$config['database'].';host='.$config['host'], $config['username'], $config['password']);
    $query = "SELECT * FROM actor";
    $stmt = $d->prepare($query);
    
    // Execute the statement
    $stmt->execute();
    
    var_dump($stmt->fetch(PDO::FETCH_ASSOC));
    
    $data = fopen('file.csv', 'w');
    
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
    {
        echo "Hi";
        // Export every row to a file
        fputcsv($data, $row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a few tests, first I tested mysql prepared statement with $pdo->prepare() and
This is my first time using SQL, and I thought I did everything right,
Using this SP I keep getting an error on the UPDATE statement indicating that
this is my first time using jquery, and i dont think it seems to
When using a PreparedStatement in JDBC, should I close the PreparedStatement first or the
First, let's get the security considerations out of the way. I'm using simple authentication
First off, I am using Windows XP. I have multiple hard drives and it
First off, there's a bit of background to this issue available on my blog:
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
I am using the MySql Connector C++ to store a JPEG image from a

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.