Navigation
Poll
Would you be an active poster if Ron's Guide had a message board?


Total Votes: 62
Comments: 18 — View
Past pollsPoll idea?
Rate Ron's Guide
Rate our resource at Bigwebmaster.com
Flat File Databases
Learn how to store and retrieve information using PHP's built in file handling functions along with serialize and unserialize.

PHP is a very powerful language, even without the use of a database, but you can only go so far without the need to store and retrieve data. One way to do this is by using flat files.

A flat file is a .txt file used to store information on the server. Because the information is stored in a .txt file, it makes it easy for you to create, manipulate, and delete databases in seconds. There are many methods you can use to store data in flat files, but I've found serialize and unserialize to be the best.

serialize and unserialize are functions in PHP that are handy when you need to store information in flat files. serialize takes an array of data and generates a storable representation of that array. For example:

<?php
  $myArray 
= array('some','useless','information');
  
$data serialize($myArray);
  echo 
$data;
?>

The above code will output the following:
a:3:{i:0;s:4:"some";i:1;s:7:"useless";i:2;s:11:"information";}

If you haven't worked with serialize before, it probably just looks like a bunch of gibberish. However, within that gibberish is the information that was held in the array '$myArray'. See it?

unserialize does the opposite of serialize, it creates an array from a representation(the output of serialize). PHP takes what looks like gibberish above and changes it back into an array, which you can then use as you would a normal array.

Try testing out serialize and unserialize, just to get the hang of how they're used. When you think you have a handle on them, go on to part two.

« Previous [ 1 2 3 ] Next »
Discuss Tutorial: Flat File Databases 32 Comments
Comment by Ron on May 11, 2004, 12:28 am
Please post questions or comments about this tutorial below. Smile
Comment by David on May 11, 2004, 1:24 am
Thanks for finally finishing the tut ron, now i can start with flat file Cool
Comment by Ron on May 11, 2004, 1:42 am
Thanks for bugging me about it Tongue otherwise I might have never got it done Laughing
Comment by cube on Jul 12, 2004, 9:28 pm
this sounds pretty easy.. lemme try it
Comment by Adam on Jul 23, 2004, 5:28 pm
I don't get it...
Comment by dcool on Aug 22, 2004, 2:04 am
your tut is pretty cool it will help me build better scripts thanks
Comment by Insane on Sep 13, 2004, 6:38 am
great tut ron but i have a cuestion, can i pull out the 5 last data that i get in the info file. Undecided
Comment by Derek on Sep 15, 2004, 8:43 am
How could I make it echo html. I'm trying to ake it so I can add downlaods to my site easier and I want to try and make echo into the table. Any suggestions?
Comment by Derek on Sep 16, 2004, 2:30 pm
Ok I've figured it out after a little time and effort i got it thanks to this tutorial mainly and a few others that helped me with a few things but this one mainly got me my own self-made file db.
Comment by Umar on Sep 18, 2004, 4:48 pm
Crying Please Can U Help Me. PLZZZZ, i want to make a simple User System with Registration, Login, Edit Profile, Member's List, ForGot PassWord, Remember Me Check BOx and User's Secure Area, Database in a Flat File. Please, and if you can Contact me On MSN Umar_Maqsood@hotmail.com

Thank YOu. Very MUCH Crying

« Previous [ 1 2 3 4 ] Next »
Post a comment
Sorry, you must be a registered member to post comments.

If you would like to register, you can do so here.
If you already have an account, please login.