]> granicus.if.org Git - php/commitdiff
MFH:
authorGeorg Richter <georg@php.net>
Sat, 21 May 2005 08:54:57 +0000 (08:54 +0000)
committerGeorg Richter <georg@php.net>
Sat, 21 May 2005 08:54:57 +0000 (08:54 +0000)
- fix for bug #33090 (mysqli_prepare doesn't return an error)
- mysql_set_charset now works for MySQL >= 5.0.6

NEWS
ext/mysqli/mysqli_api.c
ext/mysqli/php_mysqli.h
ext/mysqli/tests/bug33090.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index ab0550641837809313c3d9321639ce669ee1c331..094745266be5d0a7b8f529f621cb975f1b135489 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ PHP                                                                        NEWS
 - Fixed ext/mysqli to allocate less memory when fetching bound params
   of type (MEDIUM|LONG)BLOB/(MEDIUM|LONG)TEXT. (Andrey)
 - Fixed memory corruption in ImageTTFText() with 64bit systems. (Andrey)
+- Fixed bug #33090 (mysqli_prepare doesn't return an error). (Georg)
 - Fixed bug #33076 (str_ireplace() incorrectly counts result string length 
   and may cause segfault). (Tony)
 - Fixed bug #33059 (crash when moving xml attribute set in dtd). (Ilia)
index 3d2686bc04fe0d08886d5d875e786e2d51ef2115..6edf95122e0d55186c92fda580403d8d5b959b19 100644 (file)
@@ -1074,7 +1074,7 @@ PHP_FUNCTION(mysqli_kill)
 }
 /* }}} */
 
-/* {{{ proto mysqli_set_local_infile_default(object link)
+/* {{{ proto void mysqli_set_local_infile_default(object link)
    unsets user defined handler for load local infile command */
 PHP_FUNCTION(mysqli_set_local_infile_default)
 {
@@ -1279,14 +1279,22 @@ PHP_FUNCTION(mysqli_prepare)
 
        if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
                if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
-                       if (stmt->stmt->last_errno) {
-                               /* if we close the statement handle, we have to copy the errors to connection handle */
-                               mysql->mysql->net.last_errno = stmt->stmt->last_errno;
-                               strcpy(mysql->mysql->net.last_error, stmt->stmt->last_error);
-                               strcpy(mysql->mysql->net.sqlstate, stmt->stmt->sqlstate);
-                       }
+                       char  last_error[MYSQL_ERRMSG_SIZE];
+                       char  sqlstate[SQLSTATE_LENGTH+1];      
+                       unsigned int last_errno;
+
+                       /* mysql_stmt_close clears errors, so we have to store them temporarily */
+                       last_errno = stmt->stmt->last_errno;
+                       memcpy(last_error, stmt->stmt->last_error, MYSQL_ERRMSG_SIZE);
+                       memcpy(sqlstate, mysql->mysql->net.sqlstate, SQLSTATE_LENGTH+1);
+
                        mysql_stmt_close(stmt->stmt);
                        stmt->stmt = NULL;
+
+                       /* restore error messages */
+                       mysql->mysql->net.last_errno = last_errno;
+                       memcpy(mysql->mysql->net.last_error, last_error, MYSQL_ERRMSG_SIZE);
+                       memcpy(mysql->mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH+1);
                }
        } 
        
index 4bbfd365614237fdcceb292a3b6ebad93f7b67a3..dc0e1dcb33c93e296f070f38c17af6455b71f783 100644 (file)
@@ -95,7 +95,7 @@ typedef struct {
 #define PHP_MYSQLI_API
 #endif
 
-#if MYSQL_VERSION_ID > 40112 && MYSQL_VERSION_ID < 50000
+#if (MYSQL_VERSION_ID > 40112 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID > 50005
 #define HAVE_MYSQLI_SET_CHARSET
 #endif
 
diff --git a/ext/mysqli/tests/bug33090.phpt b/ext/mysqli/tests/bug33090.phpt
new file mode 100644 (file)
index 0000000..5c1cba9
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Bug #33090
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+       include ("connect.inc");
+
+       /*** test mysqli_connect 127.0.0.1 ***/
+       $link = mysqli_connect($host, $user, $passwd);
+       mysqli_select_db($link, "test");
+
+       if (!($link->prepare("this makes no sense"))) {
+               printf("%d\n", $link->errno);
+               printf("%s\n", $link->sqlstate);
+       }       
+       $link->close();
+?>
+--EXPECT--
+1064
+42000