From: Georg Richter Date: Sat, 21 May 2005 08:54:57 +0000 (+0000) Subject: MFH: X-Git-Tag: php-5.0.5RC1~266 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ebec35f646b0c576e6f4a6f8e5af6577fe27f495;p=php MFH: - fix for bug #33090 (mysqli_prepare doesn't return an error) - mysql_set_charset now works for MySQL >= 5.0.6 --- diff --git a/NEWS b/NEWS index ab05506418..094745266b 100644 --- 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) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 3d2686bc04..6edf95122e 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -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); } } diff --git a/ext/mysqli/php_mysqli.h b/ext/mysqli/php_mysqli.h index 4bbfd36561..dc0e1dcb33 100644 --- a/ext/mysqli/php_mysqli.h +++ b/ext/mysqli/php_mysqli.h @@ -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 index 0000000000..5c1cba961e --- /dev/null +++ b/ext/mysqli/tests/bug33090.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #33090 +--SKIPIF-- + +--FILE-- +prepare("this makes no sense"))) { + printf("%d\n", $link->errno); + printf("%s\n", $link->sqlstate); + } + $link->close(); +?> +--EXPECT-- +1064 +42000