From: Zeev Suraski Date: Wed, 11 Oct 2000 18:27:21 +0000 (+0000) Subject: Added mysql_escape_String() X-Git-Tag: php-4.0.3~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dea72ba6a4d27e4e972078ddd9774b494ac42039;p=php Added mysql_escape_String() --- diff --git a/NEWS b/NEWS index 20132adc48..0b0b8c77be 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ PHP 4.0 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 11 Oct 2000, Version 4.0.3 +- Added mysql_escape_string() (Peter A. Savitch and & Brian Wang) - Fixed many possible crash bugs with improper use of the printf() family of functions (Andi) - Fixed a problem that allowed users to override admin_value's and admin_flag's diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c index 35645bf6af..8f06268260 100644 --- a/ext/mysql/php_mysql.c +++ b/ext/mysql/php_mysql.c @@ -120,6 +120,7 @@ function_entry mysql_functions[] = { PHP_FE(mysql_field_len, NULL) PHP_FE(mysql_field_type, NULL) PHP_FE(mysql_field_flags, NULL) + PHP_FE(mysql_escape_string, NULL) /* for downwards compatability */ PHP_FALIAS(mysql, mysql_db_query, NULL) @@ -1073,6 +1074,27 @@ PHP_FUNCTION(mysql_affected_rows) /* }}} */ +/* {{{ proto char mysql_escape_string([char string]) + Escape string for mysql query */ +PHP_FUNCTION(mysql_escape_string) +{ + zval **str; + + if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) { + ZEND_WRONG_PARAM_COUNT(); + } + convert_to_string_ex(str); + /* assume worst case situation, which is 2x of the original string. + * we don't realloc() down to the real size since it'd most probably not + * be worth it + */ + Z_STRVAL_P(return_value) = (char *) emalloc(Z_STRLEN_PP(str)*2+1); + Z_STRLEN_P(return_value) = mysql_escape_string(Z_STRVAL_P(return_value), Z_STRVAL_PP(str), Z_STRLEN_PP(str)); + return_value->type = IS_STRING; +} +/* }}} */ + + /* {{{ proto int mysql_insert_id([int link_identifier]) Get the id generated from the previous INSERT operation */ PHP_FUNCTION(mysql_insert_id) diff --git a/ext/mysql/php_mysql.h b/ext/mysql/php_mysql.h index 21de02e71d..6d7a1a8611 100644 --- a/ext/mysql/php_mysql.h +++ b/ext/mysql/php_mysql.h @@ -75,6 +75,7 @@ PHP_FUNCTION(mysql_field_table); PHP_FUNCTION(mysql_field_len); PHP_FUNCTION(mysql_field_type); PHP_FUNCTION(mysql_field_flags); +PHP_FUNCTION(mysql_escape_string); ZEND_BEGIN_MODULE_GLOBALS(mysql) long default_link;