...

View Full Version : Replacing database



stophon4
05-16-2004, 09: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?

litebearer
05-16-2004, 11:18 PM
I presume you mean you want to use a text/csv file as your database, is that correct?

firepages
05-17-2004, 05: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



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

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

/*resave*/
$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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum