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

The Archive Base Latest Questions

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

How do we store arrays in database? What I am doing is the following:

  • 0

How do we store arrays in database?

What I am doing is the following:

// $data is an array

$v = base64_encode(json_encode($data));

$todo = 'INSERT INTO table (data) VALUES("' . $v . '")';
$sql = mysql_query($todo);

Also why do I have to call base64_encode before I store the array in the database?

  • 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-27T09:37:54+00:00Added an answer on May 27, 2026 at 9:37 am

    What you are doing is possibly wrong. There are many decisions you have made that are not by any means necessary, and they may also not be appropriate.

    For one thing, storing “frozen” arrays in the database is usually a bad idea because you cannot do anything with them other than get them back (you cannot modify them or query based on their contents). Solutions that “fix” this issue are database-oriented and include changing your table schema. I don’t know what you are trying to do so I won’t go in more detail.

    Then, if you do want to serialize arrays in your database (there are legitimate use cases) (edit: and only intend to access them through PHP code — as was very correctly pointed out!), the only thing you should be using is the serialize function — not json_encode or anything else. This is the very reason that function exists. When you get the values back from the database, use deserialize to get the array back.

    Finally, when injecting a variable into an SQL query, you need to escape it with mysql_real_escape_string (which you are not doing).

    So it would be much better to do:

    $sql = sprintf('INSERT INTO table (data) VALUES(\'%s\')',
                   mysql_real_escape_string(serialize($data)));
    $result = mysql_query($sql); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to store 2D arrays of 900x100 elements in a database. Efficient
What is the most efficient way to store large arrays (10000x100) in a database,
How can I store arrays in single array? e.g. I have four different arrays,
I want to store the array returned by a method into another array. How
I am doing tests in Core Data and have an array with approx. 230
I'm doing this database design stuff for a system where i need to store
I have a large multidimensional array that I would like to store into a
Problem: Need to store field value when doing this query on my database. Have
I am trying to store HTML posted from a textarea into a database. I
Using C++ and the STL, does anybody know how to store integer arrays as

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.