CVS update: php3/functions
| From: | zeev | Date: | Sat, 06 Feb 1999 02:31:16 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3929@lists.php.net to get a copy of this message | ||
Date: Friday February 5, 1999 @ 21:31
Author: zeev
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv12655/functions
Modified Files:
mysql.c
Log Message:
Add a new optional argument to mysql_fetch_array()
Index: php3/functions/mysql.c
diff -c php3/functions/mysql.c:1.178 php3/functions/mysql.c:1.179
*** php3/functions/mysql.c:1.178 Wed Jan 20 15:48:02 1999
--- php3/functions/mysql.c Fri Feb 5 21:31:16 1999
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: mysql.c,v 1.178 1999/01/20 20:48:02 eschmid Exp $ */
/* TODO:
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: mysql.c,v 1.179 1999/02/06 02:31:16 zeev Exp $ */
/* TODO:
***************
*** 98,103 ****
--- 98,106 ----
#define mysql_row_length_type unsigned int
#endif
+ #define MYSQL_ASSOC 1<<0
+ #define MYSQL_NUM 1<<1
+ #define MYSQL_BOTH (MYSQL_ASSOC|MYSQL_NUM)
function_entry mysql_functions[] = {
{"mysql_connect", php3_mysql_connect, NULL},
***************
*** 303,308 ****
--- 306,315 ----
#endif
mysql_module_entry.type = type;
+ REGISTER_LONG_CONSTANT("MYSQL_ASSOC", MYSQL_ASSOC, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MYSQL_NUM", MYSQL_NUM, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MYSQL_BOTH", MYSQL_BOTH, CONST_CS | CONST_PERSISTENT);
+
return SUCCESS;
}
***************
*** 1419,1482 ****
}
/* }}} */
- /* {{{ proto array mysql_fetch_row(int result)
- Get a result row as an enumerated array */
- void php3_mysql_fetch_row(INTERNAL_FUNCTION_PARAMETERS)
- {
- pval *result;
- MYSQL_RES *mysql_result;
- MYSQL_ROW mysql_row;
- mysql_row_length_type *mysql_row_lengths;
- int type;
- int num_fields;
- int i;
- MySQL_TLS_VARS;
-
-
- if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long(result);
- mysql_result = (MYSQL_RES *) php3_list_find(result->value.lval,&type);
-
- if (type!=MySQL_GLOBAL(php3_mysql_module).le_result) {
- php3_error(E_WARNING,"%d is not a MySQL result index",result->value.lval);
- RETURN_FALSE;
- }
- if ((mysql_row=mysql_fetch_row(mysql_result))==NULL
- || (mysql_row_lengths=mysql_fetch_lengths(mysql_result))==NULL) {
- RETURN_FALSE;
- }
- if (array_init(return_value)==FAILURE) {
- RETURN_FALSE;
- }
- num_fields = mysql_num_fields(mysql_result);
-
- for (i=0; i<num_fields; i++) {
- if (mysql_row[i]) {
- #ifndef PHP_31 /* FIXME cannot access php3_ini in modules */
- if (php3_ini.magic_quotes_runtime) {
- int len;
- char *tmp=_php3_addslashes(mysql_row[i],mysql_row_lengths[i],&len,0);
-
- add_index_stringl(return_value, i, tmp, len, 0);
- } else
- #endif
- {
- add_index_stringl(return_value, i, mysql_row[i], mysql_row_lengths[i], 1);
- }
- } else {
- /* NULL field, don't set it */
- /*add_index_stringl(return_value, i, empty_string, 0, 1);*/
- }
- }
- }
- /* }}} */
! static void php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS)
{
! pval *result;
MYSQL_RES *mysql_result;
MYSQL_ROW mysql_row;
MYSQL_FIELD *mysql_field;
--- 1426,1435 ----
}
/* }}} */
! static void php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
{
! pval *result, *arg2;
MYSQL_RES *mysql_result;
MYSQL_ROW mysql_row;
MYSQL_FIELD *mysql_field;
***************
*** 1484,1497 ****
int type;
int num_fields;
int i;
- pval *pval_ptr;
MySQL_TLS_VARS;
!
! if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
! WRONG_PARAM_COUNT;
}
convert_to_long(result);
mysql_result = (MYSQL_RES *) php3_list_find(result->value.lval,&type);
--- 1437,1467 ----
int type;
int num_fields;
int i;
MySQL_TLS_VARS;
!
! switch (ARG_COUNT(ht)) {
! case 1:
! if (getParameters(ht, 1, &result)==FAILURE) {
! RETURN_FALSE;
! }
! if (!result_type) {
! result_type = MYSQL_BOTH;
! }
! break;
! case 2:
! if (getParameters(ht, 2, &result, &arg2)==FAILURE) {
! RETURN_FALSE;
! }
! convert_to_long(arg2);
! result_type = arg2->value.lval;
! break;
! default:
! WRONG_PARAM_COUNT;
! break;
}
+
convert_to_long(result);
mysql_result = (MYSQL_RES *) php3_list_find(result->value.lval,&type);
***************
*** 1512,1530 ****
mysql_field_seek(mysql_result,0);
for (mysql_field=mysql_fetch_field(mysql_result),i=0; mysql_field;
mysql_field=mysql_fetch_field(mysql_result),i++) {
if (mysql_row[i]) {
- #ifndef PHP_31 /* FIXME cannot access php3_ini in modules */
if (php3_ini.magic_quotes_runtime) {
! int len;
! char *tmp=_php3_addslashes(mysql_row[i],mysql_row_lengths[i],&len,0);
!
! add_get_index_stringl(return_value, i, tmp, len, (void **) &pval_ptr, 0);
! } else
! #endif
! {
! add_get_index_stringl(return_value, i, mysql_row[i], mysql_row_lengths[i], (void **)
&pval_ptr, 1);
}
- _php3_hash_pointer_update(return_value->value.ht, mysql_field->name,
strlen(mysql_field->name)+1, pval_ptr);
} else {
/* NULL field, don't set it */
/* add_get_index_stringl(return_value, i, empty_string, 0, (void **) &pval_ptr); */
--- 1482,1507 ----
mysql_field_seek(mysql_result,0);
for (mysql_field=mysql_fetch_field(mysql_result),i=0; mysql_field;
mysql_field=mysql_fetch_field(mysql_result),i++) {
+ char *data;
+ int data_len;
+ int should_copy;
+
if (mysql_row[i]) {
if (php3_ini.magic_quotes_runtime) {
! data=_php3_addslashes(mysql_row[i],mysql_row_lengths[i],&data_len,0);
! should_copy=0;
! } else {
! data = mysql_row[i];
! data_len = mysql_row_lengths[i];
! should_copy=1;
! }
! if (result_type & MYSQL_ASSOC) {
! add_assoc_stringl(return_value, mysql_field->name, data, data_len, should_copy);
! should_copy=1;
! }
! if (result_type & MYSQL_NUM) {
! add_index_stringl(return_value, i, data, data_len, should_copy);
}
} else {
/* NULL field, don't set it */
/* add_get_index_stringl(return_value, i, empty_string, 0, (void **) &pval_ptr); */
***************
*** 1532,1553 ****
}
}
/* {{{ proto object mysql_fetch_object(int result)
Fetch a result row as an object */
void php3_mysql_fetch_object(INTERNAL_FUNCTION_PARAMETERS)
{
! php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (return_value->type==IS_ARRAY) {
return_value->type=IS_OBJECT;
}
}
/* }}} */
/* {{{ proto array mysql_fetch_array(int result)
Fetch a result row as an associative array */
void php3_mysql_fetch_array(INTERNAL_FUNCTION_PARAMETERS)
{
! php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
/* }}} */
--- 1509,1541 ----
}
}
+
+ /* {{{ proto array mysql_fetch_row(int result)
+ Get a result row as an enumerated array */
+ void php3_mysql_fetch_row(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQL_NUM);
+ }
+ /* }}} */
+
+
/* {{{ proto object mysql_fetch_object(int result)
Fetch a result row as an object */
void php3_mysql_fetch_object(INTERNAL_FUNCTION_PARAMETERS)
{
! php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
if (return_value->type==IS_ARRAY) {
return_value->type=IS_OBJECT;
}
}
/* }}} */
+
/* {{{ proto array mysql_fetch_array(int result)
Fetch a result row as an associative array */
void php3_mysql_fetch_array(INTERNAL_FUNCTION_PARAMETERS)
{
! php3_mysql_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net