php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52384
Patch pdo_debugDumpParams_p3.txt revision 2010-07-20 21:44 UTC by jonah dot harris at gmail dot com

Patch pdo_debugDumpParams_p3.txt for PDO related Bug #52384

Patch version 2010-07-20 21:44 UTC

Return to Bug #52384 | Download this patch
Patch Revisions:

Developer: jonah.harris@gmail.com

diff -ur php5.2-201007201430/ext/pdo/pdo_stmt.c php5.2-201007201430-pdofix/ext/pdo/pdo_stmt.c
--- php5.2-201007201430/ext/pdo/pdo_stmt.c	2010-06-16 20:41:23.000000000 -0400
+++ php5.2-201007201430-pdofix/ext/pdo/pdo_stmt.c	2010-07-20 16:16:46.144446472 -0400
@@ -2167,17 +2167,19 @@
 		RETURN_FALSE;
 	}
 	
-	php_stream_printf(out TSRMLS_CC, "SQL: [%d] %.*s\n",
+	php_stream_printf(out TSRMLS_CC, "SQL   : [len = %d] %.*s\n",
 		stmt->query_stringlen,
 		stmt->query_stringlen, stmt->query_string);
 
-	php_stream_printf(out TSRMLS_CC, "Params:  %d\n",
+	php_stream_printf(out TSRMLS_CC, "Params: %d\n",
 		stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0);
 	
 	if (stmt->bound_params) {
 		zend_hash_internal_pointer_reset_ex(stmt->bound_params, &pos);
 		while (SUCCESS == zend_hash_get_current_data_ex(stmt->bound_params,
 				(void**)&param, &pos)) {
+			zval param_copy;
+			int use_copy;
 			char *str;
 			uint len;
 			ulong num;
@@ -2188,11 +2190,25 @@
 				php_stream_printf(out TSRMLS_CC, "Key: Name: [%d] %.*s\n", len, len, str);
 			}
 
-			php_stream_printf(out TSRMLS_CC, "paramno=%d\nname=[%d] \"%.*s\"\nis_param=%d\nparam_type=%d\n",
+			/*
+			 * Make the parameter value printable.  While there are a few different
+			 * ways to do this, this seems simplest for what we want.
+			 */
+			zend_make_printable_zval(param->parameter, &param_copy, &use_copy);
+
+			php_stream_printf(out TSRMLS_CC, "paramno=%d\nname=[%d] \"%.*s\"\nis_param=%d\nparam_type=%d\nvalue=%s\n",
 				param->paramno, param->namelen, param->namelen, param->name ? param->name : "",
 				param->is_param,
-				param->param_type);
+				param->param_type,
+				(Z_TYPE_P(param->parameter) == IS_NULL)
+					? "NULL"
+					: (use_copy) ? Z_STRVAL_P(&param_copy)
+								 : Z_STRVAL_P(param->parameter));
 			
+			if (use_copy) {
+				zval_dtor(&param_copy);
+			}
+
 			zend_hash_move_forward_ex(stmt->bound_params, &pos);
 		}
 	}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC