开发者

Beginners PHP / mySQL question

I'm brand new to PHP & MySQL, and one function I'm creating needs to access a large table or database. I've created the database and it's currently in a MySQL table, which I'm accessing with no problem. The table is 11,000 rows in length, with 8 columns (all text less than 8 characters long) - it's static, and will never change. Without getting too particular, my users will hit a button which will trigger scripts to access the data, say 500 times or more. So in g开发者_JS百科eneral would it be better practice to include all of this data in a big 'switch' or 'if... then' conditional right in my scripts, rather than opening and accessing the database connection hundreds, or maybe even thousands of times? It just seems like that might be a bottleneck waiting to happen. Thanks!


Better to eliminate that 500-times access. Why do you need it? Usually we use a database to do any calculation with a single query


In your case I'd keep the database but load the entire contents into memory (array) at the start of the script. If you want to optimize later on you could use a very simple lazy loading scheme, reading a batch of data on requests. Perhaps there are hints on what rows may be requested. But keep it simple!


In reading your question, it seems like there might be lots of room there for computational improvement. It's rare that an application must do something so many times over such a large set of data.

However, one thing to note is that a database with 11,000 rows is, in fact, rather small. The whole sum of your data should be fairly insignificant (3 bytes [max] * 8 characters * 8 fields * 11,000 rows = ~2 mb). Consider pre-loading the database into memory before your program runs, and use that instead of direct database access. It should run much faster that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜