diff options
Diffstat (limited to 'ext/pdo_mysql')
-rwxr-xr-x | ext/pdo_mysql/config.m4 | 58 | ||||
-rw-r--r-- | ext/pdo_mysql/mysql_driver.c | 47 | ||||
-rw-r--r-- | ext/pdo_mysql/mysql_statement.c | 64 | ||||
-rw-r--r-- | ext/pdo_mysql/pdo_mysql.c | 29 | ||||
-rw-r--r-- | ext/pdo_mysql/php_pdo_mysql_int.h | 2 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/bug_61207.phpt | 57 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/common.phpt | 2 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql___construct.phpt | 2 | ||||
-rw-r--r-- | ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt | 4 |
9 files changed, 111 insertions, 154 deletions
diff --git a/ext/pdo_mysql/config.m4 b/ext/pdo_mysql/config.m4 index d4c3745327..a2ba2fdbdd 100755 --- a/ext/pdo_mysql/config.m4 +++ b/ext/pdo_mysql/config.m4 @@ -4,8 +4,8 @@ dnl vim: se ts=2 sw=2 et: PHP_ARG_WITH(pdo-mysql, for MySQL support for PDO, [ --with-pdo-mysql[=DIR] PDO: MySQL support. DIR is the MySQL base directory - If mysqlnd is passed as DIR, the MySQL native - native driver will be used [/usr/local]]) + If no value or mysqlnd is passed as DIR, the + MySQL native driver will be used]) if test -z "$PHP_ZLIB_DIR"; then PHP_ARG_WITH(zlib-dir, for the location of libz, @@ -28,30 +28,21 @@ if test "$PHP_PDO_MYSQL" != "no"; then done ]) - if test -f $PHP_PDO_MYSQL && test -x $PHP_PDO_MYSQL ; then - PDO_MYSQL_CONFIG=$PHP_PDO_MYSQL - elif test "$PHP_PDO_MYSQL" != "yes"; then - if test -d "$PHP_PDO_MYSQL" ; then - if test -x "$PHP_PDO_MYSQL/bin/mysql_config" ; then - PDO_MYSQL_CONFIG="$PHP_PDO_MYSQL/bin/mysql_config" - else - PDO_MYSQL_DIR="$PHP_PDO_MYSQL" + if test "$PHP_PDO_MYSQL" != "yes" && test "$PHP_PDO_MYSQL" != "mysqlnd"; then + if test -f $PHP_PDO_MYSQL && test -x $PHP_PDO_MYSQL ; then + PDO_MYSQL_CONFIG=$PHP_PDO_MYSQL + else + if test -d "$PHP_PDO_MYSQL" ; then + if test -x "$PHP_PDO_MYSQL/bin/mysql_config" ; then + PDO_MYSQL_CONFIG="$PHP_PDO_MYSQL/bin/mysql_config" + else + PDO_MYSQL_DIR="$PHP_PDO_MYSQL" + fi fi fi - else - for i in /usr/local /usr ; do - if test -x "$i/bin/mysql_config" ; then - PDO_MYSQL_CONFIG="$i/bin/mysql_config" - break; - fi - if test -r $i/include/mysql/mysql.h || test -r $i/include/mysql.h ; then - PDO_MYSQL_DIR="$i" - break; - fi - done fi - - if test "$PHP_PDO_MYSQL" = "mysqlnd"; then + + if test "$PHP_PDO_MYSQL" = "yes" || test "$PHP_PDO_MYSQL" = "mysqlnd"; then dnl enables build of mysqnd library PHP_MYSQLND_ENABLED=yes AC_DEFINE([PDO_USE_MYSQLND], 1, [Whether pdo_mysql uses mysqlnd]) @@ -100,15 +91,15 @@ if test "$PHP_PDO_MYSQL" != "no"; then AC_MSG_ERROR([Unable to find your mysql installation]) fi - PHP_CHECK_LIBRARY($PDO_MYSQL_LIBNAME, mysql_query, + PHP_CHECK_LIBRARY($PDO_MYSQL_LIBNAME, mysql_commit, [ PHP_EVAL_INCLINE($PDO_MYSQL_INCLUDE) PHP_EVAL_LIBLINE($PDO_MYSQL_LIBS, PDO_MYSQL_SHARED_LIBADD) ],[ if test "$PHP_ZLIB_DIR" != "no"; then PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR, PDO_MYSQL_SHARED_LIBADD) - PHP_CHECK_LIBRARY($PDO_MYSQL_LIBNAME, mysql_query, [], [ - AC_MSG_ERROR([PDO_MYSQL configure failed. Please check config.log for more information.]) + PHP_CHECK_LIBRARY($PDO_MYSQL_LIBNAME, mysql_commit, [], [ + AC_MSG_ERROR([PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information.]) ], [ -L$PHP_ZLIB_DIR/$PHP_LIBDIR -L$PDO_MYSQL_LIB_DIR ]) @@ -128,11 +119,6 @@ if test "$PHP_PDO_MYSQL" != "no"; then ],[ $PDO_MYSQL_LIBS ]) - - _SAVE_LIBS=$LIBS - LIBS="$LIBS $PDO_MYSQL_LIBS" - AC_CHECK_FUNCS([mysql_commit mysql_stmt_prepare mysql_next_result mysql_sqlstate]) - LIBS=$_SAVE_LIBS fi ifdef([PHP_CHECK_PDO_INCLUDES], @@ -141,15 +127,15 @@ if test "$PHP_PDO_MYSQL" != "no"; then ],[ AC_MSG_CHECKING([for PDO includes]) if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$abs_srcdir/ext + pdo_cv_inc_path=$abs_srcdir/ext elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$abs_srcdir/ext + pdo_cv_inc_path=$abs_srcdir/ext elif test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then - pdo_inc_path=$prefix/include/php/ext + pdo_cv_inc_path=$prefix/include/php/ext else AC_MSG_ERROR([Cannot find php_pdo_driver.h.]) fi - AC_MSG_RESULT($pdo_inc_path) + AC_MSG_RESULT($pdo_cv_inc_path) ]) if test -n "$PDO_MYSQL_CONFIG"; then @@ -158,7 +144,7 @@ if test "$PHP_PDO_MYSQL" != "no"; then fi dnl fix after renaming to pdo_mysql - PHP_NEW_EXTENSION(pdo_mysql, pdo_mysql.c mysql_driver.c mysql_statement.c, $ext_shared,,-I$pdo_inc_path -I) + PHP_NEW_EXTENSION(pdo_mysql, pdo_mysql.c mysql_driver.c mysql_statement.c, $ext_shared,,-I$pdo_cv_inc_path -I) ifdef([PHP_ADD_EXTENSION_DEP], [ PHP_ADD_EXTENSION_DEP(pdo_mysql, pdo) diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 96bad98722..a703f93e7c 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -36,23 +36,12 @@ #endif #include "zend_exceptions.h" -#if PDO_USE_MYSQLND +#if defined(PDO_USE_MYSQLND) # define pdo_mysql_init(persistent) mysqlnd_init(persistent) #else # define pdo_mysql_init(persistent) mysql_init(NULL) #endif -#if !defined(HAVE_MYSQL_SQLSTATE) && !defined(PDO_USE_MYSQLND) -static const char *pdo_mysql_get_sqlstate(unsigned int my_errno) { /* {{{ */ - switch (my_errno) { - /* import auto-generated case: code */ -#include "php_pdo_mysql_sqlstate.h" - default: return "HY000"; - } -} -/* }}} */ -#endif - /* {{{ _pdo_mysql_error */ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC) { @@ -72,13 +61,9 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin einfo = &H->einfo; } -#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) if (S && S->stmt) { einfo->errcode = mysql_stmt_errno(S->stmt); - } - else -#endif - { + } else { einfo->errcode = mysql_errno(H->server); } @@ -112,18 +97,11 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin PDO_DBG_RETURN(0); } -#if defined(HAVE_MYSQL_SQLSTATE) || defined(PDO_USE_MYSQLND) -# if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) if (S && S->stmt) { strcpy(*pdo_err, mysql_stmt_sqlstate(S->stmt)); - } else -# endif - { + } else { strcpy(*pdo_err, mysql_sqlstate(H->server)); } -#else - strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode)); -#endif if (!dbh->methods) { PDO_DBG_INF("Throwing exception"); @@ -187,12 +165,10 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt)); -#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) char *nsql = NULL; int nsql_len = 0; int ret; int server_version; -#endif PDO_DBG_ENTER("mysql_handle_preparer"); PDO_DBG_INF_FMT("dbh=%p", dbh); @@ -206,7 +182,6 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, goto end; } -#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) server_version = mysql_get_server_version(H->server); if (server_version < 40100) { goto fallback; @@ -255,7 +230,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, if (S->num_params) { S->params_given = 0; -#ifdef PDO_USE_MYSQLND +#if defined(PDO_USE_MYSQLND) S->params = NULL; #else S->params = ecalloc(S->num_params, sizeof(MYSQL_BIND)); @@ -270,7 +245,6 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, PDO_DBG_RETURN(1); fallback: -#endif end: stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; @@ -296,7 +270,6 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM PDO_DBG_RETURN(H->einfo.errcode ? -1 : 0); } else { -#if defined(HAVE_MYSQL_NEXT_RESULT) || defined(PDO_USE_MYSQLND) /* MULTI_QUERY support - eat up all unfetched result sets */ MYSQL_RES* result; while (mysql_more_results(H->server)) { @@ -308,7 +281,6 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM mysql_free_result(result); } } -#endif PDO_DBG_RETURN((int)c); } } @@ -324,7 +296,7 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned *len = strlen(id); PDO_DBG_RETURN(id); } -/* }}} */ +/* }}} */ /* {{{ mysql_handle_quoter */ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC) @@ -463,7 +435,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value break; case PDO_ATTR_SERVER_INFO: { char *tmp; -#ifdef PDO_USE_MYSQLND +#if defined(PDO_USE_MYSQLND) unsigned int tmp_len; if (mysqlnd_stat(H->server, &tmp, &tmp_len) == PASS) { @@ -584,7 +556,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ #endif ; -#ifdef PDO_USE_MYSQLND +#if defined(PDO_USE_MYSQLND) int dbname_len = 0; int password_len = 0; #endif @@ -626,9 +598,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ char *default_file = NULL, *default_group = NULL; #endif long compress = 0; -#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL; -#endif H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1 TSRMLS_CC); H->emulate_prepare = pdo_attr_lval(driver_options, @@ -714,7 +684,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ goto cleanup; } } -#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND) + ssl_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_KEY, NULL TSRMLS_CC); ssl_cert = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CERT, NULL TSRMLS_CC); ssl_ca = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CA, NULL TSRMLS_CC); @@ -739,7 +709,6 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ efree(ssl_cipher); } } -#endif } #ifdef PDO_MYSQL_HAS_CHARSET diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index d6dcb3a2e6..2ae559571d 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -59,12 +59,10 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ pefree(S->einfo.errmsg, stmt->dbh->is_persistent); S->einfo.errmsg = NULL; } -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND if (S->stmt) { pdo_mysql_stmt_close(S->stmt); S->stmt = NULL; } -#endif /* HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND */ #ifndef PDO_USE_MYSQLND if (S->params) { @@ -77,9 +75,6 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ efree(S->in_length); } -#endif /* PDO_USE_MYSQLND */ - -#ifdef HAVE_MYSQL_STMT_PREPARE if (S->bound_result) { int i; @@ -91,10 +86,9 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ efree(S->out_null); efree(S->out_length); } -#endif /* HAVE_MYSQL_STMT_PREPARE */ +#endif -#if HAVE_MYSQL_NEXT_RESULT || PDO_USE_MYSQLND if (S->H->server) { while (mysql_more_results(S->H->server)) { MYSQL_RES *res; @@ -108,7 +102,7 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ } } } -#endif /* HAVE_MYSQL_NEXT_RESULT || PDO_USE_MYSQLND */ + #if PDO_USE_MYSQLND if (!S->stmt && S->current_data) { mnd_free(S->current_data); @@ -140,7 +134,7 @@ static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ row_count = mysql_affected_rows(H->server); if (row_count == (my_ulonglong)-1) { - /* we either have a query that returned a result set or an error occured + /* we either have a query that returned a result set or an error occurred lets see if we have access to a result set */ if (!H->buffered) { S->result = mysql_use_result(H->server); @@ -164,7 +158,7 @@ static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ } /* }}} */ -#ifdef HAVE_MYSQL_STMT_PREPARE +#ifndef PDO_USE_MYSQLND static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ { pdo_mysql_stmt *S = stmt->driver_data; @@ -325,11 +319,9 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ PDO_DBG_ENTER("pdo_mysql_stmt_execute"); PDO_DBG_INF_FMT("stmt=%p", S->stmt); -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND if (S->stmt) { PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt)); } -#endif /* ensure that we free any previous unfetched results */ if (S->result) { @@ -348,11 +340,9 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ { -#if HAVE_MYSQL_NEXT_RESULT || PDO_USE_MYSQLND pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; pdo_mysql_db_handle *H = S->H; long row_count; - int ret; PDO_DBG_ENTER("pdo_mysql_stmt_next_rowset"); PDO_DBG_INF_FMT("stmt=%p", S->stmt); @@ -410,7 +400,7 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ #endif /* ensure that we free any previous unfetched results */ -#if HAVE_MYSQL_STMT_PREPARE +#ifndef PDO_USE_MYSQLND if (S->stmt) { stmt->column_count = (int)mysql_num_fields(S->result); mysql_stmt_free_result(S->stmt); @@ -421,35 +411,25 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ S->result = NULL; } - ret = mysql_next_result(H->server); + if (!mysql_more_results(H->server)) { + /* No more results */ + PDO_DBG_RETURN(0); + } #if PDO_USE_MYSQLND - /* for whatever reason mysqlnd breaks with libmysql compatibility at the C level, no -1 */ - if (PASS != ret) { + if (mysql_next_result(H->server) == FAIL) { pdo_mysql_error_stmt(stmt); PDO_DBG_RETURN(0); - } - if (mysql_more_results(H->server)) { - PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); } else { - /* No more results */ - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); } #else - if (ret > 0) { + if (mysql_next_result(H->server) > 0) { pdo_mysql_error_stmt(stmt); PDO_DBG_RETURN(0); - } else if (ret < 0) { - /* No more results */ - PDO_DBG_RETURN(0); } else { PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC)); } #endif - -#else - strcpy(stmt->error_code, "HYC00"); - PDO_DBG_RETURN(0); -#endif /* HAVE_MYSQL_STMT_PREPARE */ } /* }}} */ @@ -471,7 +451,6 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da #ifndef PDO_USE_MYSQLND PDO_MYSQL_PARAM_BIND *b; #endif -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; PDO_DBG_ENTER("pdo_mysql_stmt_param_hook"); @@ -603,7 +582,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da break; } } -#endif /* HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND */ + PDO_DBG_RETURN(1); } /* }}} */ @@ -624,7 +603,6 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori PDO_DBG_RETURN(1); } #else -# if HAVE_MYSQL_STMT_PREPARE int ret; if (S->stmt) { @@ -645,7 +623,6 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori PDO_DBG_RETURN(1); } -# endif /* HAVE_MYSQL_STMT_PREPARE */ #endif /* PDO_USE_MYSQLND */ if (!S->result) { @@ -736,15 +713,12 @@ static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsig } /* With mysqlnd data is stored inside mysqlnd, not S->current_data */ -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND if (!S->stmt) { -#endif if (S->current_data == NULL || !S->result) { PDO_DBG_RETURN(0); } -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND } -#endif + if (colno >= stmt->column_count) { /* error invalid column */ PDO_DBG_RETURN(0); @@ -756,7 +730,7 @@ static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsig *len = sizeof(zval); PDO_DBG_RETURN(1); } -#elif HAVE_MYSQL_STMT_PREPARE +#else if (S->stmt) { if (S->out_null[colno]) { *ptr = NULL; @@ -774,7 +748,7 @@ static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsig *len = S->out_length[colno]; PDO_DBG_RETURN(1); } -#endif /* PDO_USE_MYSQLND else HAVE_MYSQL_STMT_PREPARE */ +#endif *ptr = S->current_data[colno]; *len = S->current_lengths[colno]; PDO_DBG_RETURN(1); @@ -892,7 +866,7 @@ static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_va #endif add_assoc_zval(return_value, "flags", flags); - add_assoc_string(return_value, "table",(char *) (F->table?F->table:""), 1); + add_assoc_string(return_value, "table", (char *) (F->table?F->table:""), 1); PDO_DBG_RETURN(SUCCESS); } /* }}} */ @@ -906,15 +880,12 @@ static int pdo_mysql_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ mysql_free_result(S->result); S->result = NULL; } -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND if (S->stmt) { int retval; retval = mysql_stmt_free_result(S->stmt); PDO_DBG_RETURN(retval ? 0 : 1); } -#endif -#if HAVE_MYSQL_NEXT_RESULT || PDO_USE_MYSQLND while (mysql_more_results(S->H->server)) { MYSQL_RES *res; if (mysql_next_result(S->H->server) != 0) { @@ -925,7 +896,6 @@ static int pdo_mysql_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ mysql_free_result(res); } } -#endif PDO_DBG_RETURN(1); } /* }}} */ diff --git a/ext/pdo_mysql/pdo_mysql.c b/ext/pdo_mysql/pdo_mysql.c index b898ed0854..1dbb30f278 100644 --- a/ext/pdo_mysql/pdo_mysql.c +++ b/ext/pdo_mysql/pdo_mysql.c @@ -57,6 +57,30 @@ ZEND_DECLARE_MODULE_GLOBALS(pdo_mysql) # endif #endif +#ifdef PDO_USE_MYSQLND +#include "ext/mysqlnd/mysqlnd_reverse_api.h" +static MYSQLND * pdo_mysql_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC) +{ + if (Z_TYPE_P(zv) == IS_OBJECT && Z_OBJCE_P(zv) == php_pdo_get_dbh_ce()) { + pdo_dbh_t * dbh = zend_object_store_get_object(zv TSRMLS_CC); + + if (!dbh || dbh->driver != &pdo_mysql_driver) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Provided PDO instance is not using MySQL but %s", dbh->driver->driver_name); + return NULL; + } + + return ((pdo_mysql_db_handle *)dbh->driver_data)->server; + } + return NULL; +} + +static MYSQLND_REVERSE_API pdo_mysql_reverse_api = { + &pdo_mysql_module_entry, + pdo_mysql_convert_zv_to_mysqlnd +}; +#endif + + /* {{{ PHP_INI_BEGIN */ PHP_INI_BEGIN() @@ -94,6 +118,11 @@ static PHP_MINIT_FUNCTION(pdo_mysql) REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CA", (long)PDO_MYSQL_ATTR_SSL_CA); REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CAPATH", (long)PDO_MYSQL_ATTR_SSL_CAPATH); REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_SSL_CIPHER", (long)PDO_MYSQL_ATTR_SSL_CIPHER); + +#ifdef PDO_USE_MYSQLND + mysqlnd_reverse_api_register_api(&pdo_mysql_reverse_api TSRMLS_CC); +#endif + return php_pdo_register_driver(&pdo_mysql_driver); } /* }}} */ diff --git a/ext/pdo_mysql/php_pdo_mysql_int.h b/ext/pdo_mysql/php_pdo_mysql_int.h index c061b7684a..65d7435a73 100644 --- a/ext/pdo_mysql/php_pdo_mysql_int.h +++ b/ext/pdo_mysql/php_pdo_mysql_int.h @@ -127,7 +127,6 @@ typedef struct { long *current_lengths; #endif pdo_mysql_error_info einfo; -#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND #if PDO_USE_MYSQLND MYSQLND_STMT *stmt; #else @@ -144,7 +143,6 @@ typedef struct { unsigned long *out_length; unsigned int params_given; unsigned max_length:1; -#endif } pdo_mysql_stmt; extern pdo_driver_t pdo_mysql_driver; diff --git a/ext/pdo_mysql/tests/bug_61207.phpt b/ext/pdo_mysql/tests/bug_61207.phpt index 917b322180..411b39a70b 100644 --- a/ext/pdo_mysql/tests/bug_61207.phpt +++ b/ext/pdo_mysql/tests/bug_61207.phpt @@ -2,27 +2,27 @@ PDO MySQL Bug #61207 (PDO::nextRowset() after a multi-statement query doesn't always work) --SKIPIF-- <?php -if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded'); -require dirname(__FILE__) . '/config.inc'; -require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; -PDOTest::skip(); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +MySQLPDOTest::skip(); + ?> --FILE-- <?php -require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); +$db = MySQLPDOTest::factory(); -$link = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); +$db->query('DROP TABLE IF EXISTS test'); +$db->query('create table `test`( `id` int )'); -$link->query('create table `bug61207`( `id` int )'); +$handle1 = $db->prepare('insert into test(id) values(1); + select * from test where id = ?; + update test set id = 2 where id = ?;'); -$handle1 = $link->prepare('insert into bug61207(id) values(1); - select * from bug61207 where id = ?; - update bug61207 set id = 2 where id = ?;'); - $handle1->bindValue('1', '1'); $handle1->bindValue('2', '1'); - -$handle1->execute(); + +$handle1->execute(); $i = 1; print("Handle 1:\n"); do { @@ -31,9 +31,9 @@ do { print("Results detected\n"); } while($handle1->nextRowset()); -$handle2 = $link->prepare('select * from bug61207 where id = ?; - update bug61207 set id = 1 where id = ?;'); - +$handle2 = $db->prepare('select * from test where id = ?; + update test set id = 1 where id = ?;'); + $handle2->bindValue('1', '2'); $handle2->bindValue('2', '2'); @@ -47,9 +47,9 @@ do { print("Results detected\n"); } while($handle2->nextRowset()); -$handle3 = $link->prepare('update bug61207 set id = 2 where id = ?; - select * from bug61207 where id = ?;'); - +$handle3 = $db->prepare('update test set id = 2 where id = ?; + select * from test where id = ?;'); + $handle3->bindValue('1', '1'); $handle3->bindValue('2', '2'); @@ -63,15 +63,15 @@ do { print("Results detected\n"); } while($handle3->nextRowset()); -$handle4 = $link->prepare('insert into bug61207(id) values(3); - update bug61207 set id = 2 where id = ?; - select * from bug61207 where id = ?;'); - +$handle4 = $db->prepare('insert into test(id) values(3); + update test set id = 2 where id = ?; + select * from test where id = ?;'); + $handle4->bindValue('1', '3'); $handle4->bindValue('2', '2'); - + $handle4->execute(); - + $i = 1; print("Handle 4:\n"); do { @@ -80,7 +80,12 @@ do { print("Results detected\n"); } while($handle1->nextRowset()); -$link->query("DROP TABLE bug61207"); +$db->query("DROP TABLE test"); +?> +--CLEAN-- +<?php +require dirname(__FILE__) . '/mysql_pdo_test.inc'; +MySQLPDOTest::dropTestTable(); ?> --EXPECT-- Handle 1: diff --git a/ext/pdo_mysql/tests/common.phpt b/ext/pdo_mysql/tests/common.phpt index 8179454cf7..f55d1f883b 100644 --- a/ext/pdo_mysql/tests/common.phpt +++ b/ext/pdo_mysql/tests/common.phpt @@ -8,7 +8,7 @@ if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) print 'skip not # magic auto-configuration $config = array( - 'TESTS' => 'ext/pdo/tests' + 'TESTS' => __DIR__.'/ext/pdo/tests' ); if (false !== getenv('PDO_MYSQL_TEST_DSN')) { diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt index 9092004fe5..c3f12df7a9 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt @@ -297,4 +297,4 @@ MySQLPDOTest::skip(); [009] SQLSTATE[%s] [1045] Access denied for user 'dont%s'@'%s' (using password: YES), [n/a] n/a [010] SQLSTATE[%s] [1045] Access denied for user 'dont%s'@'%s' (using password: YES), [n/a] n/a [017] DSN=%s, SQLSTATE[%s] [%d] %s -[033] DSN = mysql:%s, character sets has not been set, @@character_set_connection reports 'latin1', expecting 'latin2'done! +done! diff --git a/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt b/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt index 37de557527..b550cb8da3 100644 --- a/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.phpt @@ -69,7 +69,7 @@ if (($tmp[1] !== 'localhost') && ($tmp[1] !== '127.0.0.1')) fwrite($fp, b"2;bar"); fclose($fp); - $sql = sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename)); + $sql = sprintf("LOAD DATA LOCAL INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'", $db->quote($filename)); if (exec_and_count(4, $db, $sql, 2)) { @@ -105,4 +105,4 @@ $db = MySQLPDOTest::factory(); $db->exec('DROP TABLE IF EXISTS test'); ?> --EXPECTF-- -done!
\ No newline at end of file +done! |