Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ void php_clear_mysql(MY_MYSQL *mysql) {
zend_string_release_ex(mysql->hash_key, 0);
mysql->hash_key = NULL;
}
if (!Z_ISUNDEF(mysql->li_read)) {
zval_ptr_dtor(&(mysql->li_read));
ZVAL_UNDEF(&mysql->li_read);
}
}
/* }}} */

Expand Down Expand Up @@ -788,7 +784,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
}
}
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");
Expand Down
20 changes: 10 additions & 10 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ PHP_FUNCTION(mysqli_data_seek)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (mysqli_result_is_unbuffered(result)) {
if (hasThis()) {
Expand Down Expand Up @@ -670,7 +670,7 @@ PHP_FUNCTION(mysqli_fetch_field)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (!(field = mysql_fetch_field(result))) {
RETURN_FALSE;
Expand All @@ -694,7 +694,7 @@ PHP_FUNCTION(mysqli_fetch_fields)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

array_init(return_value);
num_fields = mysql_num_fields(result);
Expand Down Expand Up @@ -727,7 +727,7 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (offset >= (zend_long) mysql_num_fields(result)) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
Expand Down Expand Up @@ -755,7 +755,7 @@ PHP_FUNCTION(mysqli_fetch_lengths)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

// TODO Warning?
if (!(ret = mysql_fetch_lengths(result))) {
Expand Down Expand Up @@ -809,7 +809,7 @@ PHP_FUNCTION(mysqli_field_seek)
RETURN_THROWS();
}

MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
Expand All @@ -830,7 +830,7 @@ PHP_FUNCTION(mysqli_field_tell)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

RETURN_LONG(mysql_field_tell(result));
}
Expand All @@ -845,7 +845,7 @@ PHP_FUNCTION(mysqli_free_result)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

mysqli_free_result(result, false);
MYSQLI_CLEAR_RESOURCE(mysql_result);
Expand Down Expand Up @@ -1123,7 +1123,7 @@ PHP_FUNCTION(mysqli_num_fields)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

RETURN_LONG(mysql_num_fields(result));
}
Expand All @@ -1138,7 +1138,7 @@ PHP_FUNCTION(mysqli_num_rows)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
zend_throw_error(NULL, "mysqli_num_rows() cannot be used in MYSQLI_USE_RESULT mode");
Expand Down
10 changes: 4 additions & 6 deletions ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
self_alloced = true;
}
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
} else {
/* We have flags too */
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s!s!s!s!l!s!l", &object, mysqli_link_class_entry,
Expand All @@ -118,11 +117,10 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
MYSQLI_FETCH_RESOURCE_CONN(mysql, object, MYSQLI_STATUS_INITIALIZED);

/* set some required options */
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
/* remove some insecure options */
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
}
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */

if (!socket_len || !socket) {
socket = MyG(default_socket);
Expand Down Expand Up @@ -316,7 +314,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
mysql->hash_key = NULL;
mysql->persistent = false;
}
if (!is_real_connect && self_alloced) {
if (self_alloced) {
efree(mysql);
}
RETVAL_FALSE;
Expand Down Expand Up @@ -393,7 +391,7 @@ PHP_FUNCTION(mysqli_fetch_column)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &col_no) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, MYSQLI_STATUS_VALID);

if (col_no < 0) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
Expand Down Expand Up @@ -425,7 +423,7 @@ PHP_FUNCTION(mysqli_fetch_all)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &mode) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);

if (!mode || (mode & ~MYSQLI_BOTH)) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");
Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/mysqli_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ extern void php_clear_mysql(MY_MYSQL *);
extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);

extern void php_clear_warnings(MYSQLI_WARNING *w);
extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error);
extern void php_mysqli_report_index(const char *query, unsigned int status);
extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/mysqli_result_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter)
mysqli_object *intern = iterator->result;
MYSQL_RES *result;

MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);

zval_ptr_dtor(&iterator->current_row);
php_mysqli_fetch_into_hash_aux(&iterator->current_row, result, MYSQLI_ASSOC);
Expand All @@ -115,7 +115,7 @@ static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter)
mysqli_object *intern = iterator->result;
MYSQL_RES *result;

MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);

if (mysqli_result_is_unbuffered(result)) {
if (result->unbuf->eof_reached) {
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli_warning.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ PHP_METHOD(mysqli_warning, next)
}

if (obj->ptr) {
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, "mysqli_warning", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, MYSQLI_STATUS_VALID);

if (w && w->next) {
w = w->next;
Expand Down
26 changes: 4 additions & 22 deletions ext/mysqli/php_mysqli_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,14 @@ enum mysqli_status {
MYSQLI_STATUS_VALID
};

typedef struct {
char *val;
zend_ulong buflen;
zend_ulong output_len;
zend_ulong type;
} VAR_BUFFER;

typedef struct {
unsigned int var_cnt;
VAR_BUFFER *buf;
zval *vars;
my_bool *is_null;
} BIND_BUFFER;

typedef struct {
MYSQL_STMT *stmt;
BIND_BUFFER param;
BIND_BUFFER result;
char *query;
} MY_STMT;

typedef struct {
MYSQL *mysql;
zend_string *hash_key;
zval li_read;
php_stream *li_stream;
unsigned int multi_query;
bool persistent;
int async_result_fetch_type;
Expand Down Expand Up @@ -177,7 +159,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
}

#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __check) \
{ \
MYSQLI_RESOURCE *my_res; \
mysqli_object *intern = Z_MYSQLI_P(__id); \
Expand All @@ -192,7 +174,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
}\
}

#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __check) \
{ \
MYSQLI_RESOURCE *my_res; \
if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
Expand All @@ -208,7 +190,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul

#define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), (__check)); \
if (!(__ptr)->mysql) { \
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(Z_OBJCE_P(__id)->name)); \
RETURN_THROWS(); \
Expand All @@ -217,7 +199,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul

#define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), (__check)); \
ZEND_ASSERT((__ptr)->stmt && "Missing statement?"); \
}

Expand Down