I try to write the similarity of an online store in php (at the same time I teach), it is convenient to store data in CSV , about a thousand products, say such a format:

Артикул;Радиус;Фото;Вылет;Болты;Фирма;Гарантия;Склад;Цвет;Цена 1;16;1.jpeg;6;4;Yokohama;6;4;1;2999 2;16;2.jpeg;4;4;Yokohama;4;4;1;3999 3;17;3.jpeg;33;4;Bridgestone;33;4;1;4999 4;17;4.jpeg;34;5;Goddyyear;34;5;1;5250 5;15;5.jpeg;45;4;Medved;45;5;1;4456 

I read from the file like this:

 $f = fopen("file.csv", "rt") or exit("Ошибка загрузки базы данных!"); $header=fgetcsv($f,1000,";"); 

and further cycle. Tell me your opinion:

- Is it correct? It looks good, does not slow down.

- if it is more rational to use SQL, why? or no difference?

- Wouldn't such a method be loading the server much? or will SQL be easier?

  • I'm silent about Join-ax, процедурах,триггерах,функциях... And if you have millions of tables, how will you handle? Learn SQL, without it anywhere. - Vfvtnjd
  • @ Oleg_B, if the project is small and the visits are so-so, then you can leave. But with further growth DB still need. - zenith
  • 2
    @Vtvtnjd А если у вас миллионы таблицы , a good answer to the question about small projects. Files may be quite acceptable option. - alexlz

2 answers 2

I personally would be lazy. Just because any operation requires a detailed manual description of actions. @ YYY gave examples, but imagine that you need to delete everything with a radius of 16. Write a code for walking through the array and repacking it in a new one? And if the photos are not one, but an arbitrary number of goods? And if the goods are not a hundred, but ... However, this is already superfluous :)

Plus, minus :) such an approach is also in the fact that the more code falls on one action, the more potential points of glitches. Especially when scaling a project (no matter in which direction) or changes in data structures. Support for such a project can grow into a big problem.

In general, the summary: as long as it suits you personally - do what you want and do not ask anyone for advice. No one forces you to use SQL, moreover, there are cases when using files is much more efficient. But do not say that you were not warned :)

    To your question using this approach:

    • Write the code receiving the amount of goods along the radius;
    • Write the code receiving the amount of goods for the company;
    • Write the code that receives the average price of the goods for the company;
    • Write the receiving code of the 10 most
      expensive goods;
    • Mark up Yokohama goods by 2.3%;

    Etc. etc. And then perhaps it will become clear whether to leave such an approach, or use the database.