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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:37:09+00:00 2026-05-27T04:37:09+00:00

I have an issue with exporting BLOB to a csv file using php. Obviously

  • 0

I have an issue with exporting BLOB to a csv file using php. Obviously blob is not a normal field, but it is on occasion used. But here’s what I need, I need this script to work by taking a table array and export each row in csv format. Blob is screwing this up. I’ve tried to base64_encode the blob, but I believe that would export the blob incorrectly.

Here is what I have so far:

function exportcsv($tables) {
    foreach ($tables as $k => $v) {
        $fh = fopen('sql/'.$v.'.csv', 'w');
        $sql = mysql_query("SELECT * FROM $v");
        while ($row = mysql_fetch_row($sql)) {
            $line = array();
            foreach ($row as $key => $v) {
                $line[] = base64_encode($v);
            }
            fputcsv($fh, $line, chr(9)); //tab delimiting
        }
        fclose($fh);
    }
}

Any help would be appreciated.

EDIT: Here is an image of the blob export WITHOUT base64_encode().
https://www.strongspace.com/shared/crypok1lxb

So, will base64 protect the format of blob when the need to reimport arises?

  • 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-27T04:37:10+00:00Added an answer on May 27, 2026 at 4:37 am

    The purpose of Base64 encoding is to make binary data survive transport through transport layers that are not 8-bit clean, so yes, you are on the right track with this.

    What you really need to be worried about is that fputcsv() function. What are the dangerous items you need to check for?

    1. Tabs, because this is your delimiter
    2. New line characters, because it seems you are also parsing by line

    According to this link, Base 64 encoding only spans A-Z, a-z, 0-9, + and /, which means you are safe and the new line in the image you posted is probably an artifact from word wrapping in the IDE you are using. Now all that you have to remember is that when you want to import this data back into the DB, don’t expect to just use mysqldump or mysql < to pipe it in. You’re going to have to create another php function that uses base64_decode to get the data back into it’s original state.

    You should also be aware that you are currently encoding all of the fields, not just the blob data. Base64 encoding takes up some ~33% more space as an FYI so you may want to define your tables with some bit indicating if the field is a blod and you want to enable B64 encoding on it.

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

Sidebar

Related Questions

We have an issue using the PEAR libraries on Windows from PHP . Pear
I have an issue with using AWK to simply remove a field from a
I have an issue that is driving me a bit nuts: Using a UserProfileManager
I have an issue with exporting to PDF on an iPad. My goal is,
I have a model in App Engine that I am exporting in CSV format
I have an issue where if my json file looks like this { Numbers:
Yesterday I ran into an issue with PHP's strtotime not properly adding a month.
Very strange, not sure if others have experienced this... Exporting with Flash CS5.5 to
I have created a snk file using sn -k KeyFile.snk I installed it on
So, I have a local .rdlc file with some text formatted using strikethrough formatting.

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.