Searching and Sorting: Need Advice on the Design.
Moderator: General Moderators
Searching and Sorting: Need Advice on the Design.
I have a wiki-kike project. It stores tens of thousands Vietnamese articles on a modified phpBB platform. For each article (equivalent to a post) there is a quadruple: post #, title, author, genre. I would like to be able to list them out in alphabetical order of titles or authors. How do I approach to it? Between flat file, database which way is more efficient?
I don't know what question to ask, but if you ask me question I will answer as best I know. I am a .NET programmer converting to php.
I don't know what question to ask, but if you ask me question I will answer as best I know. I am a .NET programmer converting to php.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Flat file over a database...
Depends...on what you mean by efficiency...
Programmer efficiency or code execution efficiency...
Obviously there is an overhead when using a database...compared to say writing a custom sort/search function...
However it is important to consider the following:
1) Is your code going to be executed in a distributed environment or will it be used by multiple users atthe same time.
2) Is programmer efficiency or project longevity more important than efficiency
If your writing an application in PHP using a SQL RDBMS like MySQL or SQLite is the obvious choice...why?
1) Your applications are 95% chance of being used concurrently
2) PHP, by it's very nature executes slowly...so using a RDBMS which is likely writen in C will carry out searching and sorting tasks much quicker than native PHP code
Unless you really know what you are doing, writing custom search/sort functionality, especially reading/writing is tricky...
For instance, you have to concern yourself with file locking, security, etc...
RDBMS like mySQL are designed to run in distributed environments...they can take advantage of RAID or whatever the latest rage is...they will maximize the use of hardware, which would be difficult to do on your own...
SQL code is likely very reliable and error free and SQL statements make more sense than custom filtering code depending on the language you write it in.
SQL is portable, whereas, your custom filtering code is not...if you write it in PHP and later decide to port to C...it's more difficult to port PHP to C code than it is to just copy the SQL statements to your C application.
SQL offers scalability...you can easily switch RDBMS from a single file, single user, super fast and efficient SQL engine like SQLite to a multiple user, security centric full blown RDBMS like MySQL or MSSQL in the blink of an eye...
Anyways...the answer should be obvious...use SQL don't bother writing your own custom search/sort/filter type functions...unless you absolutely have to...but ifyour using PHP as a language you don't need too
HTH
Cheers
Depends...on what you mean by efficiency...
Programmer efficiency or code execution efficiency...
Obviously there is an overhead when using a database...compared to say writing a custom sort/search function...
However it is important to consider the following:
1) Is your code going to be executed in a distributed environment or will it be used by multiple users atthe same time.
2) Is programmer efficiency or project longevity more important than efficiency
If your writing an application in PHP using a SQL RDBMS like MySQL or SQLite is the obvious choice...why?
1) Your applications are 95% chance of being used concurrently
2) PHP, by it's very nature executes slowly...so using a RDBMS which is likely writen in C will carry out searching and sorting tasks much quicker than native PHP code
Unless you really know what you are doing, writing custom search/sort functionality, especially reading/writing is tricky...
For instance, you have to concern yourself with file locking, security, etc...
RDBMS like mySQL are designed to run in distributed environments...they can take advantage of RAID or whatever the latest rage is...they will maximize the use of hardware, which would be difficult to do on your own...
SQL code is likely very reliable and error free and SQL statements make more sense than custom filtering code depending on the language you write it in.
SQL is portable, whereas, your custom filtering code is not...if you write it in PHP and later decide to port to C...it's more difficult to port PHP to C code than it is to just copy the SQL statements to your C application.
SQL offers scalability...you can easily switch RDBMS from a single file, single user, super fast and efficient SQL engine like SQLite to a multiple user, security centric full blown RDBMS like MySQL or MSSQL in the blink of an eye...
Anyways...the answer should be obvious...use SQL don't bother writing your own custom search/sort/filter type functions...unless you absolutely have to...but ifyour using PHP as a language you don't need too
HTH
Cheers
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US