diff options
Diffstat (limited to 'ext/pdo_mysql/mysql_driver.c')
-rw-r--r-- | ext/pdo_mysql/mysql_driver.c | 245 |
1 files changed, 125 insertions, 120 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index e82fdf46db..f09bc05314 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -43,10 +43,10 @@ #endif /* {{{ _pdo_mysql_error */ -int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC) +int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; - pdo_error_type *pdo_err; + pdo_error_type *pdo_err; pdo_mysql_error_info *einfo; pdo_mysql_stmt *S = NULL; @@ -105,7 +105,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin if (!dbh->methods) { PDO_DBG_INF("Throwing exception"); - zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } @@ -114,7 +114,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin /* }}} */ /* {{{ pdo_mysql_fetch_error_func */ -static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC) +static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_error_info *einfo = &H->einfo; @@ -130,7 +130,7 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in if (einfo->errcode) { add_next_index_long(info, einfo->errcode); - add_next_index_string(info, einfo->errmsg, 1); + add_next_index_string(info, einfo->errmsg); } PDO_DBG_RETURN(1); @@ -138,20 +138,18 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in /* }}} */ /* {{{ mysql_handle_closer */ -static int mysql_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) +static int mysql_handle_closer(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; - + PDO_DBG_ENTER("mysql_handle_closer"); PDO_DBG_INF_FMT("dbh=%p", dbh); if (H) { if (H->server) { mysql_close(H->server); - H->server = NULL; } if (H->einfo.errmsg) { pefree(H->einfo.errmsg, dbh->is_persistent); - H->einfo.errmsg = NULL; } pefree(H, dbh->is_persistent); dbh->driver_data = NULL; @@ -161,18 +159,18 @@ static int mysql_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) /* }}} */ /* {{{ mysql_handle_preparer */ -static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC) +static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt)); char *nsql = NULL; - int nsql_len = 0; + size_t nsql_len = 0; int ret; int server_version; - + PDO_DBG_ENTER("mysql_handle_preparer"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql); + PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql); S->H = H; stmt->driver_data = S; @@ -187,7 +185,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, goto fallback; } stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL; - ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len TSRMLS_CC); + ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len); if (ret == 1) { /* query was rewritten */ @@ -206,7 +204,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, } PDO_DBG_RETURN(0); } - + if (mysql_stmt_prepare(S->stmt, sql, sql_len)) { /* TODO: might need to pull statement specific info here? */ /* if the query isn't supported by the protocol, fallback to emulation */ @@ -235,30 +233,30 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, #else S->params = ecalloc(S->num_params, sizeof(MYSQL_BIND)); S->in_null = ecalloc(S->num_params, sizeof(my_bool)); - S->in_length = ecalloc(S->num_params, sizeof(unsigned long)); + S->in_length = ecalloc(S->num_params, sizeof(zend_ulong)); #endif } dbh->alloc_own_columns = 1; - S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0 TSRMLS_CC); + S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0); PDO_DBG_RETURN(1); fallback: end: stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; - + PDO_DBG_RETURN(1); } /* }}} */ /* {{{ mysql_handle_doer */ -static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC) +static zend_long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, size_t sql_len) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; PDO_DBG_ENTER("mysql_handle_doer"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_INF_FMT("sql=%.*s", sql_len, sql); + PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql); if (mysql_real_query(H->server, sql, sql_len)) { pdo_mysql_error(dbh); @@ -288,10 +286,10 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM /* }}} */ /* {{{ pdo_mysql_last_insert_id */ -static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len TSRMLS_DC) +static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *len) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; - char *id = php_pdo_int64_to_str(mysql_insert_id(H->server) TSRMLS_CC); + char *id = php_pdo_int64_to_str(mysql_insert_id(H->server)); PDO_DBG_ENTER("pdo_mysql_last_insert_id"); *len = strlen(id); PDO_DBG_RETURN(id); @@ -299,58 +297,58 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned /* }}} */ /* {{{ 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) +static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; PDO_DBG_ENTER("mysql_handle_quoter"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_INF_FMT("unquoted=%.*s", unquotedlen, unquoted); + PDO_DBG_INF_FMT("unquoted=%.*s", (int)unquotedlen, unquoted); *quoted = safe_emalloc(2, unquotedlen, 3); *quotedlen = mysql_real_escape_string(H->server, *quoted + 1, unquoted, unquotedlen); (*quoted)[0] =(*quoted)[++*quotedlen] = '\''; (*quoted)[++*quotedlen] = '\0'; - PDO_DBG_INF_FMT("quoted=%.*s", *quotedlen, *quoted); + PDO_DBG_INF_FMT("quoted=%.*s", (int)*quotedlen, *quoted); PDO_DBG_RETURN(1); } /* }}} */ /* {{{ mysql_handle_begin */ -static int mysql_handle_begin(pdo_dbh_t *dbh TSRMLS_DC) +static int mysql_handle_begin(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_quoter"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("START TRANSACTION") TSRMLS_CC)); + PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("START TRANSACTION"))); } /* }}} */ /* {{{ mysql_handle_commit */ -static int mysql_handle_commit(pdo_dbh_t *dbh TSRMLS_DC) +static int mysql_handle_commit(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_commit"); PDO_DBG_INF_FMT("dbh=%p", dbh); #if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND) PDO_DBG_RETURN(0 <= mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server)); #else - PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT") TSRMLS_CC)); + PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT"))); #endif } /* }}} */ /* {{{ mysql_handle_rollback */ -static int mysql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) +static int mysql_handle_rollback(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_rollback"); PDO_DBG_INF_FMT("dbh=%p", dbh); #if MYSQL_VERSION_ID >= 40100 || defined(PDO_USE_MYSQLND) PDO_DBG_RETURN(0 <= mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server)); #else - PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK") TSRMLS_CC)); + PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK"))); #endif } /* }}} */ /* {{{ mysql_handle_autocommit */ -static inline int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC) +static inline int mysql_handle_autocommit(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_autocommit"); PDO_DBG_INF_FMT("dbh=%p", dbh); @@ -359,49 +357,51 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC) PDO_DBG_RETURN(0 <= mysql_autocommit(((pdo_mysql_db_handle *)dbh->driver_data)->server, dbh->auto_commit)); #else if (dbh->auto_commit) { - PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=1") TSRMLS_CC)); + PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=1"))); } else { - PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=0") TSRMLS_CC)); + PDO_DBG_RETURN(0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=0"))); } #endif } /* }}} */ /* {{{ pdo_mysql_set_attribute */ -static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) +static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) { + zend_long lval = zval_get_long(val); + zend_bool bval = lval? 1 : 0; PDO_DBG_ENTER("pdo_mysql_set_attribute"); PDO_DBG_INF_FMT("dbh=%p", dbh); PDO_DBG_INF_FMT("attr=%l", attr); switch (attr) { - case PDO_ATTR_AUTOCOMMIT: - convert_to_boolean(val); - - /* ignore if the new value equals the old one */ - if (dbh->auto_commit ^ Z_BVAL_P(val)) { - dbh->auto_commit = Z_BVAL_P(val); - mysql_handle_autocommit(dbh TSRMLS_CC); + case PDO_ATTR_AUTOCOMMIT: + /* ignore if the new value equals the old one */ + if (dbh->auto_commit ^ bval) { + dbh->auto_commit = bval; + mysql_handle_autocommit(dbh); } PDO_DBG_RETURN(1); case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: - ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = Z_BVAL_P(val); + /* ignore if the new value equals the old one */ + ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval; PDO_DBG_RETURN(1); case PDO_MYSQL_ATTR_DIRECT_QUERY: case PDO_ATTR_EMULATE_PREPARES: - ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = Z_BVAL_P(val); + /* ignore if the new value equals the old one */ + ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval; PDO_DBG_RETURN(1); case PDO_ATTR_FETCH_TABLE_NAMES: - ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = Z_BVAL_P(val); + ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval; PDO_DBG_RETURN(1); #ifndef PDO_USE_MYSQLND case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE: - if (Z_LVAL_P(val) < 0) { + if (lval < 0) { /* TODO: Johannes, can we throw a warning here? */ ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = 1024*1024; PDO_DBG_INF_FMT("Adjusting invalid buffer size to =%l", ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size); } else { - ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = Z_LVAL_P(val); + ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = lval; } PDO_DBG_RETURN(1); break; @@ -414,7 +414,7 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_D /* }}} */ /* {{{ pdo_mysql_get_attribute */ -static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value TSRMLS_DC) +static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -423,26 +423,26 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value PDO_DBG_INF_FMT("attr=%l", attr); switch (attr) { case PDO_ATTR_CLIENT_VERSION: - ZVAL_STRING(return_value, (char *)mysql_get_client_info(), 1); + ZVAL_STRING(return_value, (char *)mysql_get_client_info()); break; case PDO_ATTR_SERVER_VERSION: - ZVAL_STRING(return_value, (char *)mysql_get_server_info(H->server), 1); + ZVAL_STRING(return_value, (char *)mysql_get_server_info(H->server)); break; case PDO_ATTR_CONNECTION_STATUS: - ZVAL_STRING(return_value, (char *)mysql_get_host_info(H->server), 1); + ZVAL_STRING(return_value, (char *)mysql_get_host_info(H->server)); break; case PDO_ATTR_SERVER_INFO: { - char *tmp; #if defined(PDO_USE_MYSQLND) - unsigned int tmp_len; + zend_string *tmp; - if (mysqlnd_stat(H->server, &tmp, &tmp_len) == PASS) { - ZVAL_STRINGL(return_value, tmp, tmp_len, 0); + if (mysqlnd_stat(H->server, &tmp) == PASS) { + ZVAL_STR(return_value, tmp); #else + char *tmp; if ((tmp = (char *)mysql_stat(H->server))) { - ZVAL_STRING(return_value, tmp, 1); + ZVAL_STRING(return_value, tmp); #endif } else { pdo_mysql_error(dbh); @@ -453,7 +453,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value case PDO_ATTR_AUTOCOMMIT: ZVAL_LONG(return_value, dbh->auto_commit); break; - + case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: ZVAL_LONG(return_value, H->buffered); break; @@ -470,7 +470,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value #endif default: - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(0); } PDO_DBG_RETURN(1); @@ -478,7 +478,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value /* }}} */ /* {{{ pdo_mysql_check_liveness */ -static int pdo_mysql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC) +static int pdo_mysql_check_liveness(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; #if MYSQL_VERSION_ID <= 32230 @@ -507,7 +507,7 @@ static int pdo_mysql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC) signal(SIGPIPE, handler); #endif /* end mysql_ping() */ PDO_DBG_RETURN(SUCCESS); -} +} /* }}} */ /* {{{ mysql_methods */ @@ -534,7 +534,7 @@ static struct pdo_dbh_methods mysql_methods = { #endif /* {{{ pdo_mysql_handle_factory */ -static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) +static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) { pdo_mysql_db_handle *H; int i, ret = 0; @@ -554,14 +554,14 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ #endif ; #if defined(PDO_USE_MYSQLND) - int dbname_len = 0; - int password_len = 0; + size_t dbname_len = 0; + size_t password_len = 0; #endif #ifdef CLIENT_MULTI_STATEMENTS if (!driver_options) { connect_opts |= CLIENT_MULTI_STATEMENTS; - } else if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MULTI_STATEMENTS, 1 TSRMLS_CC)) { + } else if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MULTI_STATEMENTS, 1)) { connect_opts |= CLIENT_MULTI_STATEMENTS; } #endif @@ -586,7 +586,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ pdo_mysql_error(dbh); goto cleanup; } - + dbh->driver_data = H; #ifndef PDO_USE_MYSQLND @@ -597,30 +597,30 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ /* handle MySQL options */ if (driver_options) { - long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC); - long local_infile = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0 TSRMLS_CC); - char *init_cmd = NULL; + zend_long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30); + zend_long local_infile = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_LOCAL_INFILE, 0); + zend_string *init_cmd = NULL; #ifndef PDO_USE_MYSQLND - char *default_file = NULL, *default_group = NULL; + zend_string *default_file = NULL, *default_group = NULL; #endif - long compress = 0; - char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL; - H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1 TSRMLS_CC); + zend_long compress = 0; + zend_string *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL; + H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1); H->emulate_prepare = pdo_attr_lval(driver_options, - PDO_MYSQL_ATTR_DIRECT_QUERY, H->emulate_prepare TSRMLS_CC); - H->emulate_prepare = pdo_attr_lval(driver_options, - PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare TSRMLS_CC); + PDO_MYSQL_ATTR_DIRECT_QUERY, H->emulate_prepare); + H->emulate_prepare = pdo_attr_lval(driver_options, + PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare); #ifndef PDO_USE_MYSQLND - H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size TSRMLS_CC); + H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size); #endif - if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_FOUND_ROWS, 0 TSRMLS_CC)) { + if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_FOUND_ROWS, 0)) { connect_opts |= CLIENT_FOUND_ROWS; } - if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_IGNORE_SPACE, 0 TSRMLS_CC)) { + if (pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_IGNORE_SPACE, 0)) { connect_opts |= CLIENT_IGNORE_SPACE; } @@ -633,7 +633,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ #if PHP_API_VERSION < 20100412 if ((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode)) #else - if (PG(open_basedir) && PG(open_basedir)[0] != '\0') + if (PG(open_basedir) && PG(open_basedir)[0] != '\0') #endif { local_infile = 0; @@ -651,41 +651,41 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ * mysqlnd doesn't support reconnect, thus we don't have "|| defined(PDO_USE_MYSQLND)" */ { - long reconnect = 1; + zend_long reconnect = 1; mysql_options(H->server, MYSQL_OPT_RECONNECT, (const char*)&reconnect); } #endif - init_cmd = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_INIT_COMMAND, NULL TSRMLS_CC); + init_cmd = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_INIT_COMMAND, NULL); if (init_cmd) { - if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)init_cmd)) { - str_efree(init_cmd); + if (mysql_options(H->server, MYSQL_INIT_COMMAND, (const char *)ZSTR_VAL(init_cmd))) { + zend_string_release(init_cmd); pdo_mysql_error(dbh); goto cleanup; } - str_efree(init_cmd); + zend_string_release(init_cmd); } -#ifndef PDO_USE_MYSQLND - default_file = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_FILE, NULL TSRMLS_CC); +#ifndef PDO_USE_MYSQLND + default_file = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_FILE, NULL); if (default_file) { - if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)default_file)) { - str_efree(default_file); + if (mysql_options(H->server, MYSQL_READ_DEFAULT_FILE, (const char *)ZSTR_VAL(default_file))) { + zend_string_release(default_file); pdo_mysql_error(dbh); goto cleanup; } - str_efree(default_file); + zend_string_release(default_file); } - - default_group= pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL TSRMLS_CC); + + default_group = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_READ_DEFAULT_GROUP, NULL); if (default_group) { - if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)default_group)) { - str_efree(default_group); + if (mysql_options(H->server, MYSQL_READ_DEFAULT_GROUP, (const char *)ZSTR_VAL(default_group))) { + zend_string_release(default_group); pdo_mysql_error(dbh); goto cleanup; } - str_efree(default_group); + zend_string_release(default_group); } #endif - compress = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_COMPRESS, 0 TSRMLS_CC); + compress = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_COMPRESS, 0); if (compress) { if (mysql_options(H->server, MYSQL_OPT_COMPRESS, 0)) { pdo_mysql_error(dbh); @@ -693,41 +693,46 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ } } - 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); - ssl_capath = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CAPATH, NULL TSRMLS_CC); - ssl_cipher = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CIPHER, NULL TSRMLS_CC); - + ssl_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_KEY, NULL); + ssl_cert = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CERT, NULL); + ssl_ca = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CA, NULL); + ssl_capath = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CAPATH, NULL); + ssl_cipher = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CIPHER, NULL); + if (ssl_key || ssl_cert || ssl_ca || ssl_capath || ssl_cipher) { - mysql_ssl_set(H->server, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher); + mysql_ssl_set(H->server, + ssl_key? ZSTR_VAL(ssl_key) : NULL, + ssl_cert? ZSTR_VAL(ssl_cert) : NULL, + ssl_ca? ZSTR_VAL(ssl_ca) : NULL, + ssl_capath? ZSTR_VAL(ssl_capath) : NULL, + ssl_cipher? ZSTR_VAL(ssl_cipher) : NULL); if (ssl_key) { - str_efree(ssl_key); + zend_string_release(ssl_key); } if (ssl_cert) { - str_efree(ssl_cert); + zend_string_release(ssl_cert); } if (ssl_ca) { - str_efree(ssl_ca); + zend_string_release(ssl_ca); } if (ssl_capath) { - str_efree(ssl_capath); + zend_string_release(ssl_capath); } if (ssl_cipher) { - str_efree(ssl_cipher); + zend_string_release(ssl_cipher); } } #if MYSQL_VERSION_ID > 50605 || defined(PDO_USE_MYSQLND) { - char *public_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY, NULL TSRMLS_CC); + zend_string *public_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SERVER_PUBLIC_KEY, NULL); if (public_key) { - if (mysql_options(H->server, MYSQL_SERVER_PUBLIC_KEY, public_key)) { + if (mysql_options(H->server, MYSQL_SERVER_PUBLIC_KEY, ZSTR_VAL(public_key))) { pdo_mysql_error(dbh); - str_efree(public_key); + zend_string_release(public_key); goto cleanup; } - str_efree(public_key); + zend_string_release(public_key); } } #endif @@ -741,7 +746,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ #endif dbname = vars[1].optval; - host = vars[2].optval; + host = vars[2].optval; if(vars[3].optval) { port = atoi(vars[3].optval); } @@ -749,10 +754,10 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ #ifdef PHP_WIN32 if (vars[2].optval && !strcmp(".", vars[2].optval)) { #else - if (vars[2].optval && !strcmp("localhost", vars[2].optval)) { + if (vars[2].optval && !strcmp("localhost", vars[2].optval)) { #endif - unix_socket = vars[4].optval; - } + unix_socket = vars[4].optval; + } /* TODO: - Check zval cache + ZTS */ #ifdef PDO_USE_MYSQLND @@ -765,7 +770,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ } if (mysqlnd_connect(H->server, host, dbh->username, dbh->password, password_len, dbname, dbname_len, - port, unix_socket, connect_opts, MYSQLND_CLIENT_NO_FLAG TSRMLS_CC) == NULL) { + port, unix_socket, connect_opts, MYSQLND_CLIENT_NO_FLAG) == NULL) { #else if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) { #endif @@ -774,7 +779,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ } if (!dbh->auto_commit) { - mysql_handle_autocommit(dbh TSRMLS_CC); + mysql_handle_autocommit(dbh); } H->attached = 1; @@ -784,14 +789,14 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ dbh->methods = &mysql_methods; ret = 1; - + cleanup: for (i = 0; i < sizeof(vars)/sizeof(vars[0]); i++) { if (vars[i].freeme) { efree(vars[i].optval); } } - + dbh->methods = &mysql_methods; PDO_DBG_RETURN(ret); |