1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to modify PHP MySQL Code to work with FLAT FILE

Discussion in 'PHP' started by kslokesh, Jan 25, 2009.

  1. #1
    I have PHP Pages for simple functions adding, editing deleting and listing the data from MySQL Database Table. It uses a single table and the approximate entries may go up to a max. of 500 entries..

    So I want to use flat file for this purpose instead of mySQL DB..
    SEMrush
    Please help me by telling me what all should I modify in the PHP Code to make it work with Flat File.

    I dont know to code PHP and mySQL as I'm not a Programmer. I can understand a bit of the PHP code..

    I need the script for a website made for an local organization for making "member details" table which has around 300 members.

    Such script will also be useful for a page I have on my site to list the addresses of the people who send me SPAM. I need the PHP Script to write on this page also. I have used PHP and Flat File for this page using the steps mentioned in the websites (designdetector and kryogenics) which can be checked using the links at bottom of that page.
    http://www.kslokesh.com/spammers/

    Please Help me..
     
    kslokesh, Jan 25, 2009 IP
    SEMrush
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Why would you want to swap an efficient and featured MySQL system for a less featured text-file system?

    Just wondering...
     
    Danltn, Jan 25, 2009 IP
  3. kslokesh

    kslokesh Well-Known Member

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Thanks Danltn... I know that MySQL is very efficient.. I had learnt DataBase very long back DBase4 and FoxPro in Windows 3.1 Version during school time..

    I want to use less featured version as I have few reasons:
    1) I need only basic functions for the Entries like Add, Edit, Delete.. If Possible the Search(Query) Feature also..
    2) If I use SQL, I need to backup the database separately (cPanel). If I move to different Host, I must change the settings, user names, database names if I dont get the similar username of current cpanel username as the databse uses username_databasename format.. If I use Flat File, I can just copy/paste the directory(folder).
    3) Number of entries is at most 500.. So Flat File can be used efficiently I think.
    4) Some times if any errors occur, I wont be able to fix or even recognize them as I dont know programming. So better to use Simple Flat File for Simple tasks..
    5) If there is any restriction of the Web Host that I can have a single SQL Database, as we use very low cost hosting. It would be better to have Flat File as the SQL DB can be used for some other purpose/work which really requires SQL and cannot be done with Flat File efficiently..

    So please help me how to do it..
     
    kslokesh, Jan 25, 2009 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    There is no so called direct conversion from Db->File system.

    You have to add atleast 3-4 lines of code for every mysql query.

    My Suggestion : Don't do it
     
    harrisunderwork, Jan 25, 2009 IP
    kslokesh likes this.
  5. Dennis M.

    Dennis M. Active Member

    Messages:
    121
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    I suggest you don't do it as well, it's very insecure to be completely honest. For security, purposes may be better to just make the simple change if you must to change hosts.

    However, if you MUST do this, you'll have to do a system of fread and fwrite to add/remove. But to do this you'll need to CHMOD 0777 meaning anyone can view, etc. If you give me a few more specifics of what you're looking for I'll help you write the script further.

    Some help though: fwrite to the end of the file for each new entry and to search you should load the data file into a variable as an array and you can use the in_array(); function to do more!

    To get this data out into standard text form I suggest you look into PHPMyAdmin's export methods. For example, try Micro$oft Word document and uncheck structure perhaps.

    Regards,
    Dennis M.
     
    Dennis M., Jan 25, 2009 IP
    kslokesh likes this.
  6. kslokesh

    kslokesh Well-Known Member

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #6
    Thanks Dennis M. I need a PHP Script to:

    Add/Edit/Delete/List the data from 12 input boxes to a Flat File and 3 TextAreas to 3 Separate Files..
    OR
    Add/Edit/Delete/List the data from 15 Form Inputs to a Single File (each record gets stored into single file)..

    I need this for storing the member details (name, phone, address, etc.) for an organization in my locality. They want to have their shops listed on the website.

    There is no security/privacy issue as it holds only Non Electronic Addresses and no sensitive data.. But it should be modified only from us.. Let anyone see it, no problem..

    At present I'v used "PHP Generator for MySQL" and "PHP Database Wizard" for that purpose..

    I want to try Flat Files also.. I have made a page to list spam email senders which uses Flat File. I need a script to do the Add/Edit functions for that also..
     
    kslokesh, Jan 25, 2009 IP
  7. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I would really avoid changing. Instead, you can use php to backup your database to avoid going into cPanel daily. Try this out...

    
    shell_exec( 'mysqldump DATABASE --user='.$database_user' --password='.$database_pass.' --opt > /path/to/backups/sql_dump.'.date("Ymd").time().'.sql' );
    
    Code (markup):
    Replace certain things like DATABASE with your database and so forth and the path/to/backups to a folder on your server. Make sure you make this random and password protect it with htaccess. If your on Windows, in place of mysqldump DATABASE you need path/to/mysqldump.exe DATABASE.
     
    xxKillswitch, Jan 26, 2009 IP
    kslokesh likes this.
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    If you don't have access to command line, try this for a MySQL -> Delimited values converter (e.g. tsv, csv.)

    http://php.fm/sql-to-delimited

    Dan.
     
    Danltn, Jan 27, 2009 IP
    kslokesh likes this.