相关的函数
如下:
- dba_close —关闭dba数据库
- dba_delete —删除数据库中指定的key
- dba_exists — 检查key是否存在
- dba_fetch— 取得指定key的值
- dba_firstkey — 获取第一个key
- dba_handlers —列出所有可用的handler
- dba_insert— 插入一条记录
- dba_key_split— Splits a key in string representation into array representation
- dba_list — 列出所有打开的数据库
- dba_nextkey — 获取下一个key
- dba_open —打开数据库
- dba_optimize — 优化数据库
- dba_popen — 使用长链接打开数据库
- dba_replace —替换或者插入一条记录
- dba_sync — 数据库同步
使用实例
1、跟踪用户和密码
<?php
$user = $_SERVER[\'argv\'][1];
$password = $_SERVER[\'argv\'][2];
$data_file = \'/tmp/users.db\';
$dbh = dba_open($data_file,\'c\',\'gdbm\') or die(\"Can\'t open db $data_file\");
if (dba_exists($user,$dbh)) {
print \"User $user exists. Changing password.\";
} else {
print \"Adding user $user.\";
}
dba_replace($user,$password,$dbh) or die(\"Can\'t write to data $data_file\");
dba_close($dbh);
?>
<##ads_in_article_manong##>
2、对数据排序
<?php
$dbh = dba_open(\'users.db\',\'c\',\'gdbm\') or die($php_errormsg);
if ($exists = dba_exists($_POST[\'username\'], $dbh)) {
$serialized_data = dba_fetch($_POST[\'username\'], $dbh) or die($php_errormsg);
$data = unserialize($serialized_data);
} else {
$data = array();
}
if ($_POST[\'new_password\']) {
$data[\'password\'] = $_POST[\'new_password\'];
}
$data[\'last_access\'] = time();
if ($exists) {
dba_replace($_POST[\'username\'],serialize($data), $dbh);
} else {
dba_insert($_POST[\'username\'],serialize($data), $dbh);
}
dba_close($dbh);
?>
3、计算所有密码的总长度
<?php
$data_file = \'/tmp/users.db\';
$total_length = 0;
if (! ($dbh = dba_open($data_file,\'r\',\'gdbm\'))) {
die(\"Can\'t open data $data_file\");
}
$k = dba_firstkey($dbh);
while ($k) {
$total_length += strlen(dba_fetch($k,$dbh));
$k = dba_nextkey($dbh);
}
print \"Total length of all passwords is $total_length characters.\";
dba_close($dbh);
?> 继续阅读与本文标签相同的文章
-
任正非:华为不是家族企业,外籍人士也可以做华为CEO!
2026-05-14栏目: 教程
-
AI×5G,智能互联迎来发展新动能
2026-05-14栏目: 教程
-
Y5T289 Infinera今年ECOC推出点对多点相干光模块
2026-05-14栏目: 教程
-
快捷键只懂用复制粘贴?你该进修了,最全Excel快捷键合集
2026-05-14栏目: 教程
-
全网“云南旅游”相关搜索流量排名TOP100 全网“云南旅游”相关搜索流量排行榜
2026-05-14栏目: 教程
