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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.