@@ -486,6 +486,12 @@ static PHP_METHOD(PDOStatement, execute)
486486 * quoted.
487487 */
488488
489+ /* string is leftover from previous calls so PDOStatement::debugDumpParams() can access */
490+ if (stmt -> active_query_string && stmt -> active_query_string != stmt -> query_string ) {
491+ efree (stmt -> active_query_string );
492+ }
493+ stmt -> active_query_string = NULL ;
494+
489495 ret = pdo_parse_params (stmt , stmt -> query_string , stmt -> query_stringlen ,
490496 & stmt -> active_query_string , & stmt -> active_query_stringlen );
491497
@@ -504,10 +510,6 @@ static PHP_METHOD(PDOStatement, execute)
504510 RETURN_FALSE ;
505511 }
506512 if (stmt -> methods -> executer (stmt )) {
507- if (stmt -> active_query_string && stmt -> active_query_string != stmt -> query_string ) {
508- efree (stmt -> active_query_string );
509- }
510- stmt -> active_query_string = NULL ;
511513 if (!stmt -> executed ) {
512514 /* this is the first execute */
513515
@@ -526,10 +528,6 @@ static PHP_METHOD(PDOStatement, execute)
526528
527529 RETURN_BOOL (ret );
528530 }
529- if (stmt -> active_query_string && stmt -> active_query_string != stmt -> query_string ) {
530- efree (stmt -> active_query_string );
531- }
532- stmt -> active_query_string = NULL ;
533531 PDO_HANDLE_STMT_ERR ();
534532 RETURN_FALSE ;
535533}
@@ -2108,6 +2106,14 @@ static PHP_METHOD(PDOStatement, debugDumpParams)
21082106 stmt -> query_stringlen ,
21092107 (int ) stmt -> query_stringlen , stmt -> query_string );
21102108
2109+ /* show parsed SQL if emulated prepares enabled */
2110+ /* pointers will be equal if PDO::query() was invoked */
2111+ if (stmt -> active_query_string != NULL && stmt -> active_query_string != stmt -> query_string ) {
2112+ php_stream_printf (out , "Sent SQL: [%zd] %.*s\n" ,
2113+ stmt -> active_query_stringlen ,
2114+ (int ) stmt -> active_query_stringlen , stmt -> active_query_string );
2115+ }
2116+
21112117 php_stream_printf (out , "Params: %d\n" ,
21122118 stmt -> bound_params ? zend_hash_num_elements (stmt -> bound_params ) : 0 );
21132119
@@ -2317,6 +2323,9 @@ PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt)
23172323 if (stmt -> methods && stmt -> methods -> dtor ) {
23182324 stmt -> methods -> dtor (stmt );
23192325 }
2326+ if (stmt -> active_query_string && stmt -> active_query_string != stmt -> query_string ) {
2327+ efree (stmt -> active_query_string );
2328+ }
23202329 if (stmt -> query_string ) {
23212330 efree (stmt -> query_string );
23222331 }
0 commit comments