com php-src: change mysql_[p]connect() to return errors by reference: ext/mysql/php_mysql.c

From: Date: Thu, 12 Dec 2013 08:47:40 +0000
Subject: com php-src: change mysql_[p]connect() to return errors by reference: ext/mysql/php_mysql.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-76653@lists.php.net to get a copy of this message
Commit: eb289b501583a137c39c64fbb421a0759dc5cbf0 Author: Antony Dovgal <tony@daylessday.org> Sat, 31 Dec 2011 00:30:31 +0400 Committer: Antony Dovgal <tony2001@php.net> Thu, 12 Dec 2013 12:47:40 +0400 Parents: d494fa8a99a6ea6ec374effbbf31c56189ba9796 Branches: badoo-5..5_mysqlnd Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eb289b501583a137c39c64fbb421a0759dc5cbf0 Log: change mysql_[p]connect() to return errors by reference Changed paths: M ext/mysql/php_mysql.c Diff: diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 88bb9ab..46a5e9e 100644 --- a/ext/mysql/php_mysql..c +++ b/ext/mysql/php_mysql.c @@ -730,6 +730,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) #endif zend_bool free_host=0, new_link=0; long connect_timeout; + zval *err_num = NULL, *err_str = NULL; php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, @@ -775,15 +776,15 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } else { /* mysql_pconnect does not support new_link parameter */ if (persistent) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!l", &host_and_port, &host_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!lzz", &host_and_port, &host_len, &user, &user_len, &passwd, &passwd_len, - &client_flags)==FAILURE) { + &client_flags, &err_num, &err_str)==FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!bl", &host_and_port, &host_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!s!blzz", &host_and_port, &host_len, &user, &user_len, &passwd, &passwd_len, - &new_link, &client_flags)==FAILURE) { + &new_link, &client_flags, &err_num, &err_str)==FAILURE) { return; } } @@ -894,9 +895,11 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(MySG(connect_error)); } MySG(connect_error) = estrdup(mysql_error(mysql->conn)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error)); #if defined(HAVE_MYSQL_ERRNO) MySG(connect_errno) = mysql_errno(mysql->conn); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno: %ld)", MySG(connect_error), MySG(connect_errno)); +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error)); #endif free(mysql); efree(hashed_details); @@ -943,6 +946,10 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) MYSQL_DO_CONNECT_RETURN_FALSE(); } mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile)); + if (err_num) { + zval_dtor(err_num); + ZVAL_LONG(err_num, 2006); + } } } else { #ifdef MYSQL_USE_MYSQLND @@ -984,6 +991,15 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (MySG(max_links) != -1 && MySG(num_links) >= MySG(max_links)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MySG(num_links)); efree(hashed_details); + + if (err_num) { + zval_dtor(err_num); + ZVAL_LONG(err_num, -1); + } + if (err_str) { + zval_dtor(err_str); + ZVAL_STRING(err_str, "Too many open links", 1); + } MYSQL_DO_CONNECT_RETURN_FALSE(); } @@ -1021,9 +1037,11 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(MySG(connect_error)); } MySG(connect_error) = estrdup(mysql_error(mysql->conn)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error)); #if defined(HAVE_MYSQL_ERRNO) MySG(connect_errno) = mysql_errno(mysql->conn); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno: %ld)", MySG(connect_error), MySG(connect_errno)); +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error)); #endif /* free mysql structure */ #ifdef MYSQL_USE_MYSQLND @@ -1031,6 +1049,17 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) #endif efree(hashed_details); efree(mysql); + +#if defined(HAVE_MYSQL_ERRNO) + if (err_num) { + zval_dtor(err_num); + ZVAL_LONG(err_num, MySG(connect_errno)); + } +#endif + if (err_str) { + zval_dtor(err_str); + ZVAL_STRING(err_str, MySG(connect_error), 1); + } MYSQL_DO_CONNECT_RETURN_FALSE(); } mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));

« previous php.cvs (#76653) next »