php3-list | 199903
Date: 03/18/99
- Next message: Rasmus Lerdorf: "Re: [PHP3] pg_fetch_array()"
- Previous message: Kristian Köhntopp: "Re: [PHP3] Simple calendar functions"
- In reply to: James Coates: "Re: [PHP3] Simple calendar functions"
- Next in thread: pete collins: "[PHP3] shopcart w/o cookies"
- Reply: pete collins: "[PHP3] shopcart w/o cookies"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Sorry. I'm not being obstenate by refusing to use databases; I just don't
> want to get too far from the shallow end. Yet.
There is a misconception brewing here. It takes a lot more knowhow to use
flatfiles than it does to use a database. I know plenty of people who
could not read and parse a flatfile if their life depended on it who are
happily using SQL databases.
It is a lot easier to do:
mysql_connect($host,"","");
$result=mysql_query("select name,age from people where user_id=12");
$user = mysql_fetch_array($result);
echo $user[name];
echo $user[age];
than it is to do:
$fp = fopen($file,"r");
while(!feof($fp)) {
$line = fgets($fp,256);
list($id,$name,$age)=explode(":",$line);
if($id==12) break;
}
echo $name;
echo $age;
in this second case it would only work for trivial cases. If any of the
fields need to be able to contain the separator character then we have to
add code to handle that. And if we need to add records to the file, then
we have to worry about file locking. And deleting records is even harder.
You basically have to read in the entire file, lock it, remove the entries
from memory and then write out the entire file again. Whereas with a
database you would just do:
mysql_query("delete from people where user_id=12");
And with SQL you can perform much more complex queries that would take you
hours of coding to do with a flat file. For example:
mysql_query("select phone_number from people where eyes='blue' and
hair='blonde' and gender='female' and age > 16 and age < 35");
This also happens to be much more readable. Even extremely non-technical
people can read through such an SQL query and immediately understand what
it is doing.
-Rasmus
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>
- Next message: Rasmus Lerdorf: "Re: [PHP3] pg_fetch_array()"
- Previous message: Kristian Köhntopp: "Re: [PHP3] Simple calendar functions"
- In reply to: James Coates: "Re: [PHP3] Simple calendar functions"
- Next in thread: pete collins: "[PHP3] shopcart w/o cookies"
- Reply: pete collins: "[PHP3] shopcart w/o cookies"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

