SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Flat-File Databases and PHP
-
Jul 8, 2001, 16:51 #1
- 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
-
Jul 8, 2001, 17:19 #2
- 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
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
-
Jul 8, 2001, 17:40 #3
- 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
-
Jul 8, 2001, 17:45 #4
- 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