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.76742 for PDO MySQL Bug #76742

Patch version 2020-07-30 03:25 UTC

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

Developer: houxiaoxian1111@163.com

diff -uprN 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-07-30 11:10:49.000000000 +0800
@@ -42,6 +42,54 @@
 #	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_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 -uprN 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-07-30 11:11:26.000000000 +0800
@@ -122,7 +122,15 @@ static void pdo_mysql_stmt_set_row_count
 	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 -uprN 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-07-30 11:09:53.000000000 +0800
@@ -154,6 +154,7 @@ extern pdo_driver_t pdo_mysql_driver;
 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;
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC