0


i'm a beginner in php..
last night i finished my first full site script
but i didn't use any MySQL databases at all
i used to serialize to store the data as an array in file
then when i want to retrieve it.. i simple load that file into variable
and unserialize it so it becomes an array with data


say this code as an example:

  <?
  //saving
  $data_array = array('name' => 'John','user-name'=>'shotgun','birth'=>'April');
  $data_array=serialize($data_array);
  file_put_contents('data.ser', $data_array);

  //calling back and printing
  file_get_contents('data.ser');
  $data_array=unserialize($data_array);
  print_r($data_array);
  ?>



i know there's absolutely no pros. with this method
but what are the cons. ?

Alex C.
  • 4,021
  • 4
  • 21
  • 24
  • [Configuration storage setup file vs. db](http://stackoverflow.com/questions/4997706/configuration-storage-setup-file-vs-db), [File vs database for storage efficiency in chat app](http://stackoverflow.com/questions/6314665/file-vs-database-for-storage-efficiency-in-chat-app) – air4x Sep 24 '12 at 08:32
  • stroing data to database will more sutailbe – StaticVariable Sep 24 '12 at 08:35

3 Answers3

0

Besides doing IO to the hard disk, I don't see any cons to your approach. Using a MySQL database will be better for more complex situations though. E.g. ones where you don't need to read the whole list of entries to get the one you want. If you were to not use databases but static files you would need to read the entire file into the memory, iterate through it until you find whatever you are looking for and then close it, which is unnecessary overhead.

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
0

Cons. for not storing into a database:

  • HDD I/O
  • not searchable
  • hard to maintain if programmers change
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
0

One major problem is that you have complete forgotten that you run PHP from a server and that your app must handle concurrent connections.

JvdBerg
  • 21,777
  • 8
  • 38
  • 55