Jump to content

Archived

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

AncientSage

SQL syntax for an array?

Recommended Posts

Hello,

What is the SQL syntax for an array? I've been searching Google for the past hour, and other has turned up.

Additionally, if someone could tell me how to put like...more than one string into that array, thanks.

Share this post


Link to post
Share on other sites
Huh?  Perhaps you mean an IN clause? Could you give an example?

Share this post


Link to post
Share on other sites
[code]
INSERT INTO config (config_name, config_value) VALUES ('allowed_file_ext', '{\.mid, \.mp3, \.wav, \.aiff}');
[/code]

Where {\.mid, \.mp3, \.wav, \.aiff} is supposed to be the array (each item in the array seperated by a comma), but I don't believe it is working as I want it to.


Share this post


Link to post
Share on other sites
Yeah, there is no such thing... if you're selecting some from a predefined set, you could use ENUM/SET, but it makes more sense to have one record per pair of name/value.  If that doesn't suffice, you'll need to insert some string that can be subsequently parsed, but that's not always better, and much harder to maintain.

Share this post


Link to post
Share on other sites
Try imploding the array into a single string value with some separator that won't cause you problems, and then exploding it when you pull it out of the database again.

Share this post


Link to post
Share on other sites
That will work, of course -- just consider the long-term implications (i.e. impossible to search properly, hard to edit, etc).

Share this post


Link to post
Share on other sites
My suggestion would be to keep the fields in the SQL table as distinct values (as opposed to parsing them into a delimited string). If you need to work with the values in an array within your php code, populate the array from the result of the query on the fly.

Share this post


Link to post
Share on other sites

×

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.