cvs: php4 /ext/mysql php_mysql.c
| From: | Sterling Hughes | Date: | Mon, 25 Mar 2002 01:07:23 +0000 |
| Subject: | cvs: php4 /ext/mysql php_mysql.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-10672@lists.php.net to get a copy of this message | ||
sterling Sun Mar 24 20:07:23 2002 EDT
Modified files:
/php4/ext/mysql php_mysql.c
Log:
clean up mysql_real_escape_string() a bit
# I really think we should just add a database handle
# parameter to mysql_escape_string()
Index: php4/ext/mysql/php_mysql.c
diff -u php4/ext/mysql/php_mysql.c:1.126 php4/ext/mysql/php_mysql.c:1.127
--- php4/ext/mysql/php_mysql.c:1.126 Sun Mar 24 18:33:07 2002
+++ php4/ext/mysql/php_mysql.c Sun Mar 24 20:07:23 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.c,v 1.126 2002/03/24 23:33:07 zak Exp $ */
+/* $Id: php_mysql.c,v 1.127 2002/03/25 01:07:23 sterling Exp $ */
/* TODO:
@@ -1515,35 +1515,28 @@
{
zval *mysql_link = NULL;
char *str;
- int id = -1, str_len;
+ char *new_str;
+ int id = -1, str_len, new_str_len;
php_mysql_conn *mysql;
- switch(ZEND_NUM_ARGS())
- {
- case 1:
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&str,
&str_len)==FAILURE) {
- RETURN_FALSE;
- }
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
- break;
- case 2:
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr",&str, &str_len,
&mysql_link)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
+
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &str, &str_len,
&mysql_link) == FAILURE) {
+ return;
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link",
le_link, le_plink);
-
- /* the maximum size of the new string is 2x the length of the
- * original string (every chas to be scaped)
- */
- Z_STRVAL_P(return_value) = (char *)emalloc(str_len * 2 + 1); // one extra byte for '\0'
- Z_STRLEN_P(return_value) = mysql_real_escape_string(&mysql->conn, Z_STRVAL_P(return_value),
str, str_len);
- Z_TYPE_P(return_value) = IS_STRING;
+ if (mysql_link == NULL) {
+ id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(id);
+ }
+ else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link",
le_link, le_plink);
+ }
+
+ new_str = emalloc(str_len * 2 + 1);
+ new_str_len = mysql_real_escape_string(&mysql->conn, new_str, str, str_len);
+ new_str = erealloc(new_str, new_str_len);
+
+ RETURN_STRINGL(new_str, new_str_len, 0);
}
/* }}} */