summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2005-10-02 20:32:17 +0000
committerMarcus Boerger <helly@php.net>2005-10-02 20:32:17 +0000
commit3e0c56aac26872198bd7098dda7ee7abbffae366 (patch)
tree3ada72a331bb693ad584dff6886acb74d7254fb4
parenta39841e57d04062269e98a0b69074f6515936267 (diff)
downloadphp-git-3e0c56aac26872198bd7098dda7ee7abbffae366.tar.gz
- Fix PDOException base
- MFH PDO::getAvailableDrivers() - Fix compiler warnings
-rwxr-xr-xext/pdo/pdo.c8
-rwxr-xr-xext/pdo/pdo_dbh.c22
-rwxr-xr-xext/pdo/php_pdo.h4
-rwxr-xr-xext/pdo/php_pdo_int.h2
4 files changed, 32 insertions, 4 deletions
diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c
index c965c87141..eb541dfdc4 100755
--- a/ext/pdo/pdo.c
+++ b/ext/pdo/pdo.c
@@ -42,7 +42,7 @@ ZEND_DECLARE_MODULE_GLOBALS(pdo)
/* True global resources - no need for thread safety here */
/* the registry of PDO drivers */
-static HashTable pdo_driver_hash;
+HashTable pdo_driver_hash;
/* we use persistent resources for the driver connection stuff */
static int le_ppdo;
@@ -317,7 +317,11 @@ PHP_MINIT_FUNCTION(pdo)
"PDO persistent database", module_number);
INIT_CLASS_ENTRY(ce, "PDOException", NULL);
- pdo_exception_ce = zend_register_internal_class_ex(&ce, php_pdo_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC);
+#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
+ pdo_exception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
+#else
+ pdo_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
+#endif
zend_declare_property_null(pdo_exception_ce, "errorInfo", sizeof("errorInfo")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
pdo_dbh_init(TSRMLS_C);
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index a066241aa0..d0a0953394 100755
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -823,7 +823,7 @@ static PHP_METHOD(PDO, getAttribute)
RETURN_LONG(dbh->error_mode);
case PDO_ATTR_DRIVER_NAME:
- RETURN_STRINGL(dbh->driver->driver_name, dbh->driver->driver_name_len, 1);
+ RETURN_STRINGL((char*)dbh->driver->driver_name, dbh->driver->driver_name_len, 1);
case PDO_ATTR_STATEMENT_CLASS:
array_init(return_value);
@@ -1062,6 +1062,23 @@ static PHP_METHOD(PDO, __sleep)
}
/* }}} */
+/* {{{ proto array pdo_drivers()
+ Return array of available PDO drivers */
+static PHP_METHOD(PDO, getAvailableDrivers)
+{
+ HashPosition pos;
+ pdo_driver_t **pdriver;
+
+ array_init(return_value);
+
+ zend_hash_internal_pointer_reset_ex(&pdo_driver_hash, &pos);
+ while (SUCCESS == zend_hash_get_current_data_ex(&pdo_driver_hash, (void**)&pdriver, &pos)) {
+ add_next_index_stringl(return_value, (char*)(*pdriver)->driver_name, (*pdriver)->driver_name_len, 1);
+ zend_hash_move_forward_ex(&pdo_driver_hash, &pos);
+ }
+}
+/* }}} */
+
function_entry pdo_dbh_functions[] = {
ZEND_MALIAS(PDO, __construct, dbh_constructor, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, prepare, NULL, ZEND_ACC_PUBLIC)
@@ -1075,9 +1092,10 @@ function_entry pdo_dbh_functions[] = {
PHP_ME(PDO, errorCode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, errorInfo, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, getAttribute, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(PDO, quote, NULL, ZEND_ACC_PUBLIC)
PHP_ME(PDO, __wakeup, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(PDO, __sleep, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
- PHP_ME(PDO, quote, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(PDO, getAvailableDrivers, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
{NULL, NULL, NULL}
};
diff --git a/ext/pdo/php_pdo.h b/ext/pdo/php_pdo.h
index c4b9c94c68..7f9b85ceb2 100755
--- a/ext/pdo/php_pdo.h
+++ b/ext/pdo/php_pdo.h
@@ -23,6 +23,10 @@
#include "zend.h"
+#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)
+#define can_handle_soft_dependency_on_SPL
+#endif
+
extern zend_module_entry pdo_module_entry;
#define phpext_pdo_ptr &pdo_module_entry
diff --git a/ext/pdo/php_pdo_int.h b/ext/pdo/php_pdo_int.h
index 3f35c99603..6bca408d54 100755
--- a/ext/pdo/php_pdo_int.h
+++ b/ext/pdo/php_pdo_int.h
@@ -24,6 +24,8 @@
/* Stuff private to the PDO extension and not for consumption by PDO drivers
* */
+
+extern HashTable pdo_driver_hash;
extern zend_class_entry *pdo_exception_ce;
PDO_API zend_class_entry *php_pdo_get_exception_base(int root TSRMLS_DC);
int php_pdo_list_entry(void);