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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:38:57+00:00 2026-05-24T20:38:57+00:00

This must be really simple… Following examples on here and php.net, I’m trying to

  • 0

This must be really simple… Following examples on here and php.net, I’m trying to get records from a mysql query, convert them to csv format, and assign this data to a variable for use in a program I have created. I would like to accomplish this without creating temporary files.

  public function export3() {
      $order_data = array();
      $order_data[] = array(
        'order_id',
        'email',
        'telephone',
        'shipping_address',
        'payment_address',
        'comment'
    );


    // Mysql returns data and is assigned to this array in the following format

    $order_data[] = array(
        '1',
        'blank@blank',
        '123456789',
        '123 Lane',
        '123 Lane',
        'no comment'
    );



    $order_data[] = array(
        '2',
        'blank3@blank3',
        '987654321',
        '321 Lane',
        '321 Lane',
        'no comment'
    );

    $outstream = fopen("php://temp", 'r+');

    foreach($order_data as $csv_data) {
        fputcsv($outstream, $csv_data);
    }

    rewind($outstream);
    $export_data = fgets($outstream);
    fclose($outstream);

    $response->output($export_data);

}

Unfortunately, I occasionally get complaints of “array to string” conversion, but even without any errors, I only get the first array (in csv format) but not the others. Any suggestions? Thank you

  • 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-24T20:38:58+00:00Added an answer on May 24, 2026 at 8:38 pm

    Use stream_get_contents() in place of fgets(), since the latter only fetches a single line.

    $export_data = stream_get_contents($outstream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be really simple but just not getting my syntax right here. let's
I know SQL well but I must be missing something really dumb here. This
This must be a classic .NET question for anyone migrating from Java. .NET does
i'm sure this must be really simple or i'm missing the point, but how
I feel like there must be something really simple that I'm not seeing here.
I'm sure this is a really simple question. The following code shows what I'm
I'm sure there must be a really simple answer to this, but at the
So, simple question really. :) I had this following code with ASPX View Engine
This must be really simple: On mySQL - UPDATE exp_channel_data Where entry_id is between
This should be really simple but for some reason I can't seem to get

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.