]> granicus.if.org Git - php/commitdiff
Added mysql_escape_String()
authorZeev Suraski <zeev@php.net>
Wed, 11 Oct 2000 18:27:21 +0000 (18:27 +0000)
committerZeev Suraski <zeev@php.net>
Wed, 11 Oct 2000 18:27:21 +0000 (18:27 +0000)
NEWS
ext/mysql/php_mysql.c
ext/mysql/php_mysql.h

diff --git a/NEWS b/NEWS
index 20132adc48318e21e60d6505edfea16f5cf1efff..0b0b8c77be8186cf562281e8632b538a56ca1640 100644 (file)
--- 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
index 35645bf6af9f983914de615e09cdecef829c0a8f..8f06268260e7da8123ec9d0326b6797d18270292 100644 (file)
@@ -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)
index 21de02e71da9b0c128d5e13b4fd769080bf87c0f..6d7a1a8611fedd99c73f38ac6331d30fb31a39d1 100644 (file)
@@ -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;