平面文件数据库 [英] Flat File Databases

查看:98
本文介绍了平面文件数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关在PHP中创建平面文件数据库结构的最佳做法是什么?很多更成熟的PHP平面文件框架,我看到尝试实现类似SQL的查询语法,这是超过了我的目的在大多数情况下(我只是使用一个数据库在那一点)。

What are your 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 the small code overhead one would want by taking on this problem in the first place?

推荐答案

那么,平面数据库的性质是什么。它们是大还是小。它是简单的数组与数组在其中?如果它的东西简单说userprofiles像这样构建:

Well, what is the nature of the flat databases. Are they large or small. Is it simple arrays with arrays in them? if its something simple say userprofiles built as such:

$user = array("name" => "dubayou", 
              "age" => 20,
              "websites" => array("dubayou.com","willwharton.com","codecream.com"),
              "and_one" => "more");

并保存或更新该用户的 db记录 p>

and to save or update the db record for that user.

$dir = "../userdata/";  //make sure to put it bellow what the server can reach.
file_put_contents($dir.$user['name'],serialize($user));

并为用户加载记录
$ b

and to load the record for the user

function &get_user($name){
    return unserialize(file_get_contents("../userdata/".$name));
}

但是这种实现会根据应用程序和您需要的数据库的性质。

but again this implementation will vary on the application and nature of the database you need.

这篇关于平面文件数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆