Cless Posted December 31, 2008 Share Posted December 31, 2008 Hmm, this may be difficult to explain, but I'll give it a shot. I have a table (hereby known as 'blehtable'), and one of the fields (hereby known as 'blehfield') looks sort of like this: "Username-Password-Email". When somebody registers, for example, it would have the value of something like "[email protected]" (except the password would be encrypted). Then, when called, I explode it using "-" (don't worry, I disallow the usage of "-" in usernames and such), as such: $array= explode("-", $blehfield); $username= $array[0]; $password= $array[1]; $email= $array[2]; ...which works fine. Now, the thing is: when I'm using where queries. If, for example, I wanted to use a query like: mysql_query("SELECT * FROM blehtable WHERE username='John'"); ...I couldn't. I would have to somehow call it from 'blehfield'. Basically, what I am wondering is, is there some sort of way which I could do so with the current method (other than using WHERE blehfield LIKE 'John-%' or whatever)? Thanks! Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/ Share on other sites More sharing options...
DarkWater Posted December 31, 2008 Share Posted December 31, 2008 Now, I just have a simple question. Why in the world would you do that when you could just have 3 separate fields? I cannot think of any good, logical reasons for it. You should NEVER EVER EVER create a field just to explode() it when the data could very well fit into distinct columns. Read up on database normalization. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726774 Share on other sites More sharing options...
Cless Posted December 31, 2008 Author Share Posted December 31, 2008 To improve speed. After running several tests, I have proven that, if you have less fields within a table, it does not take nearly as long to select or update the table. Seeing as my website consists of nearly 100,000 users, lag is becoming a concern, and therefore, I needed to optimize a bit. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726785 Share on other sites More sharing options...
DarkWater Posted December 31, 2008 Share Posted December 31, 2008 It's no optimizing when you make things slower. The 3 extra fields won't hurt you. And if your database tables are properly normalized, speed should not too much of an issue; it's likely a limitation of your server (if you're on shared hosting). MySQL operations are much, much faster than PHP. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726786 Share on other sites More sharing options...
Cless Posted December 31, 2008 Author Share Posted December 31, 2008 I did this with a lot of other fields too, reduced about 50 of them, and the site has been going a lot quicker since then. It is quite optimized (uses limits, indexes, and all that fun stuff). Seeing as getting a good server is difficult, I'm basically trying to make-do with what I have. I do have a dedicated server, just not an extremely good one. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726788 Share on other sites More sharing options...
DarkWater Posted December 31, 2008 Share Posted December 31, 2008 If you have that many fields in one table in the first place, you're probably doing it wrong. I'm telling you right now that MySQL is very fast if you use it correctly. By adding those hyphens and completely breaking normalization, you're making MySQL do MORE work than it has to by figuring out the wildcards when searching. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726790 Share on other sites More sharing options...
Cless Posted December 31, 2008 Author Share Posted December 31, 2008 I didn't mean that I cut down on 50 fields in one table. Anyway, I'll conduct some more tests. Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726791 Share on other sites More sharing options...
DarkWater Posted December 31, 2008 Share Posted December 31, 2008 I didn't mean that I cut down on 50 fields in one table. Anyway, I'll conduct some more tests. Good, you had me worried there for a second. @_@ But anyway, using PHP's string functions and having new arrays initialized for it just makes for messy coding and more work. How are you conducting your tests, btw? Link to comment https://forums.phpfreaks.com/topic/138956-database-arrays/#findComment-726792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.