php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #76742
Patch patch.79914 revision 2020-08-08 00:53 UTC by houxiaoxian1111 at 163 dot com
revision 2020-08-05 02:31 UTC by houxiaoxian1111 at 163 dot com
Patch patch.76742 revision 2020-07-30 03:25 UTC by houxiaoxian1111 at 163 dot com

Patch patch.79914 for PDO MySQL Bug #76742

Patch version 2020-08-08 00:53 UTC

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

Developer: houxiaoxian1111@163.com

diff -up origin/php-7.1.11/ext/pdo_mysql/mysql_driver.c new/php-7.1.11/ext/pdo_mysql/mysql_driver.c
--- origin/php-7.1.11/ext/pdo_mysql/mysql_driver.c	2017-10-25 15:04:36.000000000 +0800
+++ new/php-7.1.11/ext/pdo_mysql/mysql_driver.c	2020-08-08 08:44:30.000000000 +0800
@@ -42,6 +42,55 @@
 #	define pdo_mysql_init(persistent) mysql_init(NULL)
 #endif
 
+/* {{{ _pdo_mysql_stmt_error */
+
+int _pdo_mysql_stmt_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line)
+{
+        pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
+        pdo_error_type *pdo_err;
+        pdo_mysql_error_info *einfo;
+        pdo_mysql_stmt *S = NULL;
+
+
+        PDO_DBG_ENTER("_pdo_mysql_stmt_error");
+        PDO_DBG_INF_FMT("file=%s line=%d", file, line);
+        S = (pdo_mysql_stmt*)stmt->driver_data;
+        pdo_err = &stmt->error_code;
+        einfo   = &S->einfo;
+
+        einfo->errcode = mysql_errno(H->server);
+        einfo->file = file;
+        einfo->line = line;
+
+        if (einfo->errcode) {
+                if (einfo->errcode == 2014) {
+                        einfo->errmsg = pestrdup(
+                                "Cannot execute queries while other unbuffered queries are active.  "
+                                "Consider using PDOStatement::fetchAll().  Alternatively, if your code "
+                                "is only ever going to run against mysql, you may enable query "
+                                "buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.",
+                                dbh->is_persistent);
+                } else if (einfo->errcode == 2057) {
+                        einfo->errmsg = pestrdup(
+                                "A stored procedure returning result sets of different size was called. "
+                                "This is not supported by libmysql",
+                                dbh->is_persistent);
+
+                } else {
+                        einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
+                }
+        } else { /* no error */
+                strcpy(*pdo_err, PDO_ERR_NONE);
+                PDO_DBG_RETURN(0);
+        }
+        strcpy(*pdo_err, mysql_sqlstate(H->server));
+
+        PDO_DBG_INF("Throwing exception");
+        zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode, "SQLSTATE[%s] [%d] %s",
+                                *pdo_err, einfo->errcode, einfo->errmsg);
+        PDO_DBG_RETURN(einfo->errcode);
+}
+
 /* {{{ _pdo_mysql_error */
 int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line)
 {
diff -up origin/php-7.1.11/ext/pdo_mysql/mysql_statement.c new/php-7.1.11/ext/pdo_mysql/mysql_statement.c
--- origin/php-7.1.11/ext/pdo_mysql/mysql_statement.c	2017-10-25 15:04:36.000000000 +0800
+++ new/php-7.1.11/ext/pdo_mysql/mysql_statement.c	2020-08-08 08:45:15.000000000 +0800
@@ -119,10 +119,19 @@ static void pdo_mysql_stmt_set_row_count
 {
 	zend_long row_count;
 	pdo_mysql_stmt *S = stmt->driver_data;
+	pdo_mysql_db_handle *H = S->H;
 	row_count = (zend_long) mysql_stmt_affected_rows(S->stmt);
 	if (row_count != (zend_long)-1) {
 		stmt->row_count = row_count;
-	}
+	}else {
+        	if (!H->buffered) {
+                	S->result = mysql_use_result(H->server);
+        	} else {
+                	S->result = mysql_store_result(H->server);
+        	}
+        	pdo_mysql_error_stmt_emulate_false(stmt);                
+        	PDO_DBG_VOID_RETURN;
+    	}
 }
 /* }}} */
 
diff -up origin/php-7.1.11/ext/pdo_mysql/php_pdo_mysql_int.h new/php-7.1.11/ext/pdo_mysql/php_pdo_mysql_int.h
--- origin/php-7.1.11/ext/pdo_mysql/php_pdo_mysql_int.h	2017-10-25 15:04:36.000000000 +0800
+++ new/php-7.1.11/ext/pdo_mysql/php_pdo_mysql_int.h	2020-08-08 08:43:59.000000000 +0800
@@ -150,10 +150,12 @@ typedef struct {
 } pdo_mysql_stmt;
 
 extern pdo_driver_t pdo_mysql_driver;
+extern int _pdo_mysql_stmt_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
 
 extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
 #define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__)
 #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__)
+#define pdo_mysql_error_stmt_emulate_false(s) _pdo_mysql_stmt_error(stmt->dbh, stmt, __FILE__, __LINE__)
 
 extern struct pdo_stmt_methods mysql_stmt_methods;
 
Common subdirectories: origin/php-7.1.11/ext/pdo_mysql/tests and new/php-7.1.11/ext/pdo_mysql/tests
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC