diff options
Diffstat (limited to 'ext/dba')
| -rw-r--r-- | ext/dba/dba.c | 33 | ||||
| -rw-r--r-- | ext/dba/php_dba.h | 1 | ||||
| -rw-r--r-- | ext/dba/tests/007.phpt | 40 |
3 files changed, 73 insertions, 1 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c index eed953b5c9..71f21ad4e7 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -52,6 +52,7 @@ function_entry dba_functions[] = { PHP_FE(dba_optimize, NULL) PHP_FE(dba_sync, NULL) PHP_FE(dba_handlers, NULL) + PHP_FE(dba_list, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -513,7 +514,7 @@ PHP_FUNCTION(dba_sync) } /* }}} */ -/* {{{ proto array dba_list() +/* {{{ proto array dba_handlers() List configured databases */ PHP_FUNCTION(dba_handlers) { @@ -534,6 +535,36 @@ PHP_FUNCTION(dba_handlers) } /* }}} */ +/* {{{ proto array dba_list() + List configured databases */ +PHP_FUNCTION(dba_list) +{ + ulong numitems, i; + zend_rsrc_list_entry *le; + dba_info *info; + + if (ZEND_NUM_ARGS()!=0) { + ZEND_WRONG_PARAM_COUNT(); + RETURN_FALSE; + } + + if (array_init(return_value) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array"); + RETURN_FALSE; + } + numitems = zend_hash_next_free_element(&EG(regular_list)); + for (i=1; i<numitems; i++) { + if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) { + continue; + } + if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) { + info = (dba_info *)(le->ptr); + add_index_string(return_value, i, info->path, 1); + } + } +} +/* }}} */ + #endif /* diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h index c1bc6f1dd0..832e66638c 100644 --- a/ext/dba/php_dba.h +++ b/ext/dba/php_dba.h @@ -95,6 +95,7 @@ PHP_FUNCTION(dba_fetch); PHP_FUNCTION(dba_optimize); PHP_FUNCTION(dba_sync); PHP_FUNCTION(dba_handlers); +PHP_FUNCTION(dba_list); #else #define dba_module_ptr NULL diff --git a/ext/dba/tests/007.phpt b/ext/dba/tests/007.phpt new file mode 100644 index 0000000000..82316cfd01 --- /dev/null +++ b/ext/dba/tests/007.phpt @@ -0,0 +1,40 @@ +--TEST-- +DBA Multiple File Creation Test +--SKIPIF-- +<?php + require_once('skipif.inc'); + if (!function_exists('dba_list')) die('skip dba_list() not available'); +?> +--FILE-- +<?php + require_once('test.inc'); + $db_file1 = dirname(__FILE__).'/test1.dbm'; + $db_file2 = dirname(__FILE__).'/test2.dbm'; + if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + echo "database file created with $handler.\n"; + } else { + echo "$db_file does not exist\n"; + } + if (($db_file1=dba_open($db_file1, "n", $handler))!==FALSE) { + echo "database file created with $handler.\n"; + } else { + echo "$db_file does not exist\n"; + } + if (($db_file2=dba_open($db_file2, "n", $handler))!==FALSE) { + echo "database file created with $handler.\n"; + } else { + echo "$db_file does not exist\n"; + } + var_dump(dba_list()); + dba_close($db_file); +?> +--EXPECTF-- +database file created with %s. +array(3) { + [%d]=> + string(%d) "%sext/dba/tests/test.dbm" + [%d]=> + string(%d) "%sext/dba/tests/test1.dbm" + [%d]=> + string(%d) "%sext/dba/tests/test2.dbm" +}
\ No newline at end of file |
