CodeCanyon

Data File

  • Has been a member for 2-3 years
  • Exclusive Author
  • Bought between 10 and 49 items
Ruttyj says

Hello, wow first comment… just to let you know you might want to fix your strip_tags() on the demo… it doesn’t seem to be working

2 years ago
Author
betterphp betterphp replied

that’s because i forgot my test server has magic quotes enabled…

thanks for telling me

2 years ago
Author
betterphp betterphp replied

can I also point out, that you are not buying a comments system, so breaking the page and telling me I need to do more work on it is not that helpful.

2 years ago
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
JeffT says

I kinda like this idea. Just out of curiousity…are the methods accessing the file separately each time, or is it kinda like a DB where you’re constantly connected?

Just trying to see if you’ve tested this out on large amounts of data. I can see a huge benefit versus a database as it relates to backup, as I could just backup flatfiles versus having to restore a database…

2 years ago
Author
betterphp betterphp replied

the data is read from the file when you first create the object, $data = new data_file(‘something’); and only written to the file when you call the commit method.

all the other functions just work with the array which is kept in memory.

I have tested it with 1000 entries in the comments example and it still performs the same as with 10 entries in terms of speed. This test was done on my local server which never has a load average about 0.02 so I’m not sure how this will translate to a real world test.

Ill post some speed test results now actually, probably worth advertising that in some cases its faster than mysql anyway.

2 years ago
Default-user JeffT replied

Definitely. I’ve always been a advocate of grabbing data and manipulating it server-side anyway. A relevant suggestion might be to create some cool “select” methods, to really compete with database queries. Especially stuff like grouping, min/max, etc. Just a thought….

2 years ago
Author
betterphp betterphp replied

thinking about it, you could store an array of data and they use the php array_* functions to do most of the things that mysql allows.

2 years ago
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
JeffT says

Well yeah, that’s where I was going with it. It would just be a really cool bonus for people to save them even more time. That’s the main thing I see that a normal database would have over your server-side solution. Purchasing…

2 years ago
Author
betterphp betterphp replied

I guess that would make it easy to implement too,

thanks for purchasing, hope you like it.

2 years ago
  • Has been a member for 2-3 years
  • Bought between 100 and 499 items
altrano says
Purchased

hello a little question

why use in data_file class on line 21 double array_pop ??

array_pop($this->syspath); array_pop($this->syspath);

sorry this question i’m not so the hero in PHP . And sorry for my english.

2 years ago
Author
betterphp betterphp replied

to remove the last two elements from the array, one being empty and one being the current folder.

take that section of code and put it into a new file and experiment with commenting one array_pop and you should see the difference.

unfortunately array_pop will not take an argument of how many elements to remove from the end of the array so it has to be called twice, that got on my nerves at the time I wrote it too.

The whole point of that section of code is to give me a full base path to work from, to make it more portable,

2 years ago
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United States
  • Referred between 1 and 9 users
blazedd says

So is this just an abstraction or does this do anything more?

2 years ago
Author
betterphp betterphp replied

it does everything described in the documentation,

http://jacekk.co.uk/code/data_file/docs/class.data_file.html

because the system works mostly with arrays, and they are so easy to manipulate with PHP anyway I left it at the documented methods.

what further functionality are you looking for ?, I’m always open to suggestions and ideas for improvement.

2 years ago
  • Has been a member for 4-5 years
  • Bought between 100 and 499 items
dirty_den says

Great idea – from what i can gather a class/framework to deal with flatfile db manipulation, but to me the screen shot is ambigious with the mysql code and db connection details this looks like it should be for sql not flatfile. I would love to see something which is simple and can replicate the sorting methods etc of mysql in flatfile environment. To me I dislike sql for all but the most complex sites with much information. I think flatfile dbs are convenient and can simplify things a great deal which is good.

2 years ago
Author
betterphp betterphp replied

the sql example shows how you could store settings in a file for a mysql connection.

The reason I didn’t implement the select methods similar to sql, is that the system works with arrays which are quite easy to manipulate with php anyway, however this has been suggested a few times now so I will look into it.

are there any specific sql-like method you can think of,

at the moment im thinking of adding a select() function that will do some query like tasks, but id like to hear some other ideas.

2 years ago
  • Has been a member for 2-3 years
  • Bought between 10 and 49 items
  • United Kingdom
bakerman says

hi, I prefer flatfile database over mysql. I have tried many file database before, but my opinion is that they are all right till you have a small amount of data like your test.

Data File 10000 Inserts: 0.02156400680542 10000 Selects: 0.0066959857940674

MySQL 10000 Inserts: 0.90946888923645 10000 Selects: 0.042078018188477

What if you have , lets say 100000 selects? The file can be xx MB by then. Is it gonna be still faster than mysql?

Thanks

1 year ago
Author
betterphp betterphp replied

it should always be faster, when you first open the file all of the data is transferred to a php array (in memory) so SELECTS are basically getting a key from that array, very speedy :)

Its probably not a good idea to store huge amounts in the file, because you will run out of memory available to php eventually, that’s why I recommend you split the data into as many files as possible.

1 year ago
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 50 and 99 items
yenerich says
Purchased

If i have this: Array ( [0] => Array ( [name] => Jacek [email] => jacek@notreal.co.uk [msg] => testing message )

[1] => Array
    (
        [name] => Joe
        [email] => test@test.com
        [msg] => second testing message
    )
[2] => Array
    (
        [name] => Joe
        [email] => test@test.com
        [msg] => second testing message again !
    )

)

How can i remove, lets say, the whole [1] (Joe’s comment)? I want to be able to remove some comments, how can i do that? I dont want to remove some key of one comment, but the whole one. Can you help me please?

1 year ago
Author
betterphp betterphp replied

you can just do

unset($comments[1]);
1 year ago
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 50 and 99 items
yenerich says
Purchased

Thanks for you answer.

I did that, but i found this problem: i cant now the index number of the message i want to delete. Because now my first message its not one and i do not know how to obtain by programming that number.

Lets say now i have

[3] => Array ( [name] => Joe [email] => test@test.com [msg] => second testing message )

and

[5] => Array ( [name] => Joe [email] => test@test.com [msg] => second testing message )

How can i obtain the index number of the message i want to delete?

1 year ago
Author
betterphp betterphp replied

when you loop over the array you can do

foreach ($array as $index => $post){
   echo $post['email'];
}

inside that loop $index will hold the value of the current array element being used, so you could use that to add a delete link to your posts

foreach ($array as $index => $post){
   echo '<a href="?rm=', $index, '">Delete</a>';
}

then you can check for the $_GET[‘rm’] variable and remove the key its related to. Obviously you would have to make this available to only admins in some way, and stop it being used to just remove all of the posts.

Is that any help ?

1 year ago
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 50 and 99 items
yenerich says
Purchased

Yes!! You are the man!!

Thank you.

5 stars for you :)

ps: How can i give you a 5 star rating? I read its needed 3 votes, how can i vote?

1 year ago
Author
betterphp betterphp replied

You know, I have no idea haha. I never actually bought anything from this site. It doesn’t seem that obvious.

Your intention to give a good rating will do ;)

1 year ago
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
abrandlincoln says

hello, I’m in the need of a flat file db for a small game I’m making. I would like to store and commit the score and some basic user data(name,website,fav quote,selected avatar), as I have no php knowledge I was wondering if you have in mind adding more examples to the docs as they are now (for folks like me) too thin…

thanks!

4 months ago
Author
betterphp betterphp replied

I wasnt planning on it, but you can store pretty muchy anything, the user info example could be

$user_db = new data_file('user_info.dat');

// to store user info.
$user_db->add($username, array(/* an array of data to store */));

// to get it back
$user_db->get($username);

// this will return the array that was stored previously.

If you are only making one change you can call commit() after add(), if you are making lots it should be called after all of them.

4 months ago
abrandlincoln abrandlincoln replied

thanks for trying, I think i’ll stick with localStorage as js is more my thing.

4 months ago

by
by
by
by
by