Skip to content

Commit

Permalink
Mysqli: bind-in-execute (mysqlnd)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela committed Oct 3, 2020
1 parent 1079622 commit c1f0fd3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ext/mysqli/mysqli_api.c
Expand Up @@ -817,15 +817,44 @@ PHP_FUNCTION(mysqli_stmt_execute)
{
MY_STMT *stmt;
zval *mysql_stmt;
zval *input_params = NULL;
#ifndef MYSQLI_USE_MYSQLND
unsigned int i;
#endif

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|a", &mysql_stmt, mysqli_stmt_class_entry, &input_params) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);

// bind-in-execute
#if defined(MYSQLI_USE_MYSQLND)
if(input_params) {
zval *tmp;
zend_ulong num_index;
unsigned int index;
MYSQLND_PARAM_BIND *params;

params = mysqlnd_stmt_alloc_param_bind(stmt->stmt);
if (!params) {
// can we safely return here?
RETVAL_FALSE;
}

index = 0;
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(input_params), num_index, tmp) {
ZVAL_COPY_VALUE(&params[index].zv, tmp);
params[index].type = MYSQL_TYPE_VAR_STRING;
index++;
} ZEND_HASH_FOREACH_END();

if(mysqlnd_stmt_bind_param(stmt->stmt, params)) {
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
RETVAL_FALSE;
}
}
#endif

#ifndef MYSQLI_USE_MYSQLND
if (stmt->param.var_cnt) {
int j;
Expand Down

0 comments on commit c1f0fd3

Please sign in to comment.