SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    United Kingdom
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Flat-File Databases and PHP

    I would preffer to use mysql for my databases, but the server I'm on only allows me to use 5 of them, so I'm also going to need to use flat-file databases.

    I was wondering if anyone knows any good tutorials or code examples concerning this topic?
    No one is a virgin, life screws us all

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With a few functions you can easily read from a flat file database.

    file() takes one parameter (the file location) and will read each line in a file into a new array element

    $array = file("$url");

    $array[0] = row1
    $array[1] = row2

    and so on

    Next you'll want to split up each row into it's components.

    To do this use the explode function.

    $array= explode("|",$element);

    So here is what your script would look like that reads from your database: If your row's look like this:

    Chris|Male|Brown|Brown

    PHP Code:
    $url "http://www.domain.com/path/to/file/";
    $main_array file("$url");

    function 
    chop_up($element){
        
    $row_array explode("|",$element);
        
    $name $row_array[0];
        
    $sex $row_array[1];
        
    $hair_color $row_array[2];
        
    $eye_color $row_array[3];
    }

    array_walk($main_array'chop_up');
    //This Array Walk function will execute the function 'chop_up' once for each element in the array 
    Of course once you get your data out you can sort it and print it and all of that good stuff.


    On a side note there is no limit to how many tables you can have in one db, so why not simply combine 2 dbs?
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    The url below has some related info:
    http://hotwired.lycos.com/webmonkey/...x2a_page3.html

    As Aspen wrote, does that mean we can have 2 or more applications, or 2 or more different websites using the same database? That's great, but what are the security problems encountered?

    Johns

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As long as they are on the same server it makes no difference. They could even be on different servers and it'd work fine.

    When accessing a database MySQL doesn't care at all where the request is coming from, what it cares about is the username and password used. So a site about cats and a site about dogs can use the same database if they wanted to. Doesn't make much of a difference.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


Bookmarks

Posting Permissions

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