From d7f61a3e9b24b3b7e01cf843067eb9c6dbe9dcc5 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 16 Jul 2026 13:26:25 -0300 Subject: [PATCH 1/2] Binding errors should be more descriptive Identify the call site when possible via message variants. --- ibm_db2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ibm_db2.c b/ibm_db2.c index 89be662..03f7c83 100644 --- a/ibm_db2.c +++ b/ibm_db2.c @@ -4695,7 +4695,7 @@ static int _php_db2_execute_helper(stmt_handle *stmt_res, zval **data, int bind_ if (_php_db2_hash_find_ind(curr->varname, strlen(curr->varname), &temp, &bind_data, &symbol_table_used) != FAILURE ) { rc = _php_db2_bind_data( stmt_res, curr, bind_data); if ( rc == SQL_ERROR ) { - php_error_docref(NULL, E_WARNING, "Binding Error 1"); + php_error_docref(NULL, E_WARNING, "Error binding $%s from cached parameters", curr->varname); return rc; } curr = curr->next; @@ -4729,7 +4729,7 @@ static int _php_db2_execute_helper(stmt_handle *stmt_res, zval **data, int bind_ rc = _php_db2_bind_data( stmt_res, curr, data); if ( rc == SQL_ERROR ) { - php_error_docref(NULL, E_WARNING, "Binding Error 2"); + php_error_docref(NULL, E_WARNING, "Error binding parameter number %d", param_no); return rc; } } else { @@ -4742,7 +4742,7 @@ static int _php_db2_execute_helper(stmt_handle *stmt_res, zval **data, int bind_ if ( curr != NULL ) { rc = _php_db2_bind_data( stmt_res, curr, data); if ( rc == SQL_ERROR ) { - php_error_docref(NULL, E_WARNING, "Binding Error 2"); + php_error_docref(NULL, E_WARNING, "Error binding head cache node"); return rc; } stmt_res->current_node = curr->next; @@ -4885,7 +4885,7 @@ PHP_FUNCTION(db2_execute) */ rc = _php_db2_execute_helper(stmt_res, data, 0, bind_params); if ( rc == SQL_ERROR) { - php_error_docref(NULL, E_WARNING, "Binding Error"); + php_error_docref(NULL, E_WARNING, "Error binding additional params in execute"); RETURN_FALSE; } /* Move array ptr forward */ @@ -4910,7 +4910,7 @@ PHP_FUNCTION(db2_execute) /* And bind sequentially */ rc = _php_db2_execute_helper(stmt_res, NULL, 1, 0); if ( rc == SQL_ERROR ) { - php_error_docref(NULL, E_WARNING, "Binding Error 3"); + php_error_docref(NULL, E_WARNING, "Error binding params in execute"); RETURN_FALSE; } } @@ -7847,7 +7847,7 @@ PHP_FUNCTION( db2_execute_many ) rc = SQLBindParameter(stmt_res->hstmt, curr->param_num, curr->param_type, valueType, curr->data_type, curr->param_size, curr->scale, (curr->value), 0, (SQLLEN *)&((curr->value)->value.lval)); } if ( rc == SQL_ERROR ) { - sprintf(error, "Binding Error1 : %s", IBM_DB2_G(__php_stmt_err_msg)); + sprintf(error, "Error binding params in execute many: %s", IBM_DB2_G(__php_stmt_err_msg)); _build_client_err_list(head_error_list, error); err_count++; break; From 95d006ec6f824fe29099637c5d0fa18bd3a36f8c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 16 Jul 2026 13:55:03 -0300 Subject: [PATCH 2/2] Additional logging for cases where SQL_ERROR is returned without a check that i5_log_verbose can trigger --- ibm_db2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ibm_db2.c b/ibm_db2.c index 03f7c83..3f4740d 100644 --- a/ibm_db2.c +++ b/ibm_db2.c @@ -4350,6 +4350,7 @@ static int _php_db2_bind_pad(param_node *curr, int nullterm, int isvarying, int /* something went very wrong with heap */ if (Z_STRVAL_P(*data) == NULL ) { + php_error_docref(NULL, E_WARNING, "Pointer to string data for binding padding is null"); return SQL_ERROR; } @@ -4516,6 +4517,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b break; default: + php_error_docref(NULL, E_WARNING, "Unknown SQL data type %d used for binding", curr->data_type); return SQL_ERROR; } @@ -4525,6 +4527,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b if ( curr->param_type == DB2_PARAM_FILE) { /* Only string types can be bound */ if ( ZEND_Z_TYPE_PP(bind_data) != IS_STRING) { + php_error_docref(NULL, E_WARNING, "Only string types can be bound, got %s", zend_zval_type_name(*bind_data)); return SQL_ERROR; } /* len = 0 */ @@ -4661,6 +4664,7 @@ static int _php_db2_bind_data( stmt_handle *stmt_res, param_node *curr, zval **b break; default: + php_error_docref(NULL, E_WARNING, "zval of type %s cannot be bound", zend_zval_type_name(curr->value)); return SQL_ERROR; } return rc;