diff options
Diffstat (limited to 'ext/mysql/php_mysql.c')
-rw-r--r-- | ext/mysql/php_mysql.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 0d5584301..42a22989d 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_mysql.c,v 1.213.2.6.2.5 2006/08/02 10:04:11 tony2001 Exp $ */ +/* $Id: php_mysql.c,v 1.213.2.6.2.10 2007/04/23 09:32:44 tony2001 Exp $ */ /* TODO: * @@ -447,9 +447,9 @@ PHP_MINFO_FUNCTION(mysql) php_info_print_table_start(); php_info_print_table_header(2, "MySQL Support", "enabled"); - sprintf(buf, "%ld", MySG(num_persistent)); + snprintf(buf, sizeof(buf), "%ld", MySG(num_persistent)); php_info_print_table_row(2, "Active Persistent Links", buf); - sprintf(buf, "%ld", MySG(num_links)); + snprintf(buf, sizeof(buf), "%ld", MySG(num_links)); php_info_print_table_row(2, "Active Links", buf); php_info_print_table_row(2, "Client API version", mysql_get_client_info()); #if !defined (PHP_WIN32) && !defined (NETWARE) @@ -519,9 +519,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } host_and_port=passwd=NULL; user=php_get_current_user(); - hashed_details_length = strlen(user)+5+3; - hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "mysql__%s_", user); + hashed_details_length = spprintf(&hashed_details, 0, "mysql__%s_", user); client_flags = CLIENT_INTERACTIVE; } else { host_and_port = MySG(default_host); @@ -617,9 +615,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } } - hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host_and_port))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); - hashed_details = (char *) emalloc(hashed_details_length+1); - sprintf(hashed_details, "mysql_%s_%s_%s", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd)); + hashed_details_length = spprintf(&hashed_details, 0, "mysql_%s_%s_%s_%d", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd), client_flags); } /* We cannot use mysql_port anymore in windows, need to use @@ -673,8 +669,9 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) #if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */ mysql_init(&mysql->conn); - if (connect_timeout != -1) + if (connect_timeout != -1) { mysql_options(&mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout); + } if (mysql_real_connect(&mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL) { #else @@ -778,8 +775,9 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) #if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */ mysql_init(&mysql->conn); - if (connect_timeout != -1) - mysql_options(&mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout); + if (connect_timeout != -1) { + mysql_options(&mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout); + } if (mysql_real_connect(&mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL) { #else @@ -1235,9 +1233,9 @@ static void php_mysql_do_query_general(zval **query, zval **mysql_link, int link if (!strncasecmp("select", Z_STRVAL_PP(query), 6)){ MYSQL_ROW row; - char *newquery = (char *)emalloc(Z_STRLEN_PP(query) + 10); - sprintf ((char *)newquery, "EXPLAIN %s", Z_STRVAL_PP(query)); - mysql_real_query(&mysql->conn, newquery, strlen(newquery)); + char *newquery; + int newql = spprintf (&newquery, 0, "EXPLAIN %s", Z_STRVAL_PP(query)); + mysql_real_query(&mysql->conn, newquery, newql); efree (newquery); if (mysql_errno(&mysql->conn)) { php_error_docref("http://www.mysql.com/doc" TSRMLS_CC, E_WARNING, "%s", mysql_error(&mysql->conn)); |