Click here to Skip to main content
15,868,066 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to insert array data one column sql in php


What I have tried:

How to insert array data one column sql in php
Posted
Updated 28-Nov-22 6:04am

1 solution

SQL has no concept of arrays, so it can't store one in a single column of a single row, which ise what I assume you want to do.
There is a way to do it - which is to store the data as a CSV string - but frankly that's a poor bodge that normally gives you huge headaches down the line.

The better way is to have a table for the array data - one column per array element - and store the ID of that row into the original table as a Foreign Key.
That way, you can access it when you need it and you don't "clutter" your main table.

But it really depends what you intend to do with the data within SQL itself: if all you are ever going to be doing is storing and retrieving it to your presentation app unchanged, then CSV would not be a real problem. If you are going to search it and select rows for the main table then it all starts to get iffy regardless of what you are doing and you may want to rethink any appraoch.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900