本文整理汇总了PHP中dba_insert函数的典型用法代码示例。如果您正苦于以下问题:PHP dba_insert函数的具体用法?PHP dba_insert怎么用?PHP dba_insert使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dba_insert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addcomment
function addcomment($m)
{
global $xmlrpcerruser;
$err = "";
// get the first param
$msgID = php_xmlrpc_decode($m->getParam(0));
$name = php_xmlrpc_decode($m->getParam(1));
$comment = php_xmlrpc_decode($m->getParam(2));
$dbh = dba_open("/tmp/comments.db", "c", "db2");
if ($dbh) {
$countID = "{$msgID}_count";
if (dba_exists($countID, $dbh)) {
$count = dba_fetch($countID, $dbh);
} else {
$count = 0;
}
// add the new comment in
dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
dba_insert($msgID . "_name_{$count}", $name, $dbh);
$count++;
dba_replace($countID, $count, $dbh);
dba_close($dbh);
} else {
$err = "Unable to open comments database.";
}
// if we generated an error, create an error return response
if ($err) {
return new xmlrpcresp(0, $xmlrpcerruser, $err);
} else {
// otherwise, we create the right response
// with the state name
return new xmlrpcresp(new xmlrpcval($count, "int"));
}
}
示例2: insert
/**
* Store a key/value. If the key already exist : error
*
* @param string $key the key
* @param string $value
*
* @return boolean false if failure
*/
public function insert($key, $value)
{
if (is_resource($value)) {
return false;
}
return dba_insert($key, serialize($value), $this->_connection);
}
示例3: run
function run()
{
global $wgExtensionMessagesFiles, $wgMessageCache, $IP;
$nameHash = md5(implode("\n", array_keys($wgExtensionMessagesFiles)));
$dir = "{$IP}/cache/ext-msgs";
wfMkdirParents($dir);
$db = dba_open("{$dir}/{$nameHash}.cdb", 'n', 'cdb');
if (!$db) {
echo "Cannot open DB file\n";
exit(1);
}
# Load extension messages
foreach ($wgExtensionMessagesFiles as $file) {
$messages = $magicWords = array();
require $file;
foreach ($messages as $lang => $unused) {
$wgMessageCache->processMessagesArray($messages, $lang);
}
}
# Write them to the file
foreach ($wgMessageCache->mExtensionMessages as $lang => $messages) {
foreach ($messages as $key => $text) {
dba_insert("{$lang}:{$key}", $text, $db);
}
}
dba_close($db);
}
示例4: add
public function add($k, $v)
{
if (dba_exists($k, $this->handle)) {
return FALSE;
}
return @dba_insert($k, $this->s->serialize($v), $this->handle);
}
示例5: addComment
function addComment($req)
{
$err = "";
// since validation has already been carried out for us,
// we know we got exactly 3 string values
$encoder = new PhpXmlRpc\Encoder();
$n = $encoder->decode($req);
$msgID = $n[0];
$name = $n[1];
$comment = $n[2];
$dbh = dba_open("/tmp/comments.db", "c", "db2");
if ($dbh) {
$countID = "{$msgID}_count";
if (dba_exists($countID, $dbh)) {
$count = dba_fetch($countID, $dbh);
} else {
$count = 0;
}
// add the new comment in
dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
dba_insert($msgID . "_name_{$count}", $name, $dbh);
$count++;
dba_replace($countID, $count, $dbh);
dba_close($dbh);
} else {
$err = "Unable to open comments database.";
}
// if we generated an error, create an error return response
if ($err) {
return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
} else {
// otherwise, we create the right response
return new PhpXmlRpc\Response(new PhpXmlRpc\Value($count, "int"));
}
}
示例6: buildPathCache
function buildPathCache($paths, $last, $cwd, $zcache)
{
$parentPaths = array();
$populated = array();
$old_db_line = false;
if (file_exists($cwd . '.patchwork.paths.txt')) {
$old_db = @fopen($cwd . '.patchwork.paths.txt', 'rb');
$old_db && ($old_db_line = fgets($old_db));
} else {
$old_db = false;
}
$tmp = $cwd . '.~' . uniqid(mt_rand(), true);
$db = fopen($tmp, 'wb');
$paths = array_flip($paths);
unset($paths[$cwd]);
uksort($paths, array($this, 'dirCmp'));
foreach ($paths as $h => $level) {
$this->populatePathCache($populated, $old_db, $old_db_line, $db, $parentPaths, $paths, substr($h, 0, -1), $level, $last);
}
$db && fclose($db);
$old_db && fclose($old_db);
$h = $cwd . '.patchwork.paths.txt';
'\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h);
rename($tmp, $h) || unlink($tmp);
if (function_exists('dba_handlers')) {
$h = array('cdb', 'db2', 'db3', 'db4', 'qdbm', 'gdbm', 'ndbm', 'dbm', 'flatfile', 'inifile');
$h = array_intersect($h, dba_handlers());
$h || ($h = dba_handlers());
if ($h) {
foreach ($h as $db) {
if ($h = @dba_open($tmp, 'nd', $db, 0600)) {
break;
}
}
}
} else {
$h = false;
}
if ($h) {
foreach ($parentPaths as $paths => &$level) {
sort($level);
dba_insert($paths, implode(',', $level), $h);
}
dba_close($h);
$h = $cwd . '.patchwork.paths.db';
'\\' === DIRECTORY_SEPARATOR && file_exists($h) && @unlink($h);
rename($tmp, $h) || unlink($tmp);
} else {
$db = false;
foreach ($parentPaths as $paths => &$level) {
sort($level);
$paths = md5($paths) . '.' . substr(md5($cwd), -6) . '.path.txt';
$h = $zcache . $paths[0] . DIRECTORY_SEPARATOR . $paths[1] . DIRECTORY_SEPARATOR;
file_exists($h) || mkdir($h, 0700, true);
file_put_contents($h . $paths, implode(',', $level));
}
}
return $db;
}
示例7: new_token
function new_token($consumer, $type="request") {/*{{{*/
$key = md5(time());
$secret = time() + time();
$token = new OAuthToken($key, md5(md5($secret)));
if (!dba_insert("${type}_$key", serialize($token), $this->dbh)) {
throw new OAuthException("doooom!");
}
return $token;
}/*}}}*/
示例8: db4_insert
function db4_insert($key, $val)
{
$binkey = bin4($key);
dbg_log("inserting key #{$key} in binary that's ({$binkey})");
$ret = dba_insert(bin4($key), $val, $GLOBALS['db']);
if ($ret === false) {
die('failed to insert');
}
return $ret;
}
示例9: newToken
function newToken($consumer, $type = "request")
{
$key = md5(time());
$secret = time() + time();
$token = new \OAuth\Token($key, md5(md5($secret)));
if (!dba_insert("{$type}_{$key}", serialize($token), $this->dbh)) {
throw new \OAuth\Exception("doooom!");
}
return $token;
}
示例10: set
public function set($key, $value)
{
// Store
if ($this->useCache) {
$this->cache[$key] = $value;
}
// Convert
$v = $this->encode($value);
// Write
if (dba_exists($key, $this->dbHandler)) {
$r = dba_replace($key, $v, $this->dbHandler);
} else {
$r = dba_insert($key, $v, $this->dbHandler);
}
return $r;
}
示例11: WRITE
function WRITE($hash, $overwrite = 0)
{
$key = $hash["id"] . "." . $hash["version"];
$ex = dba_exists($key, $this->handle);
if (!$overwrite && $ex) {
return;
}
$hash = serialize($hash);
if ($this->gz) {
$hash = gzcompress($hash, $this->gz);
}
if ($ex) {
$r = dba_replace($key, $hash, $this->handle);
} else {
$r = dba_insert($key, $hash, $this->handle);
}
return $r;
}
示例12: _swap
private function _swap()
{
$count =& $this->_count;
$disk =& $this->_disk;
/* freeing memory and dump it to disk {{{ */
$limit = $this->_limit;
if (memory_get_usage() / (1024 * 1024) <= $limit) {
return;
/* nothing to free-up, so return */
}
$limit -= $this->_threshold;
/* dump X megabytes to disk */
$wdata =& $this->_data;
end($wdata);
fwrite(STDERR, "Freeing " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n");
$i = $count;
while (memory_get_usage() / (1024 * 1024) >= $limit) {
if (--$i < 0) {
break;
}
$xdata = current($wdata);
if (!is_array($xdata)) {
prev($wdata);
continue;
}
$xkey = key($wdata);
fwrite(STDERR, "\t\tAttempt to free {$xkey}\n");
$serial = serialize($xdata);
if (!dba_insert($xkey, $serial, $this->_db)) {
dba_replace($xkey, $serial, $this->_db);
}
unset($wdata[$xkey]);
unset($xdata);
unset($serial);
$wdata[$xkey] = true;
prev($wdata);
$disk++;
}
dba_sync($this->_db);
fwrite(STDERR, "\tFreed " . ceil(memory_get_usage() / (1024 * 1024)) . "M " . time() . "\n");
/* }}} */
}
示例13: addcomment
function addcomment($m)
{
global $xmlrpcerruser;
$err = "";
// since validation has already been carried out for us,
// we know we got exactly 3 string values
$n = php_xmlrpc_decode($m);
$msgID = $n[0];
$name = $n[1];
$comment = $n[2];
$dbh = dba_open("/tmp/comments.db", "c", "db2");
if ($dbh) {
$countID = "{$msgID}_count";
if (dba_exists($countID, $dbh)) {
$count = dba_fetch($countID, $dbh);
} else {
$count = 0;
}
// add the new comment in
dba_insert($msgID . "_comment_{$count}", $comment, $dbh);
dba_insert($msgID . "_name_{$count}", $name, $dbh);
$count++;
dba_replace($countID, $count, $dbh);
dba_close($dbh);
} else {
$err = "Unable to open comments database.";
}
// if we generated an error, create an error return response
if ($err) {
return new xmlrpcresp(0, $xmlrpcerruser, $err);
} else {
// otherwise, we create the right response
// with the state name
return new xmlrpcresp(new xmlrpcval($count, "int"));
}
}
示例14: analyze
function analyze($filename)
{
if (file_exists($filename)) {
// Calc key filename::mod_time::size - should be unique
$key = $filename . '::' . filemtime($filename) . '::' . filesize($filename);
// Loopup key
$result = dba_fetch($key, $this->dba);
// Hit
if ($result !== false) {
return unserialize($result);
}
}
// Miss
$result = parent::analyze($filename);
// Save result
if (file_exists($filename)) {
dba_insert($key, serialize($result), $this->dba);
}
return $result;
}
示例15: dirname
<?php
require_once dirname(__FILE__) . '/test.inc';
echo "database handler: {$handler}\n";
if (($db_file = dba_open($db_file, "n", $handler)) !== FALSE) {
dba_insert(array("a", "b", "c"), "Content String 2", $db_file);
} else {
echo "Error creating database\n";
}