Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP without a database 2

Status
Not open for further replies.

thumbelina

Programmer
Jun 4, 2001
58
CA
ok I know this is going to sound silly, but. All of my PHP experience is using MYSQL with it. Now I have access to php but not to any kind of server side database. I want to keep working with PHP but all the info I ever saw on it was with a database. So where can I find info on PHP uses without a database or maybe there is another way to use a database. Well I'm just looking for a few suggestions, anyone got any?
 
Well, it's true that not having an SQL database limits many of the things you can do with PHP, it's not the end of the world ;-). You just need to become more aware of PHP's file management functions, such as file(), fopen(), fgets(), fputs(), etc... and the many other data manipulation tools that come with PHP. This experience will actually make you a better programmer, by forcing you not to rely on databases to deal with every little piece of data.

For example, PHP can store and read data in plain text files with comma-delimited lists, so it's possible to get many of the features of a dynamic website, if you use these carefully. PHP even has a function specifically to open CSV files and parse for data fields (
Or you could use and save text files in the "keyword = 'value'" format.

And if you really want to handle data structures on the server without a database, you could learn PHP's built-in XML features. (usually PHP is installed with basic XML parsing nowadays)

Also, it's surprising what kind of data you can store away in serialized form in plain text files on the server. For example. You can store whole arrays, or even objects, in later versions of PHP, just by serializing them and saving the serialized data to a text file. Then when you need to read your data, you just fopen() the file, unserialize() the contents, and your array or object is available.

With all of these other approaches available, you might learn that databases aren't the answer to everything. Sometimes, you can actually do things more efficiently with these methods than with a database. For example, I use a database for user authentication on a very busy website, but once the user has logged in, I have a PHP class that instantiates the "$user" object, and saves the object information into a session variable. Thus, as the user browses around the site, I don't have to repeatedly query a table on the database for every page to have the personalized user information available.

HTH, have fun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top