易截截图软件、单文件、免安装、纯绿色、仅160KB

Berkeley 5.0.21提供的PHP扩展的Bug

今天装了个Berkeley 5.0.21进行测试。
顺利编译了自带的php_db4模块后,进行测试。发现del操作报错:
illegal flag specified to DB->del
<?php
dl('db4.so');
$db = new Db4();
$db->open(null, 'info.db', 'info');
$db->put('key', 'value');
var_dump($db->del('key'));
$db->close();
$db->del的返回值是22。也就是参数错误。
之前没接触过BDB,也不知道正不正常。但怀疑是不是因为php是支持4.x系列的,因此进到php模块的代码看了一下。
php的del的实现很简单:
/* {{{ proto bool DB4::del(string $key [, object $txn])
*/
ZEND_NAMED_FUNCTION(_wrap_db_del)
{
DB *db = NULL;
DB_TXN *txn = NULL;
zval *txn_obj = NULL;
u_int32_t flags; // 出错行:未初始化!改为 u_int32_t flags = 0;
DBT key;
char *keyname;
int keylen;
getDbfromThis(db);
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|O", &keyname, &keylen,
&txn_obj, db_txn_ce) == FAILURE)
{
return;
}
if(txn_obj) {
getDbTxnfromThis(txn);
flags = 0;
}
memset(&key, 0, sizeof(DBT));
key.data = keyname;
key.size = keylen;
RETURN_LONG(db->del(db, txn, &key, flags));
}
/* }}} */
因为我没有传递txn对象,因此txn_obj判断为false,出错原因就很简单了:
flags没初始化。
看起来低级错误谁都会犯。
修正后测试正常。


相关文档:

学习php Reflection(二)

(4)映射类(ReflectionClass)
ReflectionClass类允许你反向映射类。
<?
php
interface MySerializable  
{    
// ...}
class My
Object
 
{    
// ...}
/** A counter class */
class 
Counter 
exten ......

如何在PHP中创建数组

原文链接:http://www.phpdo.net/index.php/20100409/54.html
如何在PHP中创建数组呢?
在PHP中使用array函数来创建一个数组,它允许一定数量用逗号key=>value参数。Key可以是integer或者string类型,value可以是任何值。
例如:
 <?php
 $array = array(“php1″=>”phpdo”, ......

php Mod rewrite test

In the directory where you plan to install Elgg, do the following:
Create the file .htaccess and add these two lines
RewriteEngine on
RewriteRule ^testing.php$ modrewrite.php
This tells the webserver to load modrewrite.php when testing.php is
requested.
In order to get this test to work on ......

[转]用PHP的ob_start();控制您的浏览器cache!


Output Control
函数可以让你自由控制脚本中数据的输出。它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况。输出控制函数不对使用
header()

setcookie(),
发送的文件头信息产生影响
,
只对那些类似于
echo()

PHP
代码的数据块有作用。
我们先举一个简单的例子,让大家对 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号