Jump to content

MySQL Arrays


Millar

Recommended Posts

I know quite a lot about MySQL but I have never needed to use an array as a mysql value.

I need to do this so my personal messaging system will allow sending messages to multiple recipients.

Now, really don't know how to go about using an array as a mysql field type. So if anyone could tell me what type of field I need and how to insert/retreive information using php, that would be really helpful.

Thanks in advanced,
Millar.
Link to comment
https://forums.phpfreaks.com/topic/32369-mysql-arrays/
Share on other sites

Like Fenway suggested, you're probably asking the wrong question. I seriously doubt that you NEED to do this.

I'm guessing what you really want to do is store a PHP array. In which case, you can either store the values as a comma separated list, and explode() it when you retrieve it. Or, if you have more complex arrays, serialize() it and store that text in the database.

But if you take that approach, you are ultimately selling yourself/employer/clients short. Later if you need to go back and see who received a specific message or see stats on messages received by dept, or whatever, you'd be pretty much helpless. Instead do like fenway said, add a recipients table. It only needs two or maybe 3 fields, message_id, recipient_id, and possibly status_id.

You'll need to use another database such as PostgreSQL if you HAVE to use arrays.
Link to comment
https://forums.phpfreaks.com/topic/32369-mysql-arrays/#findComment-150619
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.