Solved

Simple time reservation site . . . . Can PHP use flat files?

Posted on 2009-05-05
8
232 Views
Last Modified: 2013-12-12
I want to create a trivial page where visitors can enter simple info (reserving a date and time slot for my service - dog walking ! )
Without an SQL interfaced DB, can I save user info and selections in another way, say on a flat file?
I dont need GB of space. Is there a simple site web host? with domain registration? I need a trivial PHP page that need only remember dates my users want my service.
Ideas?
I do have an always-on machine. Could I link that to a domain, with some php and simple db?
Trivial?

0
Comment
Question by:beavoid
  • 4
  • 3
8 Comments
 
LVL 4

Assisted Solution

by:bleach77
bleach77 earned 50 total points
ID: 24311131
1. Yes, you can save it in a flat file. Database are mostly use for big data for easier search.
   Use fread and fwrite function.

2. You can link the domain to your computer. Given that you have a fix IP. Otherwise you have to change the IP of your site everytime your IP change. But I guess it will be much more easier to use a hosting site as it does not cost a lot nowadays. You can google for a cheap hosting :)
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24312576
Try this sample code to get used to it.  I would however recommend a bit more advanced reading up on .csv plain text databases.  .csv are basicly plain text spread sheets that can be read by excel etc.  Reading and saving and updating CSV format is much easier in the long run than coming up with your own format for your text files.

PHP has functions for managing csv files... just try a Google search for some tutorials and you will be up and running really fast.

Also Bleach is right - there are good reasons to use a web host - not just very cheap but also they manage uptime, security and etc for you so you don't need to worry about it.  It's probably the best idea for serving a website as the service is more high tech and safer than serving from your own home or office in most circumstances.
$file = "full/path/to/your-text.txt";
 
$fp = fopen ($file,"r"); //open file for reading
$Data = fread($fp,filesize($file));  // read data save as $Data variable
fclose ($fp);
 
$fp = fopen ($file,"w+"); //open file for writing (and create the file if it not exists!)
fwrite($fp,$Data));  // save data to the file
fclose ($fp);

Open in new window

0
 

Author Comment

by:beavoid
ID: 24370831
Where will $file reside?
In the site's file directory, with the PHP files?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24375123
Hi,

$file = "full/path/to/your-text.txt";

- The file can be wherever you want it to be *inside* your web directory... it could be along side your php files but it might be better to create another sub folder - perhaps "data/myfile.csv" or similar.

Cheers!
0
 

Author Comment

by:beavoid
ID: 24381310
So, i I get a google web-space, this file should be right there with index.php?
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 450 total points
ID: 24387060
Yes you can put it there if you like so long as wherever you put it, it must match the path in your code :)
0
 

Author Comment

by:beavoid
ID: 24400883
Would you go for the tab spaced simple .txt DB for a trivial site like this?
I havent used .csv yet and the .txt should be fine.

I know all about CS 200 whitespace DB's

Does the $data up there return the entire file specified?
How do I delimit the  $data  tokens?
0
 
LVL 3

Accepted Solution

by:
NIPPLES earned 450 total points
ID: 24401449
Hi there,

CSV is plain text - just with delimiters.  A standard CSV will use something like...

"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"

You can also use a tab as the delimiter... to work with tabs in PHP they are similar to new lines ...

/r/n = new line
/t = tab

Finally yes, in the example above, $data variable contains the entire files text.  For much larger text files you may want to use a recursive file read with a buffer, maybe something like...


$CompleteData = "";
$ConnectionString = "path/to/your/file.txt";
 
$handle = @fopen($ConnectionString, "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 9096);
	$CompleteData .= $buffer;
    }
    fclose($handle);
}
print $CompleteData;

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using javascript confirmation for a delete in mysql 5 31
javascript: add id amounts 5 47
showing loader for php/mysql/ajax live search 13 26
Decrypt string by php 7 31
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question