Dynadot โ€” .com Registration $8.99

PHP Basic Help

Spaceship Spaceship
Watch

abc123ben

Established Member
Impact
2
I am currently reading from the PHP and MySQL 2nd Edition Dummies book. And I am kind of stuck on what this means. I seem not to understand it. Any help greatly appreciated. On the book, I am on page 57, and on the section about Variable-length format. It says:

"In this format, MySQL stores the string in a field that is the same length as the string. You still specify a length for the string, but if the string is shorter than the specified length, MySQL only uses the space required rather than leaving the extra space empty. If the string is longer than the space specified, the extra characters are not stored."

OK. So basically, what I think this means is that for instance if the field is specified with a length of 10. If the string is shorter than the specified length, MySQL ignores the extra space required, and uses the string as it is. If the string is longer than the specified space, the extra characters aren't stored.

Well, if that's true, its kind of the same like a fixed-length format, but oh well. If it isn't, please could you correct me. Thanks.

Ben.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Yup i think you got it.

So if my field has a limit of 10 characters and i enter 5, then it will only store 5 characters and leave the otherrs blank.

If i enter 15 characters though... it will only store the first 10 and cut off the rest.

Just common sense really ;) MySQL isn't out there to confuse you, most of its using your initiative. Good luck with PHP!
 
0
•••
thanks :) understand it now :)
 
0
•••
np's :)
 
Last edited:
0
•••
beaver6813 said:
Yup i think you got it.

So if my field has a limit of 10 characters and i enter 5, then it will only store 5 characters and leave the otherrs blank.


Actually no it is not saying that. The quote states that if the string is shorter than the specified length then the memory used by that field will be the length of the string.

Some types will allocate the maximum memory in the database even if it is empty others will only allocate the used space. This may seem like a trivial difference but if you have a large database it can make a huge amount of different if you are using more space than is required.
 
0
•••
Right...there should be no padding characters if you are under the MySQL limitation(s).
 
0
•••
It's all a matter of speed vs. size. I believe that fixed length strings are slightly quicker to work with as MySQL knows how to 'jump' through the rows instead of having to find the length of each field and go through it that way. I know, it's a really simplistic description but hopefully you get the idea.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back