Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    5

    Lightbulb Unanswered: Using a plain text database, to include several fields on a page.

    I need to build a small but powerfull system, that could include (from only one or two files, plain files) to the site.

    Im going to use PHP.

    The problem is.. (im going to use the function: INCLUDE) but!... how can i include only a part of the plain text file? (lets call it DB).

    Well, how can i include a part of the db, to a part of the site?

    Example:

    Hardware (a section of the site!)
    Dimms (a subsection)

    Table:

    1 (id of the file) Price: 10 dollars | Comment: good dimm!
    2 (id of the file) Price: 30 dollars | Comment: this one rocks!


    And so on...

    So.. thats the website table.. but what about the php config at the table? (includes and that) and what about the plain db!?...

    I dont know what kinda file extension use for the db..

    .DAT ? .TXT ? or another one? like .DB or dunno.. some kinda invention for the site.. hehe (cause its gonna be a plain file inside... so.. i think i could change the extension) .R ? for example?....

    Dunno! im just wondering!...
    And i need some help here, i need to finish this so bad!!

    I hope some one could help me... i will help with the things i can at another section of the forum.. or this one too. why not?.

  2. #2
    Join Date
    Sep 2003
    Location
    ventura,ca,us
    Posts
    8
    From what I can understand from your post, you want to use a flat file to include values into your PHP script. You wouldn't want to include() but rather a combination of fopen() and fread() or file() to read in the contents of the flat file and then you can decide what data to use from there. Using include() just indiscriminately grabs the entire file, no way around it.

    Normally the file is just a plain text file, so db.txt would work fine.

    The other way to do it, a method I much prefer, is to use a DB server like MySQL or Postgresql.

  3. #3
    Join Date
    Sep 2003
    Posts
    5
    Originally posted by bdl
    From what I can understand from your post, you want to use a flat file to include values into your PHP script. You wouldn't want to include() but rather a combination of fopen() and fread() or file() to read in the contents of the flat file and then you can decide what data to use from there. Using include() just indiscriminately grabs the entire file, no way around it.

    Normally the file is just a plain text file, so db.txt would work fine.

    The other way to do it, a method I much prefer, is to use a DB server like MySQL or Postgresql.


    Ah yeah.. but i cant use any db server like those ones.. i cant use db servers for this project.

    So.. how can i fopen() or fread() or file() ? could you send me some help?

    Thanks for your reply!!

    PS: How can i know wich part of the file to add at a table?.. i mean.. i need some ID for a product... like: ID:33420 and then at the flat file (with several lines) the price comment img url, etc...

    like:

    ID:12340
    Name of the product: DIMM128mb
    Price: $20 dollars
    Comment: GOOD DIMMS GOOD ONES!
    IMG url: http://www.myimgurl.net
    .................................................. ...........
    ID:12341
    Name of the product: DIMM256mb
    Price: $40 dollars
    Comment: GOOD DIMMS GOOD ONES!
    IMG url: http://www.myimgurl.net
    .................................................. ...........

    And so on....

    i think i need an id for a line.. like:

    .................................................. ...........
    ID:12341 Name of the product: DIMM256mb
    ID:12342 Price: $40 dollars
    ID:12343 Comment: GOOD DIMMS GOOD ONES!
    ID:12344 IMG url: http://www.myimgurl.net



    Or something like that.... nope?
    Just wondering
    Last edited by gushh; 09-05-03 at 01:42.

  4. #4
    Join Date
    Sep 2003
    Location
    Wisconsin, USA
    Posts
    34
    You're basically talking about creating your own DB server in PHP, with a flat file data storage backend ...

    This is going to be very difficult and probably very slow. (Pages take a long time to load.) Honestly, I don't think you could make it work with any large amounts of data.

    Why exactly can't you use a real DB server? If your host doesn't provide one, chances are that your PHP code running on their server can connect to a real DB running on a different server (on a different host.)


    I'm not trying to be mean in any way, so please try to not take this personally. But if you are having difficulties with built-in commands like fopen() and fread() (which have php manual entries at http://www.php.net/manual), you're probably not up to the necessary level of expertise to create something like this. (Which, as I said before, I think is a bad idea to begin with.)

    Honestly, were it me, I would do everything I possibly can to connect to a real DB, and if I couldn't, I'd deem it "Not reasonably possible."


    However, I always try to help, so here goes...

    What you need to do is write your data into a Comma-Seperated Values format like this:

    12340,DIMM128Mb,20,GOOD DIMMS GOOD ONES!,http://www.myimgurl.net
    12341,DIMM256Mb,40,GOOD DIMMS GOOD ONES!,http://www.myimgurl.net

    Then you can just use fgetcsv() to bring your data into an array. Using that built-in function will be a lot faster than anything you could write yourself (because it's built-in), and will make your coding job a lot easier.

    Of course, you'll have to parse any input & replace the commas with something else, like "^", and then when you read the data back in, replace all the "^"'s with commas again.


    But you'll have to read the manual & help sites for how to do this. Hope this puts you in the right direction.

  5. #5
    Join Date
    Apr 2004
    Posts
    1
    Originally posted by moku
    You're basically talking about creating your own DB server in PHP, with a flat file data storage backend ...

    This is going to be very difficult and probably very slow. ...
    That's of course true. Nevertheless, there might be situations where you _need_ a text database system. And that's why I created one. So, you might want to check out

    mUps -- A mUlti-Purpose Text Database System For PHP
    http://www.fam.tuwien.ac.at/~schamane/sysadmin/mups/

    HTH,

    --
    -- Andreas

Posting Permissions

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