Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

What are the best practices around creating flat-file database structures in PHP?

A lot of the more mature PHP flat-file frameworks I see out there attempt to implement SQL-like query syntax, which is over the top for my purposes in most cases (I would just use a database at that point).

Are there any elegant tricks out there to get good performance and features with a small code overhead?

1 Answer

0 votes
by (40.7k points)

If the userprofiles built as such, then use the below code:

$user = array("name" => "dubayou", 

              "age" => 20,

              "websites" => array("","",""),

              "and_one" => "more");

To save or update the DB record for that user, use the below query:

$dir = "../userdata/";  //But, make sure to put it bellow so that the server can reach.


To load the record for the user, you can do this:

function &get_user($name){

    return unserialize(file_get_contents("../userdata/".$name));


But, the above implementation will vary on the application and nature of the database according to your needs.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 26, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 11, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories