0

So one of my columns in my table has values like this

a:2:{i:0;s:6:"Subbed";i:1;s:6:"Dubbed";}

Right now it's stored as longtext and I've heard that varchar is faster than longtext if you're going to query it often.

So I have two questions, can values like this be stored as varchar and how do I retrieve these values as an array in php like ["Subbed, "Dubbed"].

How do I insert values like this if I have something like ["Subbed", "Dubbed"] and I want a:2:{i:0;s:6:"Subbed";i:1;s:6:"Dubbed";} .

Finally, is this something like a stringified array?

10
  • 1
    you should look at db normalisation, this is not the ideal storage strategy Commented Jul 1, 2014 at 20:28
  • 2
    Is there a particular reason you aren't doing this in a normalized way? You are violating 1NF with this structure which typically is not good. Commented Jul 1, 2014 at 20:28
  • How does your title match your question? Commented Jul 1, 2014 at 20:28
  • 1
    Your first problem is that your data is not held correctly. You should not have multiple values saved in a single column. They should each have their own. As far as the difference between LONGTEXT and VARCHAR, yeah, LONGTEXT is a really bad idea. Commented Jul 1, 2014 at 20:29
  • Also, in this stage, I wouldn't worry about the field type. I don't think the field type shouldn't matter that much. Also note that varchar has serious limits. The total record size in MySQL can be 65535 bytes at most, which is about 21000 characters if you have a UTF-8 VARCHAR field. This is total per record, so all fields combined. LONGTEXT is stored separately and doesn't have this limit. Commented Jul 1, 2014 at 20:29

1 Answer 1

1
  1. See this question: MySQL: Large VARCHAR vs. TEXT?

  2. It's the format used by serialization functions in php! You get to learn stuff every day. Check the PHP documentation.

Sign up to request clarification or add additional context in comments.

12 Comments

write a parser !?!? lol serialize was used so um use unserialize php.net/manual/en/function.unserialize.php
I wasn't familiar with the serialization function of PHP, thank you for the link, and glad I could make you laugh...
7k rep and you have never encountered one of the basic php functions come on dude :-)
I never had to use them. And as you may see, my rep isn't solely based on php. Hopefully I'll get a badge for it some day though, I'm getting there with everyone's help.
@didierc I am not going to be using wordpress any more. I am taking the data and remodeling it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.