Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replacing database

    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...

    PHP Code:
    $line fgets ($h4096); 
    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:
    PHP Code:
    // 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?
    Last edited by stophon4; 05-16-2004 at 09:50 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    I presume you mean you want to use a text/csv file as your database, is that correct?

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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

    PHP Code:
    <?
    $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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Kool, that's a much easier way to do it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •