Skip to content

Commit 50c5a4b

Browse files
committed
Mysqli: bind-in-execute (mysqlnd)
1 parent f068954 commit 50c5a4b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,15 +811,43 @@ PHP_FUNCTION(mysqli_stmt_execute)
811811
{
812812
MY_STMT *stmt;
813813
zval *mysql_stmt;
814+
zval *input_params = NULL;
814815
#ifndef MYSQLI_USE_MYSQLND
815816
unsigned int i;
816817
#endif
817818

818-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
819+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|a", &mysql_stmt, mysqli_stmt_class_entry, &input_params) == FAILURE) {
819820
RETURN_THROWS();
820821
}
821822
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
822823

824+
// bind-in-execute
825+
#if defined(MYSQLI_USE_MYSQLND)
826+
if(input_params) {
827+
zval *tmp;
828+
unsigned int index;
829+
MYSQLND_PARAM_BIND *params;
830+
831+
params = mysqlnd_stmt_alloc_param_bind(stmt->stmt);
832+
if (!params) {
833+
// can we safely return here?
834+
RETVAL_FALSE;
835+
}
836+
837+
index = 0;
838+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input_params), tmp) {
839+
ZVAL_COPY_VALUE(&params[index].zv, tmp);
840+
params[index].type = MYSQL_TYPE_VAR_STRING;
841+
index++;
842+
} ZEND_HASH_FOREACH_END();
843+
844+
if(mysqlnd_stmt_bind_param(stmt->stmt, params)) {
845+
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
846+
RETVAL_FALSE;
847+
}
848+
}
849+
#endif
850+
823851
#ifndef MYSQLI_USE_MYSQLND
824852
if (stmt->param.var_cnt) {
825853
int j;

0 commit comments

Comments
 (0)