View Full Version : Replacing database

05-16-2004, 10:45 PM
Aright, I am literally trying to replace a database with using php only, and I think I can do it, there is just a little bit of source code that I need that I dont know what to do for...

$line = fgets ($h, 4096);

I know that searches for the whole files one line at a time, but I need it to return what line it found it on...

And then I can just tell it to read the another line of a file, almost as if the username was the fgets and the one line would be the other file, not as good as a database but very close, and here is some more code used for reading the password file:

// opens a file and read some data
$fp = fopen("password.dat", "r");
$data = fgets($fp, $username_line);

// where are we ?
echo ftell($fp); // 11

So is that all I need?
and I will probably use base64 encrypting too, isn't that good enough for a replacement for a database?

05-17-2004, 12:18 AM
I presume you mean you want to use a text/csv file as your database, is that correct?

05-17-2004, 06:30 AM
unless the file is very big >100kb or so , you may be better off loading the file into an array , playing with it and resaving it

foreach($file as $k=>$v){
echo "this is line $k :: $v<br />";

/*change line 5*/
$file[5]= 'new data overwriting line 5'."\n";

$fp=fopen( 'password.dat' , 'w' ) ;
fputs( $fp , implode( '' , $file ) ) ;
fclose( $fp ) ;

note that the array returned from file() is indexed from 0 , so `line 1` is $file[0] etc

05-17-2004, 01:11 PM
Kool, that's a much easier way to do it ;)