开发者

Is a database the best choice to store data for my web app?

开发者 https://www.devze.com 2023-02-06 10:39 出处:网络
After I made this question I decided that it would be best to store data on my own server. The data is in a table with 100-500 rows and 12 columns. I am a newbie programmer currently develo开发者_如何

After I made this question I decided that it would be best to store data on my own server. The data is in a table with 100-500 rows and 12 columns. I am a newbie programmer currently develo开发者_如何学运维ping my first web app with JavaScript and PHP and I am looking for the best solution to store and retrieve this data. I have no needs to make complicated queries, I just need to retrieve each row of data based on the content in one of the columns.

I am considering a database for this purpose, however as I have no experience with databases I don't know if it is the best solution for my needs. When I get the content it is actually in CSV format so I don't know if it is better to just save it that way on my own server or saving it to a database. Then on client request I would tranform the data using PHP and send it as JSON.

  • Is a database the best solution for my web app? or should I stick to CSV files?
  • If a database is the best choice, could you please point me to a good tutorial, example or book to get started?

Thanks in advance.


Database is the best solution. If you are trying to pick out individual rows in the CSV file, there will be quite an overhead in parsing the whole file, just to get at a little piece of information. Databases on the otherhand are far more efficient at this, and will do it in a fraction of the time.

If you are using PHP, then the most common database to use is MySQL, and nearly every host will include this as standard.

Here is a nice tutorial to get you started, but google MySQL and PHP, and there is a huge amount of information on the web for you to get information. PHP and MySQL is very very popular, so there is a lot of info out there.


If this table of data is static or almost completely static (meaning you edit it manually once/week or something like that), a CSV is much simpler.

Once it gets more complicated than that, a database looks better as the situation gets more complex:

1) Multiple users will be reading and writing to/from this single table

2) This one table becomes 2 tables, then 5 tables, then 15 tables...


Unless you are good at parsing files I would stick to a database you can always import your csv files easily enough. As for a good tutorial just google mysql and the first 5 or so links should be more than enough to get you started.

--Edit--

Not to mention that PHP has a lot of really good built in functions for mysql database calls just look-up mysql_query and it's related functions on PHP.NET


I think if this is a mobile webapp you are looking at performance and how fast results are returned or script execution. I would definitely go with a database over a CSV file. Here is a Stack Question I think might help as well.


I'd stick with the database - especially if you've already built it. If you need to scale up, you'll see better performance. Also, if you need to start doing more complex things down the road, a database will have the flexibility to do more. It's no harder than dealing with CSV data (I'd say easier, but that's me) and you get the advantages of databases, even if you never need them. You'll always have the option.

As for importing the data, you can easily set up a script to read the .CSV file and insert it into the database. You could even set it up to run periodically. You upload a file with a specific name, and every few minutes you have a CRON job run a script to look for the file, import it to the database and then on success delete the file.

As for books, I'm fond of the O'Riley series - check out the book for your DBMS of choice. There are also loads of web tutorials on dealing with databases. PHP and MySQL are well covered. As a bonus, there are free, easy to set up tools like xamp that will run Apache/PHP/MySQL on your PC for convenient development.


I would use the SQLite database. It's the middleground between a CSV file and MySql. SQLite doesn't require you to have a server process running on your machine. Nothing to install. The SQLite database is a single file and you can save it wherever you like. Use PDO or if you are 5.3 use the new SQLite3 extension. DON'T use the sqlite extension, it will create old SQLite2 databases. SQlite2 has been deprecated for a while now. Oh yeah, a tutorial using PDO: http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html

0

精彩评论

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

关注公众号