2004-05-17 23:41:51 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| PHP Version 5 |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-01-03 11:08:10 +08:00
| Copyright ( c ) 1997 - 2014 The PHP Group |
2004-05-17 23:41:51 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
2004-05-17 23:41:51 +08:00
| that is bundled with this package in the file LICENSE , and is |
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
2004-05-17 23:41:51 +08:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Author : Wez Furlong < wez @ php . net > |
| Marcus Boerger < helly @ php . net > |
| Sterling Hughes < sterling @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
/* The PDO Statement Handle Class */
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
# include "php.h"
# include "php_ini.h"
# include "ext/standard/info.h"
2005-02-28 06:32:11 +08:00
# include "ext/standard/php_var.h"
2004-05-17 23:41:51 +08:00
# include "php_pdo.h"
# include "php_pdo_driver.h"
# include "php_pdo_int.h"
# include "zend_exceptions.h"
2005-03-21 08:29:06 +08:00
# include "zend_interfaces.h"
2005-02-07 06:11:12 +08:00
# include "php_memory_streams.h"
2004-05-17 23:41:51 +08:00
2007-08-30 22:06:12 +08:00
/* {{{ arginfo */
2011-06-18 23:56:14 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_pdostatement__void , 0 )
ZEND_END_ARG_INFO ( )
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_execute , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , bound_input_params ) /* array */
2006-03-19 06:24:05 +08:00
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_fetch , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , how )
ZEND_ARG_INFO ( 0 , orientation )
ZEND_ARG_INFO ( 0 , offset )
2006-03-19 06:24:05 +08:00
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2008-09-24 07:07:52 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_fetchobject , 0 , 0 , 0 )
2007-08-30 22:06:12 +08:00
ZEND_ARG_INFO ( 0 , class_name )
ZEND_ARG_INFO ( 0 , ctor_args ) /* array */
2006-03-19 06:24:05 +08:00
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_fetchcolumn , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , column_number )
2006-03-19 06:24:05 +08:00
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_fetchall , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , how )
ZEND_ARG_INFO ( 0 , class_name )
ZEND_ARG_INFO ( 0 , ctor_args ) /* array */
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_bindvalue , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , paramno )
ZEND_ARG_INFO ( 0 , param )
ZEND_ARG_INFO ( 0 , type )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_bindparam , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , paramno )
ZEND_ARG_INFO ( 1 , param )
ZEND_ARG_INFO ( 0 , type )
ZEND_ARG_INFO ( 0 , maxlen )
ZEND_ARG_INFO ( 0 , driverdata )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_bindcolumn , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , column )
ZEND_ARG_INFO ( 1 , param )
ZEND_ARG_INFO ( 0 , type )
ZEND_ARG_INFO ( 0 , maxlen )
ZEND_ARG_INFO ( 0 , driverdata )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_pdostatement_setattribute , 0 )
ZEND_ARG_INFO ( 0 , attribute )
ZEND_ARG_INFO ( 0 , value )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_pdostatement_getattribute , 0 )
ZEND_ARG_INFO ( 0 , attribute )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO ( arginfo_pdostatement_getcolumnmeta , 0 )
ZEND_ARG_INFO ( 0 , column )
ZEND_END_ARG_INFO ( )
2008-10-11 03:35:34 +08:00
2007-08-30 22:06:12 +08:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_pdostatement_setfetchmode , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , mode )
ZEND_ARG_INFO ( 0 , params )
2006-03-19 06:24:05 +08:00
ZEND_END_ARG_INFO ( )
2004-05-18 02:13:03 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
2005-11-08 00:53:15 +08:00
# define PHP_STMT_GET_OBJ \
2014-04-22 18:23:03 +08:00
pdo_stmt_t * stmt = Z_PDO_STMT_P ( getThis ( ) ) ; \
2005-11-08 00:53:15 +08:00
if ( ! stmt - > dbh ) { \
2014-04-22 18:23:03 +08:00
RETURN_FALSE ; \
2005-11-08 00:53:15 +08:00
} \
2004-05-17 23:41:51 +08:00
static PHP_FUNCTION ( dbstmt_constructor ) /* { { { */
{
php_error_docref ( NULL TSRMLS_CC , E_ERROR , " You should not create a PDOStatement manually " ) ;
}
/* }}} */
2005-02-23 03:27:34 +08:00
static inline int rewrite_name_to_position ( pdo_stmt_t * stmt , struct pdo_bound_param_data * param TSRMLS_DC ) /* { { { */
2005-02-13 14:29:35 +08:00
{
if ( stmt - > bound_param_map ) {
/* rewriting :name to ? style.
* We need to fixup the parameter numbers on the parameters .
* If we find that a given named parameter has been used twice ,
* we will raise an error , as we can ' t be sure that it is safe
* to bind multiple parameters onto the same zval in the underlying
* driver */
2014-05-08 15:19:43 +08:00
char * name ;
2005-02-13 14:29:35 +08:00
int position = 0 ;
2005-07-09 01:00:28 +08:00
if ( stmt - > named_rewrite_template ) {
/* this is not an error here */
return 1 ;
}
2005-07-11 22:14:56 +08:00
if ( ! param - > name ) {
2005-07-12 11:19:44 +08:00
/* do the reverse; map the parameter number to the name */
2014-05-08 15:19:43 +08:00
if ( ( name = zend_hash_index_find_ptr ( stmt - > bound_param_map , param - > paramno ) ) ! = NULL ) {
param - > name = STR_INIT ( name , strlen ( name ) , 0 ) ;
2005-07-12 11:19:44 +08:00
return 1 ;
}
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY093 " , " parameter was not defined " TSRMLS_CC ) ;
return 0 ;
2005-07-11 22:14:56 +08:00
}
2014-05-08 15:19:43 +08:00
ZEND_HASH_FOREACH_PTR ( stmt - > bound_param_map , name ) {
if ( strncmp ( name , param - > name - > val , param - > name - > len + 1 ) ) {
2005-02-13 14:29:35 +08:00
position + + ;
continue ;
}
if ( param - > paramno > = 0 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " , " PDO refuses to handle repeating the same :named parameter for multiple positions with this driver, as it might be unsafe to do so. Consider using a separate name for each parameter instead " TSRMLS_CC ) ;
return - 1 ;
}
param - > paramno = position ;
return 1 ;
2014-04-23 10:58:08 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2005-02-13 14:29:35 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY093 " , " parameter was not defined " TSRMLS_CC ) ;
return 0 ;
}
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2005-02-13 14:29:35 +08:00
2004-05-17 23:41:51 +08:00
/* trigger callback hook for parameters */
2005-02-23 03:27:34 +08:00
static int dispatch_param_event ( pdo_stmt_t * stmt , enum pdo_param_event event_type TSRMLS_DC ) /* { { { */
2004-05-17 23:41:51 +08:00
{
int ret = 1 , is_param = 1 ;
struct pdo_bound_param_data * param ;
HashTable * ht ;
if ( ! stmt - > methods - > param_hook ) {
return 1 ;
}
2005-02-13 14:29:35 +08:00
2004-05-17 23:41:51 +08:00
ht = stmt - > bound_params ;
iterate :
if ( ht ) {
2014-04-23 10:58:08 +08:00
ZEND_HASH_FOREACH_PTR ( ht , param ) {
2004-05-17 23:41:51 +08:00
if ( ! stmt - > methods - > param_hook ( stmt , param , event_type TSRMLS_CC ) ) {
ret = 0 ;
break ;
}
2014-04-23 10:58:08 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2004-05-17 23:41:51 +08:00
}
if ( ret & & is_param ) {
ht = stmt - > bound_columns ;
is_param = 0 ;
goto iterate ;
}
return ret ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
2005-02-23 03:27:34 +08:00
int pdo_stmt_describe_columns ( pdo_stmt_t * stmt TSRMLS_DC ) /* { { { */
2004-05-17 23:41:51 +08:00
{
int col ;
stmt - > columns = ecalloc ( stmt - > column_count , sizeof ( struct pdo_column_data ) ) ;
for ( col = 0 ; col < stmt - > column_count ; col + + ) {
if ( ! stmt - > methods - > describer ( stmt , col TSRMLS_CC ) ) {
return 0 ;
}
2004-05-21 06:28:53 +08:00
/* if we are applying case conversions on column names, do so now */
if ( stmt - > dbh - > native_case ! = stmt - > dbh - > desired_case & & stmt - > dbh - > desired_case ! = PDO_CASE_NATURAL ) {
char * s = stmt - > columns [ col ] . name ;
switch ( stmt - > dbh - > desired_case ) {
case PDO_CASE_UPPER :
while ( * s ! = ' \0 ' ) {
* s = toupper ( * s ) ;
s + + ;
}
break ;
case PDO_CASE_LOWER :
while ( * s ! = ' \0 ' ) {
* s = tolower ( * s ) ;
s + + ;
}
break ;
default :
;
}
}
2004-05-17 23:41:51 +08:00
2005-02-13 14:29:35 +08:00
#if 0
2004-05-17 23:41:51 +08:00
/* update the column index on named bound parameters */
2004-05-21 22:09:51 +08:00
if ( stmt - > bound_params ) {
2004-05-17 23:41:51 +08:00
struct pdo_bound_param_data * param ;
if ( SUCCESS = = zend_hash_find ( stmt - > bound_params , stmt - > columns [ col ] . name ,
stmt - > columns [ col ] . namelen , ( void * * ) & param ) ) {
param - > paramno = col ;
}
}
2005-02-13 14:29:35 +08:00
# endif
2004-05-17 23:41:51 +08:00
if ( stmt - > bound_columns ) {
struct pdo_bound_param_data * param ;
2014-04-22 18:23:03 +08:00
if ( ( param = zend_hash_str_find_ptr ( stmt - > bound_columns ,
stmt - > columns [ col ] . name , stmt - > columns [ col ] . namelen ) ) ! = NULL ) {
2004-05-17 23:41:51 +08:00
param - > paramno = col ;
}
}
}
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
2005-02-23 03:27:34 +08:00
static void get_lazy_object ( pdo_stmt_t * stmt , zval * return_value TSRMLS_DC ) /* { { { */
2004-05-21 21:26:58 +08:00
{
2014-05-03 16:06:27 +08:00
if ( Z_ISUNDEF ( stmt - > lazy_object_ref ) ) {
2014-04-22 18:23:03 +08:00
pdo_row_t * row = ecalloc ( 1 , sizeof ( pdo_row_t ) ) ;
row - > stmt = stmt ;
2014-04-24 21:14:36 +08:00
zend_object_std_init ( & row - > std , pdo_row_ce TSRMLS_CC ) ;
2014-04-22 18:23:03 +08:00
ZVAL_OBJ ( & stmt - > lazy_object_ref , & row - > std ) ;
row - > std . handlers = & pdo_row_object_handlers ;
2014-04-24 21:14:36 +08:00
stmt - > std . gc . refcount + + ;
2004-05-21 21:26:58 +08:00
}
2014-04-22 18:23:03 +08:00
ZVAL_COPY ( return_value , & stmt - > lazy_object_ref ) ;
2004-05-21 21:26:58 +08:00
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
static void param_dtor ( zval * el ) /* { { { */
2004-05-17 23:41:51 +08:00
{
2014-04-22 18:23:03 +08:00
struct pdo_bound_param_data * param = ( struct pdo_bound_param_data * ) Z_PTR_P ( el ) ;
2004-05-17 23:41:51 +08:00
/* tell the driver that it is going away */
if ( param - > stmt - > methods - > param_hook ) {
2014-04-22 18:23:03 +08:00
TSRMLS_FETCH ( ) ;
2004-05-17 23:41:51 +08:00
param - > stmt - > methods - > param_hook ( param - > stmt , param , PDO_PARAM_EVT_FREE TSRMLS_CC ) ;
}
2004-05-25 22:47:22 +08:00
if ( param - > name ) {
2014-04-23 10:58:08 +08:00
STR_RELEASE ( param - > name ) ;
2004-05-25 22:47:22 +08:00
}
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( param - > parameter ) ) {
2014-04-22 18:23:03 +08:00
zval_ptr_dtor ( & param - > parameter ) ;
ZVAL_UNDEF ( & param - > parameter ) ;
2007-03-07 17:03:07 +08:00
}
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( param - > driver_params ) ) {
2014-04-22 18:23:03 +08:00
zval_ptr_dtor ( & param - > driver_params ) ;
2004-05-25 22:47:22 +08:00
}
2014-04-24 21:14:36 +08:00
efree ( param ) ;
2004-05-17 23:41:51 +08:00
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
2005-02-23 03:27:34 +08:00
static int really_register_bound_param ( struct pdo_bound_param_data * param , pdo_stmt_t * stmt , int is_param TSRMLS_DC ) /* { { { */
2004-05-17 23:41:51 +08:00
{
HashTable * hash ;
2014-04-25 11:00:35 +08:00
zval * parameter ;
2004-05-17 23:41:51 +08:00
struct pdo_bound_param_data * pparam = NULL ;
hash = is_param ? stmt - > bound_params : stmt - > bound_columns ;
if ( ! hash ) {
ALLOC_HASHTABLE ( hash ) ;
zend_hash_init ( hash , 13 , NULL , param_dtor , 0 ) ;
if ( is_param ) {
stmt - > bound_params = hash ;
} else {
stmt - > bound_columns = hash ;
}
}
2014-04-25 11:00:35 +08:00
if ( ! Z_ISREF ( param - > parameter ) ) {
parameter = & param - > parameter ;
} else {
parameter = Z_REFVAL ( param - > parameter ) ;
}
2014-05-03 16:06:27 +08:00
if ( PDO_PARAM_TYPE ( param - > param_type ) = = PDO_PARAM_STR & & param - > max_value_len < = 0 & & ! Z_ISNULL_P ( parameter ) ) {
2014-04-25 11:00:35 +08:00
if ( Z_TYPE_P ( parameter ) = = IS_DOUBLE ) {
2007-06-26 09:24:10 +08:00
char * p ;
2014-04-25 11:00:35 +08:00
int len = spprintf ( & p , 0 , " %.*H " , ( int ) EG ( precision ) , Z_DVAL_P ( parameter ) ) ;
ZVAL_STRINGL ( parameter , p , len ) ;
2014-04-22 18:23:03 +08:00
efree ( p ) ;
2007-06-26 09:24:10 +08:00
} else {
2014-04-25 11:00:35 +08:00
convert_to_string ( parameter ) ;
2007-06-26 09:24:10 +08:00
}
2014-04-30 22:32:42 +08:00
} else if ( PDO_PARAM_TYPE ( param - > param_type ) = = PDO_PARAM_INT & & ( Z_TYPE_P ( parameter ) = = IS_FALSE | | Z_TYPE_P ( parameter ) = = IS_TRUE ) ) {
2014-04-25 11:00:35 +08:00
convert_to_long ( parameter ) ;
} else if ( PDO_PARAM_TYPE ( param - > param_type ) = = PDO_PARAM_BOOL & & Z_TYPE_P ( parameter ) = = IS_LONG ) {
convert_to_boolean ( parameter ) ;
2004-05-17 23:41:51 +08:00
}
param - > stmt = stmt ;
param - > is_param = is_param ;
2014-04-22 18:23:03 +08:00
if ( Z_REFCOUNTED ( param - > driver_params ) ) {
Z_ADDREF ( param - > driver_params ) ;
2004-05-17 23:41:51 +08:00
}
2005-11-25 08:29:04 +08:00
if ( ! is_param & & param - > name & & stmt - > columns ) {
2004-05-17 23:41:51 +08:00
/* try to map the name to the column */
int i ;
for ( i = 0 ; i < stmt - > column_count ; i + + ) {
2014-04-23 10:58:08 +08:00
if ( strncmp ( stmt - > columns [ i ] . name , param - > name - > val , param - > name - > len + 1 ) = = 0 ) {
2004-05-17 23:41:51 +08:00
param - > paramno = i ;
break ;
}
}
2004-12-28 06:04:54 +08:00
/* if you prepare and then execute passing an array of params keyed by names,
* then this will trigger , and we don ' t want that */
2004-05-17 23:41:51 +08:00
if ( param - > paramno = = - 1 ) {
2011-06-01 21:23:25 +08:00
char * tmp ;
2014-04-23 10:58:08 +08:00
spprintf ( & tmp , 0 , " Did not find column name '%s' in the defined columns; it will not be bound " , param - > name - > val ) ;
2011-06-01 21:23:25 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , tmp TSRMLS_CC ) ;
efree ( tmp ) ;
2004-05-17 23:41:51 +08:00
}
2005-11-25 08:29:04 +08:00
}
2004-05-17 23:41:51 +08:00
if ( param - > name ) {
2014-04-23 10:58:08 +08:00
if ( is_param & & param - > name - > val [ 0 ] ! = ' : ' ) {
zend_string * temp = STR_ALLOC ( param - > name - > len + 1 , 0 ) ;
temp - > val [ 0 ] = ' : ' ;
2014-04-24 21:14:36 +08:00
memmove ( temp - > val + 1 , param - > name - > val , param - > name - > len + 1 ) ;
2005-07-22 22:31:20 +08:00
param - > name = temp ;
} else {
2014-04-23 10:58:08 +08:00
param - > name = STR_INIT ( param - > name - > val , param - > name - > len , 0 ) ;
2005-07-22 22:31:20 +08:00
}
2005-02-13 14:29:35 +08:00
}
2005-11-27 05:20:52 +08:00
if ( is_param & & ! rewrite_name_to_position ( stmt , param TSRMLS_CC ) ) {
if ( param - > name ) {
2014-04-23 10:58:08 +08:00
STR_RELEASE ( param - > name ) ;
2005-11-27 05:20:52 +08:00
param - > name = NULL ;
}
return 0 ;
}
2006-03-28 04:51:01 +08:00
/* ask the driver to perform any normalization it needs on the
* parameter name . Note that it is illegal for the driver to take
* a reference to param , as it resides in transient storage only
* at this time . */
2004-05-17 23:41:51 +08:00
if ( stmt - > methods - > param_hook ) {
2006-03-28 04:51:01 +08:00
if ( ! stmt - > methods - > param_hook ( stmt , param , PDO_PARAM_EVT_NORMALIZE
TSRMLS_CC ) ) {
2006-03-15 23:25:50 +08:00
if ( param - > name ) {
2014-04-23 10:58:08 +08:00
STR_RELEASE ( param - > name ) ;
2006-03-15 23:25:50 +08:00
param - > name = NULL ;
}
2005-11-16 14:32:33 +08:00
return 0 ;
}
2004-05-17 23:41:51 +08:00
}
2006-03-28 04:51:01 +08:00
/* delete any other parameter registered with this number.
* If the parameter is named , it will be removed and correctly
* disposed of by the hash_update call that follows */
2005-11-25 08:29:04 +08:00
if ( param - > paramno > = 0 ) {
zend_hash_index_del ( hash , param - > paramno ) ;
}
2006-03-28 04:51:01 +08:00
/* allocate storage for the parameter, keyed by its "canonical" name */
2005-11-25 08:29:04 +08:00
if ( param - > name ) {
2014-05-07 11:00:36 +08:00
pparam = zend_hash_update_mem ( hash , param - > name , param , sizeof ( struct pdo_bound_param_data ) ) ;
2005-11-25 08:29:04 +08:00
} else {
2014-05-07 11:00:36 +08:00
pparam = zend_hash_index_update_mem ( hash , param - > paramno , param , sizeof ( struct pdo_bound_param_data ) ) ;
2005-11-25 08:29:04 +08:00
}
2006-03-28 04:51:01 +08:00
/* tell the driver we just created a parameter */
if ( stmt - > methods - > param_hook ) {
if ( ! stmt - > methods - > param_hook ( stmt , pparam , PDO_PARAM_EVT_ALLOC
TSRMLS_CC ) ) {
/* undo storage allocation; the hash will free the parameter
* name if required */
if ( pparam - > name ) {
2014-04-23 10:58:08 +08:00
zend_hash_del ( hash , pparam - > name ) ;
2006-03-28 04:51:01 +08:00
} else {
zend_hash_index_del ( hash , pparam - > paramno ) ;
}
2007-01-28 05:53:26 +08:00
/* param->parameter is freed by hash dtor */
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & param - > parameter ) ;
2006-03-28 04:51:01 +08:00
return 0 ;
}
}
2004-05-17 23:41:51 +08:00
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
/* {{{ proto bool PDOStatement::execute([array $bound_input_params])
Execute a prepared statement , optionally binding parameters */
static PHP_METHOD ( PDOStatement , execute )
{
zval * input_params = NULL ;
int ret = 1 ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-17 23:41:51 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |a! " , & input_params ) ) {
RETURN_FALSE ;
}
2004-05-20 08:05:22 +08:00
PDO_STMT_CLEAR_ERR ( ) ;
2004-05-17 23:41:51 +08:00
if ( input_params ) {
struct pdo_bound_param_data param ;
2014-04-22 18:23:03 +08:00
zval * tmp ;
zend_string * key = NULL ;
2004-05-17 23:41:51 +08:00
ulong num_index ;
2006-08-09 22:45:00 +08:00
if ( stmt - > bound_params ) {
zend_hash_destroy ( stmt - > bound_params ) ;
FREE_HASHTABLE ( stmt - > bound_params ) ;
stmt - > bound_params = NULL ;
}
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
ZEND_HASH_FOREACH_KEY_VAL ( Z_ARRVAL_P ( input_params ) , num_index , key , tmp ) {
2004-05-17 23:41:51 +08:00
memset ( & param , 0 , sizeof ( param ) ) ;
2014-04-22 18:23:03 +08:00
if ( key ) {
2004-05-22 06:24:20 +08:00
/* yes this is correct. we don't want to count the null byte. ask wez */
2014-05-08 15:19:43 +08:00
param . name = key ;
2004-05-17 23:41:51 +08:00
param . paramno = - 1 ;
} else {
/* we're okay to be zero based here */
2014-05-17 10:28:54 +08:00
/* num_index is unsignend
2004-05-17 23:41:51 +08:00
if ( num_index < 0 ) {
2005-02-07 05:05:59 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY093 " , NULL TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
2014-05-17 10:28:54 +08:00
*/
2004-05-17 23:41:51 +08:00
param . paramno = num_index ;
}
param . param_type = PDO_PARAM_STR ;
2014-04-25 10:44:21 +08:00
ZVAL_COPY ( & param . parameter , tmp ) ;
2004-05-17 23:41:51 +08:00
if ( ! really_register_bound_param ( & param , stmt , 1 TSRMLS_CC ) ) {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( param . parameter ) ) {
2007-01-28 05:53:26 +08:00
zval_ptr_dtor ( & param . parameter ) ;
}
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
2014-04-22 18:23:03 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2004-05-17 23:41:51 +08:00
}
2004-05-18 16:59:27 +08:00
2005-01-18 12:58:50 +08:00
if ( PDO_PLACEHOLDER_NONE = = stmt - > supports_placeholders ) {
2004-05-18 23:19:31 +08:00
/* handle the emulated parameter binding,
* stmt - > active_query_string holds the query with binds expanded and
* quoted .
*/
2005-01-21 11:57:06 +08:00
ret = pdo_parse_params ( stmt , stmt - > query_string , stmt - > query_stringlen ,
& stmt - > active_query_string , & stmt - > active_query_stringlen TSRMLS_CC ) ;
if ( ret = = 0 ) {
/* no changes were made */
stmt - > active_query_string = stmt - > query_string ;
2005-02-07 00:46:18 +08:00
stmt - > active_query_stringlen = stmt - > query_stringlen ;
2009-12-03 23:24:43 +08:00
ret = 1 ;
2005-01-21 11:57:06 +08:00
} else if ( ret = = - 1 ) {
/* something broke */
PDO_HANDLE_STMT_ERR ( ) ;
2004-05-18 23:19:31 +08:00
RETURN_FALSE ;
}
2004-05-18 16:59:27 +08:00
} else if ( ! dispatch_param_event ( stmt , PDO_PARAM_EVT_EXEC_PRE TSRMLS_CC ) ) {
2004-06-14 06:09:54 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
if ( stmt - > methods - > executer ( stmt TSRMLS_CC ) ) {
2005-01-21 11:57:06 +08:00
if ( stmt - > active_query_string & & stmt - > active_query_string ! = stmt - > query_string ) {
2004-05-18 23:57:46 +08:00
efree ( stmt - > active_query_string ) ;
}
2005-01-21 11:57:06 +08:00
stmt - > active_query_string = NULL ;
2004-05-17 23:41:51 +08:00
if ( ! stmt - > executed ) {
/* this is the first execute */
2006-11-29 00:27:53 +08:00
if ( stmt - > dbh - > alloc_own_columns & & ! stmt - > columns ) {
2004-05-17 23:41:51 +08:00
/* for "big boy" drivers, we need to allocate memory to fetch
* the results into , so lets do that now */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
ret = pdo_stmt_describe_columns ( stmt TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
}
stmt - > executed = 1 ;
}
if ( ret & & ! dispatch_param_event ( stmt , PDO_PARAM_EVT_EXEC_POST TSRMLS_CC ) ) {
RETURN_FALSE ;
}
RETURN_BOOL ( ret ) ;
}
2005-01-21 11:57:06 +08:00
if ( stmt - > active_query_string & & stmt - > active_query_string ! = stmt - > query_string ) {
2004-05-18 23:57:46 +08:00
efree ( stmt - > active_query_string ) ;
}
2005-01-21 11:57:06 +08:00
stmt - > active_query_string = NULL ;
2004-05-20 08:05:22 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
/* }}} */
2005-09-12 04:32:28 +08:00
static inline void fetch_value ( pdo_stmt_t * stmt , zval * dest , int colno , int * type_override TSRMLS_DC ) /* { { { */
2004-05-17 23:41:51 +08:00
{
struct pdo_column_data * col ;
char * value = NULL ;
unsigned long value_len = 0 ;
2005-02-07 06:11:12 +08:00
int caller_frees = 0 ;
2005-10-31 11:23:38 +08:00
int type , new_type ;
2004-05-17 23:41:51 +08:00
col = & stmt - > columns [ colno ] ;
2005-10-31 11:23:38 +08:00
type = PDO_PARAM_TYPE ( col - > param_type ) ;
new_type = type_override ? PDO_PARAM_TYPE ( * type_override ) : type ;
2004-05-17 23:41:51 +08:00
value = NULL ;
value_len = 0 ;
2005-02-07 06:11:12 +08:00
stmt - > methods - > get_col ( stmt , colno , & value , & value_len , & caller_frees TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
2005-09-12 04:32:28 +08:00
switch ( type ) {
2008-07-21 21:09:28 +08:00
case PDO_PARAM_ZVAL :
if ( value & & value_len = = sizeof ( zval ) ) {
int need_copy = ( new_type ! = PDO_PARAM_ZVAL | | stmt - > dbh - > stringify ) ? 1 : 0 ;
zval * zv = * ( zval * * ) value ;
ZVAL_ZVAL ( dest , zv , need_copy , 1 ) ;
} else {
ZVAL_NULL ( dest ) ;
}
if ( Z_TYPE_P ( dest ) = = IS_NULL ) {
type = new_type ;
}
break ;
2005-01-12 11:26:46 +08:00
case PDO_PARAM_INT :
if ( value & & value_len = = sizeof ( long ) ) {
ZVAL_LONG ( dest , * ( long * ) value ) ;
break ;
}
ZVAL_NULL ( dest ) ;
break ;
case PDO_PARAM_BOOL :
if ( value & & value_len = = sizeof ( zend_bool ) ) {
ZVAL_BOOL ( dest , * ( zend_bool * ) value ) ;
break ;
}
ZVAL_NULL ( dest ) ;
break ;
2005-02-06 06:46:26 +08:00
case PDO_PARAM_LOB :
2005-02-07 06:11:12 +08:00
if ( value = = NULL ) {
ZVAL_NULL ( dest ) ;
} else if ( value_len = = 0 ) {
2009-04-23 21:26:10 +08:00
/* Warning, empty strings need to be passed as stream */
2005-10-31 11:23:38 +08:00
if ( stmt - > dbh - > stringify | | new_type = = PDO_PARAM_STR ) {
2014-04-22 18:23:03 +08:00
zend_string * buf ;
buf = php_stream_copy_to_mem ( ( php_stream * ) value , PHP_STREAM_COPY_ALL , 0 ) ;
if ( buf = = NULL ) {
2007-09-13 05:21:18 +08:00
ZVAL_EMPTY_STRING ( dest ) ;
} else {
2014-04-22 18:23:03 +08:00
ZVAL_STR ( dest , buf ) ;
2007-09-13 05:21:18 +08:00
}
2005-10-31 10:07:38 +08:00
php_stream_close ( ( php_stream * ) value ) ;
} else {
php_stream_to_zval ( ( php_stream * ) value , dest ) ;
}
2005-10-31 11:23:38 +08:00
} else if ( ! stmt - > dbh - > stringify & & new_type ! = PDO_PARAM_STR ) {
2005-02-07 06:11:12 +08:00
/* they gave us a string, but LOBs are represented as streams in PDO */
php_stream * stm ;
# ifdef TEMP_STREAM_TAKE_BUFFER
if ( caller_frees ) {
stm = php_stream_memory_open ( TEMP_STREAM_TAKE_BUFFER , value , value_len ) ;
if ( stm ) {
caller_frees = 0 ;
}
} else
# endif
{
stm = php_stream_memory_open ( TEMP_STREAM_READONLY , value , value_len ) ;
}
if ( stm ) {
php_stream_to_zval ( stm , dest ) ;
} else {
ZVAL_NULL ( dest ) ;
}
2005-11-25 11:23:17 +08:00
} else {
2014-04-22 18:23:03 +08:00
ZVAL_STRINGL ( dest , value , value_len ) ;
2005-02-07 06:11:12 +08:00
}
break ;
2004-05-17 23:41:51 +08:00
case PDO_PARAM_STR :
2005-07-12 10:40:59 +08:00
if ( value & & ! ( value_len = = 0 & & stmt - > dbh - > oracle_nulls = = PDO_NULL_EMPTY_STRING ) ) {
2014-04-22 18:23:03 +08:00
ZVAL_STRINGL ( dest , value , value_len ) ;
2004-05-20 04:38:53 +08:00
break ;
2004-05-17 23:41:51 +08:00
}
default :
ZVAL_NULL ( dest ) ;
}
2005-02-07 06:11:12 +08:00
2005-10-31 11:23:38 +08:00
if ( type ! = new_type ) {
switch ( new_type ) {
case PDO_PARAM_INT :
2014-04-22 18:23:03 +08:00
convert_to_long_ex ( dest ) ;
2005-10-31 11:23:38 +08:00
break ;
case PDO_PARAM_BOOL :
2014-04-22 18:23:03 +08:00
convert_to_boolean_ex ( dest ) ;
2005-10-31 11:23:38 +08:00
break ;
case PDO_PARAM_STR :
2014-04-22 18:23:03 +08:00
convert_to_string_ex ( dest ) ;
2005-10-31 11:23:38 +08:00
break ;
case PDO_PARAM_NULL :
2014-04-22 18:23:03 +08:00
convert_to_null_ex ( dest ) ;
2005-10-31 11:23:38 +08:00
break ;
default :
;
}
}
2005-02-07 06:11:12 +08:00
if ( caller_frees & & value ) {
efree ( value ) ;
}
2005-07-08 12:13:00 +08:00
if ( stmt - > dbh - > stringify ) {
switch ( Z_TYPE_P ( dest ) ) {
case IS_LONG :
case IS_DOUBLE :
convert_to_string ( dest ) ;
break ;
}
}
2005-07-12 10:40:59 +08:00
if ( Z_TYPE_P ( dest ) = = IS_NULL & & stmt - > dbh - > oracle_nulls = = PDO_NULL_TO_STRING ) {
ZVAL_EMPTY_STRING ( dest ) ;
}
2004-05-17 23:41:51 +08:00
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
static int do_fetch_common ( pdo_stmt_t * stmt , enum pdo_fetch_orientation ori , long offset , int do_bind TSRMLS_DC ) /* { { { */
2004-05-17 23:41:51 +08:00
{
2006-11-29 00:27:53 +08:00
if ( ! stmt - > executed ) {
return 0 ;
}
2004-05-17 23:41:51 +08:00
if ( ! dispatch_param_event ( stmt , PDO_PARAM_EVT_FETCH_PRE TSRMLS_CC ) ) {
return 0 ;
}
2005-01-12 12:49:12 +08:00
if ( ! stmt - > methods - > fetcher ( stmt , ori , offset TSRMLS_CC ) ) {
2004-05-17 23:41:51 +08:00
return 0 ;
}
/* some drivers might need to describe the columns now */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
if ( ! stmt - > columns & & ! pdo_stmt_describe_columns ( stmt TSRMLS_CC ) ) {
2004-05-17 23:41:51 +08:00
return 0 ;
}
if ( ! dispatch_param_event ( stmt , PDO_PARAM_EVT_FETCH_POST TSRMLS_CC ) ) {
return 0 ;
}
if ( do_bind & & stmt - > bound_columns ) {
/* update those bound column variables now */
struct pdo_bound_param_data * param ;
2014-04-22 18:23:03 +08:00
ZEND_HASH_FOREACH_PTR ( stmt - > bound_columns , param ) {
2004-05-17 23:41:51 +08:00
if ( param - > paramno > = 0 ) {
2014-04-25 11:00:35 +08:00
if ( ! Z_ISREF ( param - > parameter ) ) {
continue ;
}
// ???? convert_to_string(¶m->parameter);
2004-05-17 23:41:51 +08:00
/* delete old value */
2014-04-25 11:00:35 +08:00
zval_dtor ( Z_REFVAL ( param - > parameter ) ) ;
2004-05-17 23:41:51 +08:00
/* set new value */
2014-04-25 11:00:35 +08:00
fetch_value ( stmt , Z_REFVAL ( param - > parameter ) , param - > paramno , ( int * ) & param - > param_type TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
/* TODO: some smart thing that avoids duplicating the value in the
* general loop below . For now , if you ' re binding output columns ,
2004-05-20 08:05:22 +08:00
* it ' s better to use LAZY or BOUND fetches if you want to shave
2004-05-17 23:41:51 +08:00
* off those cycles */
}
2014-04-22 18:23:03 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2004-05-17 23:41:51 +08:00
}
2004-05-20 04:38:53 +08:00
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2004-05-20 04:38:53 +08:00
2005-02-23 03:27:34 +08:00
static int do_fetch_class_prepare ( pdo_stmt_t * stmt TSRMLS_DC ) /* { { { */
2005-02-20 22:31:44 +08:00
{
2014-04-22 18:23:03 +08:00
zend_class_entry * ce = stmt - > fetch . cls . ce ;
zend_fcall_info * fci = & stmt - > fetch . cls . fci ;
zend_fcall_info_cache * fcc = & stmt - > fetch . cls . fcc ;
2005-02-23 08:52:46 +08:00
fci - > size = sizeof ( zend_fcall_info ) ;
2005-02-20 22:31:44 +08:00
if ( ! ce ) {
stmt - > fetch . cls . ce = ZEND_STANDARD_CLASS_DEF_PTR ;
2006-03-29 04:19:44 +08:00
ce = ZEND_STANDARD_CLASS_DEF_PTR ;
2005-02-20 22:31:44 +08:00
}
if ( ce - > constructor ) {
fci - > function_table = & ce - > function_table ;
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & fci - > function_name ) ;
2005-02-20 22:31:44 +08:00
fci - > symbol_table = NULL ;
2014-04-22 18:23:03 +08:00
fci - > retval = & stmt - > fetch . cls . retval ;
2014-04-26 04:32:51 +08:00
fci - > param_count = 0 ;
2014-04-08 02:46:45 +08:00
fci - > params = NULL ;
2005-02-20 22:31:44 +08:00
fci - > no_separation = 1 ;
2014-04-26 04:32:51 +08:00
zend_fcall_info_args ( fci , & stmt - > fetch . cls . ctor_args TSRMLS_CC ) ;
2014-04-08 02:46:45 +08:00
2005-02-20 22:31:44 +08:00
fcc - > initialized = 1 ;
fcc - > function_handler = ce - > constructor ;
fcc - > calling_scope = EG ( scope ) ;
2008-07-25 16:23:07 +08:00
fcc - > called_scope = ce ;
2005-02-20 22:31:44 +08:00
return 1 ;
2014-05-03 16:06:27 +08:00
} else if ( ! Z_ISUNDEF ( stmt - > fetch . cls . ctor_args ) ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " user-supplied class does not have a constructor, use NULL for the ctor_params parameter, or simply omit it " TSRMLS_CC ) ;
2005-02-20 22:31:44 +08:00
return 0 ;
} else {
return 1 ; /* no ctor no args is also ok */
}
}
2005-02-23 03:27:34 +08:00
/* }}} */
2005-03-09 13:50:03 +08:00
static int make_callable_ex ( pdo_stmt_t * stmt , zval * callable , zend_fcall_info * fci , zend_fcall_info_cache * fcc , int num_args TSRMLS_DC ) /* { { { */
2005-02-23 03:27:34 +08:00
{
2009-12-14 11:44:33 +08:00
char * is_callable_error = NULL ;
2005-02-23 03:27:34 +08:00
2009-12-14 11:44:33 +08:00
if ( zend_fcall_info_init ( callable , 0 , fci , fcc , NULL , & is_callable_error TSRMLS_CC ) = = FAILURE ) {
if ( is_callable_error ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , is_callable_error TSRMLS_CC ) ;
efree ( is_callable_error ) ;
2005-02-23 03:27:34 +08:00
} else {
2009-12-14 11:44:33 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " user-supplied function must be a valid callback " TSRMLS_CC ) ;
2006-05-30 17:46:59 +08:00
}
2005-02-23 03:27:34 +08:00
return 0 ;
}
2009-12-15 05:44:56 +08:00
if ( is_callable_error ) {
/* Possible E_STRICT error message */
efree ( is_callable_error ) ;
}
2005-02-23 03:27:34 +08:00
fci - > param_count = num_args ; /* probably less */
2014-04-24 21:14:36 +08:00
fci - > params = safe_emalloc ( sizeof ( zval ) , num_args , 0 ) ;
2005-02-23 03:27:34 +08:00
return 1 ;
}
/* }}} */
2005-02-20 22:31:44 +08:00
2005-02-23 03:27:34 +08:00
static int do_fetch_func_prepare ( pdo_stmt_t * stmt TSRMLS_DC ) /* { { { */
{
2014-04-24 21:14:36 +08:00
zend_fcall_info * fci = & stmt - > fetch . cls . fci ;
zend_fcall_info_cache * fcc = & stmt - > fetch . cls . fcc ;
2005-02-23 03:27:34 +08:00
2014-04-22 18:23:03 +08:00
if ( ! make_callable_ex ( stmt , & stmt - > fetch . func . function , fci , fcc , stmt - > column_count TSRMLS_CC ) ) {
2005-02-23 03:27:34 +08:00
return 0 ;
} else {
2014-04-22 18:23:03 +08:00
stmt - > fetch . func . values = safe_emalloc ( sizeof ( zval ) , stmt - > column_count , 0 ) ;
2005-02-23 03:27:34 +08:00
return 1 ;
}
}
/* }}} */
static int do_fetch_opt_finish ( pdo_stmt_t * stmt , int free_ctor_agrs TSRMLS_DC ) /* { { { */
2005-02-20 22:31:44 +08:00
{
/* fci.size is used to check if it is valid */
if ( stmt - > fetch . cls . fci . size & & stmt - > fetch . cls . fci . params ) {
2014-05-06 08:06:58 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . cls . ctor_args ) ) {
/* Added to free constructor arguments ??? */
zend_fcall_info_args_clear ( & stmt - > fetch . cls . fci , 1 ) ;
} else {
efree ( stmt - > fetch . cls . fci . params ) ;
}
2005-02-23 03:27:34 +08:00
stmt - > fetch . cls . fci . params = NULL ;
2005-02-20 22:31:44 +08:00
}
2014-04-24 21:14:36 +08:00
2005-02-23 08:52:46 +08:00
stmt - > fetch . cls . fci . size = 0 ;
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . cls . ctor_args ) & & free_ctor_agrs ) {
2005-02-23 08:52:46 +08:00
zval_ptr_dtor ( & stmt - > fetch . cls . ctor_args ) ;
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & stmt - > fetch . cls . ctor_args ) ;
2005-02-23 08:52:46 +08:00
stmt - > fetch . cls . fci . param_count = 0 ;
2005-02-20 22:31:44 +08:00
}
2005-07-07 19:19:56 +08:00
if ( stmt - > fetch . func . values ) {
2007-10-08 12:06:15 +08:00
efree ( stmt - > fetch . func . values ) ;
2005-02-23 03:27:34 +08:00
stmt - > fetch . func . values = NULL ;
}
2005-02-20 22:31:44 +08:00
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2005-02-20 22:31:44 +08:00
2004-05-20 04:38:53 +08:00
/* perform a fetch. If do_bind is true, update any bound columns.
* If return_value is not null , store values into it according to HOW . */
2014-04-22 18:23:03 +08:00
static int do_fetch ( pdo_stmt_t * stmt , int do_bind , zval * return_value , enum pdo_fetch_type how , enum pdo_fetch_orientation ori , long offset , zval * return_all TSRMLS_DC ) /* { { { */
2004-05-20 04:38:53 +08:00
{
2008-10-11 00:47:15 +08:00
int flags , idx , old_arg_count = 0 ;
2006-06-20 21:26:01 +08:00
zend_class_entry * ce = NULL , * old_ce = NULL ;
2014-04-22 18:23:03 +08:00
zval grp_val , * pgrp , retval , old_ctor_args ;
2008-01-11 09:47:18 +08:00
int colno ;
2004-05-21 06:06:42 +08:00
2005-02-20 07:36:58 +08:00
if ( how = = PDO_FETCH_USE_DEFAULT ) {
how = stmt - > default_fetch_type ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2008-10-11 00:47:15 +08:00
flags = how & PDO_FETCH_FLAGS ;
2007-08-01 06:48:42 +08:00
how = how & ~ PDO_FETCH_FLAGS ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2005-01-12 12:49:12 +08:00
if ( ! do_fetch_common ( stmt , ori , offset , do_bind TSRMLS_CC ) ) {
2004-05-20 04:38:53 +08:00
return 0 ;
}
2004-07-13 04:12:39 +08:00
if ( how = = PDO_FETCH_BOUND ) {
RETVAL_TRUE ;
return 1 ;
}
2008-01-11 09:47:18 +08:00
if ( flags & PDO_FETCH_GROUP & & stmt - > fetch . column = = - 1 ) {
colno = 1 ;
} else {
colno = stmt - > fetch . column ;
}
2004-05-17 23:41:51 +08:00
if ( return_value ) {
2005-02-21 00:12:57 +08:00
int i = 0 ;
2004-05-20 04:38:53 +08:00
2004-05-21 21:26:58 +08:00
if ( how = = PDO_FETCH_LAZY ) {
get_lazy_object ( stmt , return_value TSRMLS_CC ) ;
return 1 ;
}
2005-06-09 03:51:56 +08:00
RETVAL_FALSE ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
switch ( how ) {
2006-05-12 06:43:44 +08:00
case PDO_FETCH_USE_DEFAULT :
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_ASSOC :
case PDO_FETCH_BOTH :
case PDO_FETCH_NUM :
2005-07-03 11:49:44 +08:00
case PDO_FETCH_NAMED :
2006-03-20 01:35:36 +08:00
if ( ! return_all ) {
2014-04-22 18:23:03 +08:00
ZVAL_NEW_ARR ( return_value ) ;
zend_hash_init ( Z_ARRVAL_P ( return_value ) , stmt - > column_count , NULL , ZVAL_PTR_DTOR , 0 ) ; ;
2006-03-20 01:35:36 +08:00
} else {
array_init ( return_value ) ;
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
2007-05-17 03:33:57 +08:00
case PDO_FETCH_KEY_PAIR :
if ( stmt - > column_count ! = 2 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain extactly 2 columns. " TSRMLS_CC ) ;
return 0 ;
}
2007-07-22 23:14:21 +08:00
if ( ! return_all ) {
array_init ( return_value ) ;
}
2007-05-17 03:33:57 +08:00
break ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_COLUMN :
2008-01-11 09:47:18 +08:00
if ( colno > = 0 & & colno < stmt - > column_count ) {
if ( flags = = PDO_FETCH_GROUP & & stmt - > fetch . column = = - 1 ) {
fetch_value ( stmt , return_value , 1 , NULL TSRMLS_CC ) ;
2008-01-15 02:41:31 +08:00
} else if ( flags = = PDO_FETCH_GROUP & & colno ) {
fetch_value ( stmt , return_value , 0 , NULL TSRMLS_CC ) ;
2008-01-11 09:47:18 +08:00
} else {
fetch_value ( stmt , return_value , colno , NULL TSRMLS_CC ) ;
}
2005-02-28 06:32:11 +08:00
if ( ! return_all ) {
return 1 ;
} else {
break ;
}
2008-02-20 11:11:43 +08:00
} else {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " Invalid column index " TSRMLS_CC ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
return 0 ;
case PDO_FETCH_OBJ :
object_init_ex ( return_value , ZEND_STANDARD_CLASS_DEF_PTR ) ;
break ;
case PDO_FETCH_CLASS :
2005-02-21 00:12:57 +08:00
if ( flags & PDO_FETCH_CLASSTYPE ) {
zval val ;
2014-04-22 18:23:03 +08:00
zend_class_entry * cep ;
2005-02-21 00:12:57 +08:00
old_ce = stmt - > fetch . cls . ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & old_ctor_args , & stmt - > fetch . cls . ctor_args ) ;
2005-02-23 08:52:46 +08:00
old_arg_count = stmt - > fetch . cls . fci . param_count ;
do_fetch_opt_finish ( stmt , 0 TSRMLS_CC ) ;
2005-02-21 00:12:57 +08:00
2005-09-12 04:32:28 +08:00
fetch_value ( stmt , & val , i + + , NULL TSRMLS_CC ) ;
2005-02-21 00:12:57 +08:00
if ( Z_TYPE ( val ) ! = IS_NULL ) {
convert_to_string ( & val ) ;
2014-04-22 18:23:03 +08:00
if ( ( cep = zend_lookup_class ( Z_STR ( val ) TSRMLS_CC ) ) = = NULL ) {
2005-02-21 00:12:57 +08:00
stmt - > fetch . cls . ce = ZEND_STANDARD_CLASS_DEF_PTR ;
} else {
2014-04-22 18:23:03 +08:00
stmt - > fetch . cls . ce = cep ;
2005-02-21 00:12:57 +08:00
}
}
do_fetch_class_prepare ( stmt TSRMLS_CC ) ;
zval_dtor ( & val ) ;
}
2005-02-20 05:35:31 +08:00
ce = stmt - > fetch . cls . ce ;
2006-07-30 19:19:56 +08:00
if ( ! ce ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " No fetch class specified " TSRMLS_CC ) ;
return 0 ;
}
2005-02-28 06:32:11 +08:00
if ( ( flags & PDO_FETCH_SERIALIZE ) = = 0 ) {
object_init_ex ( return_value , ce ) ;
if ( ! stmt - > fetch . cls . fci . size ) {
if ( ! do_fetch_class_prepare ( stmt TSRMLS_CC ) )
{
return 0 ;
}
2005-02-20 22:31:44 +08:00
}
2006-05-12 06:43:44 +08:00
if ( ce - > constructor & & ( flags & PDO_FETCH_PROPS_LATE ) ) {
2014-04-22 18:23:03 +08:00
stmt - > fetch . cls . fci . object = Z_OBJ_P ( return_value ) ;
stmt - > fetch . cls . fcc . object = Z_OBJ_P ( return_value ) ;
2006-05-12 06:43:44 +08:00
if ( zend_call_function ( & stmt - > fetch . cls . fci , & stmt - > fetch . cls . fcc TSRMLS_CC ) = = FAILURE ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " could not call class constructor " TSRMLS_CC ) ;
return 0 ;
} else {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . cls . retval ) ) {
2014-04-22 18:23:03 +08:00
zval_ptr_dtor ( & stmt - > fetch . cls . retval ) ;
ZVAL_UNDEF ( & stmt - > fetch . cls . retval ) ;
2006-05-12 06:43:44 +08:00
}
}
}
2005-02-14 01:04:04 +08:00
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
case PDO_FETCH_INTO :
2014-05-03 16:06:27 +08:00
if ( Z_ISUNDEF ( stmt - > fetch . into ) ) {
2005-10-10 22:44:16 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " No fetch-into object specified. " TSRMLS_CC ) ;
return 0 ;
break ;
}
2014-04-25 11:45:23 +08:00
ZVAL_COPY ( return_value , & stmt - > fetch . into ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-04-22 18:23:03 +08:00
if ( zend_get_class_entry ( Z_OBJ_P ( return_value ) TSRMLS_CC ) = = ZEND_STANDARD_CLASS_DEF_PTR ) {
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
how = PDO_FETCH_OBJ ;
}
break ;
2005-02-23 03:27:34 +08:00
case PDO_FETCH_FUNC :
2014-05-03 16:06:27 +08:00
if ( Z_ISUNDEF ( stmt - > fetch . func . function ) ) {
2006-07-30 19:19:56 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " No fetch function specified " TSRMLS_CC ) ;
return 0 ;
}
2005-02-23 03:27:34 +08:00
if ( ! stmt - > fetch . func . fci . size ) {
if ( ! do_fetch_func_prepare ( stmt TSRMLS_CC ) )
{
return 0 ;
}
}
break ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
default :
/* shouldn't happen */
return 0 ;
2004-05-17 23:41:51 +08:00
}
2005-02-20 07:11:23 +08:00
2007-07-22 23:14:21 +08:00
if ( return_all & & how ! = PDO_FETCH_KEY_PAIR ) {
2014-04-22 18:23:03 +08:00
//???
//ZVAL_NULL(&grp_val);
2008-01-11 09:47:18 +08:00
if ( flags = = PDO_FETCH_GROUP & & how = = PDO_FETCH_COLUMN & & stmt - > fetch . column > 0 ) {
fetch_value ( stmt , & grp_val , colno , NULL TSRMLS_CC ) ;
} else {
fetch_value ( stmt , & grp_val , i , NULL TSRMLS_CC ) ;
}
2005-02-23 03:27:34 +08:00
convert_to_string ( & grp_val ) ;
2005-02-28 06:32:11 +08:00
if ( how = = PDO_FETCH_COLUMN ) {
i = stmt - > column_count ; /* no more data to fetch */
} else {
i + + ;
}
2005-02-20 07:11:23 +08:00
}
2004-05-17 23:41:51 +08:00
2005-02-23 03:27:34 +08:00
for ( idx = 0 ; i < stmt - > column_count ; i + + , idx + + ) {
2014-04-22 18:23:03 +08:00
zval val ;
fetch_value ( stmt , & val , i , NULL TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
switch ( how ) {
case PDO_FETCH_ASSOC :
2014-04-22 18:23:03 +08:00
add_assoc_zval ( return_value , stmt - > columns [ i ] . name , & val ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
2007-05-17 03:33:57 +08:00
case PDO_FETCH_KEY_PAIR :
{
2014-04-22 18:23:03 +08:00
zval tmp ;
fetch_value ( stmt , & tmp , + + i , NULL TSRMLS_CC ) ;
2007-07-22 23:14:21 +08:00
2014-04-22 18:23:03 +08:00
if ( Z_TYPE ( val ) = = IS_LONG ) {
zend_hash_index_update ( ( return_all ? Z_ARRVAL_P ( return_all ) : Z_ARRVAL_P ( return_value ) ) , Z_LVAL ( val ) , & tmp ) ;
2007-05-17 03:33:57 +08:00
} else {
2014-04-22 18:23:03 +08:00
convert_to_string ( & val ) ;
zend_symtable_update ( ( return_all ? Z_ARRVAL_P ( return_all ) : Z_ARRVAL_P ( return_value ) ) , Z_STR ( val ) , & tmp ) ;
2007-05-17 03:33:57 +08:00
}
2007-07-22 23:14:21 +08:00
zval_ptr_dtor ( & val ) ;
return 1 ;
2007-05-17 03:33:57 +08:00
}
break ;
2004-05-17 23:41:51 +08:00
2006-05-12 06:43:44 +08:00
case PDO_FETCH_USE_DEFAULT :
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_BOTH :
2014-04-22 18:23:03 +08:00
add_assoc_zval ( return_value , stmt - > columns [ i ] . name , & val ) ;
if ( Z_REFCOUNTED ( val ) ) {
Z_ADDREF ( val ) ;
}
add_next_index_zval ( return_value , & val ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
2005-07-03 11:49:44 +08:00
case PDO_FETCH_NAMED :
/* already have an item with this name? */
{
2014-04-22 18:23:03 +08:00
zval * curr_val ;
if ( ( curr_val = zend_hash_str_find ( Z_ARRVAL_P ( return_value ) , stmt - > columns [ i ] . name ,
strlen ( stmt - > columns [ i ] . name ) ) ) ) {
zval arr ;
if ( Z_TYPE_P ( curr_val ) ! = IS_ARRAY ) {
2005-07-03 11:49:44 +08:00
/* a little bit of black magic here:
* we ' re creating a new array and swapping it for the
* zval that ' s already stored in the hash under the name
* we want . We then add that zval to the array .
* This is effectively the same thing as :
* if ( ! is_array ( $ hash [ $ name ] ) ) {
* $ hash [ $ name ] = array ( $ hash [ $ name ] ) ;
* }
* */
2014-04-22 18:23:03 +08:00
zval cur ;
2005-07-03 11:49:44 +08:00
2014-04-22 18:23:03 +08:00
array_init ( & arr ) ;
2005-07-03 11:49:44 +08:00
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & cur , curr_val ) ;
ZVAL_COPY_VALUE ( curr_val , & arr ) ;
2005-07-03 11:49:44 +08:00
2014-04-22 18:23:03 +08:00
add_next_index_zval ( & arr , & cur ) ;
2005-07-03 11:49:44 +08:00
} else {
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & arr , curr_val ) ;
2005-07-03 11:49:44 +08:00
}
2014-04-22 18:23:03 +08:00
add_next_index_zval ( & arr , & val ) ;
2005-07-03 11:49:44 +08:00
} else {
2014-04-22 18:23:03 +08:00
add_assoc_zval ( return_value , stmt - > columns [ i ] . name , & val ) ;
2005-07-03 11:49:44 +08:00
}
}
break ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_NUM :
2014-04-22 18:23:03 +08:00
add_next_index_zval ( return_value , & val ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
2004-05-21 06:06:42 +08:00
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_OBJ :
case PDO_FETCH_INTO :
2005-02-20 21:42:03 +08:00
zend_update_property ( NULL , return_value ,
stmt - > columns [ i ] . name , stmt - > columns [ i ] . namelen ,
2014-04-22 18:23:03 +08:00
& val TSRMLS_CC ) ;
2005-07-03 01:19:58 +08:00
zval_ptr_dtor ( & val ) ;
2005-02-20 21:42:03 +08:00
break ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_CLASS :
2005-02-28 06:32:11 +08:00
if ( ( flags & PDO_FETCH_SERIALIZE ) = = 0 | | idx ) {
zend_update_property ( ce , return_value ,
stmt - > columns [ i ] . name , stmt - > columns [ i ] . namelen ,
2014-04-22 18:23:03 +08:00
& val TSRMLS_CC ) ;
2005-07-07 19:19:56 +08:00
zval_ptr_dtor ( & val ) ;
2005-02-28 06:32:11 +08:00
} else {
# ifdef MBO_0
php_unserialize_data_t var_hash ;
PHP_VAR_UNSERIALIZE_INIT ( var_hash ) ;
2014-04-22 18:23:03 +08:00
if ( php_var_unserialize ( return_value , ( const unsigned char * * ) & Z_STRVAL ( val ) , Z_STRVAL ( val ) + Z_STRLEN ( val ) , NULL TSRMLS_CC ) = = FAILURE ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " cannot unserialize data " TSRMLS_CC ) ;
2005-02-28 06:32:11 +08:00
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
return 0 ;
}
PHP_VAR_UNSERIALIZE_DESTROY ( var_hash ) ;
2005-02-28 06:58:08 +08:00
# endif
2005-02-28 06:32:11 +08:00
if ( ! ce - > unserialize ) {
2005-07-07 19:19:56 +08:00
zval_ptr_dtor ( & val ) ;
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " cannot unserialize class " TSRMLS_CC ) ;
2005-02-28 06:32:11 +08:00
return 0 ;
2014-04-22 18:23:03 +08:00
} else if ( ce - > unserialize ( return_value , ce , ( unsigned char * ) ( Z_TYPE ( val ) = = IS_STRING ? Z_STRVAL ( val ) : " " ) , Z_TYPE ( val ) = = IS_STRING ? Z_STRLEN ( val ) : 0 , NULL TSRMLS_CC ) = = FAILURE ) {
2005-07-07 19:19:56 +08:00
zval_ptr_dtor ( & val ) ;
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " cannot unserialize class " TSRMLS_CC ) ;
2005-02-28 06:32:11 +08:00
zval_dtor ( return_value ) ;
ZVAL_NULL ( return_value ) ;
2005-03-09 13:50:03 +08:00
return 0 ;
2005-07-07 19:19:56 +08:00
} else {
zval_ptr_dtor ( & val ) ;
2005-02-28 06:32:11 +08:00
}
}
2005-02-20 23:28:09 +08:00
break ;
2005-02-23 03:27:34 +08:00
case PDO_FETCH_FUNC :
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & stmt - > fetch . func . values [ idx ] , & val ) ;
ZVAL_COPY_VALUE ( & stmt - > fetch . cls . fci . params [ idx ] , & stmt - > fetch . func . values [ idx ] ) ;
2005-02-23 03:27:34 +08:00
break ;
2005-02-20 23:28:09 +08:00
default :
2005-02-23 03:27:34 +08:00
zval_ptr_dtor ( & val ) ;
2005-02-20 23:28:09 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " 22003 " , " mode is out of range " TSRMLS_CC ) ;
2005-02-23 08:52:46 +08:00
return 0 ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
}
2004-05-21 06:06:42 +08:00
}
2005-02-20 23:28:09 +08:00
switch ( how ) {
2010-02-12 06:14:06 +08:00
case PDO_FETCH_CLASS :
if ( ce - > constructor & & ! ( flags & ( PDO_FETCH_PROPS_LATE | PDO_FETCH_SERIALIZE ) ) ) {
2014-04-22 18:23:03 +08:00
stmt - > fetch . cls . fci . object = Z_OBJ_P ( return_value ) ;
stmt - > fetch . cls . fcc . object = Z_OBJ_P ( return_value ) ;
2010-02-12 06:14:06 +08:00
if ( zend_call_function ( & stmt - > fetch . cls . fci , & stmt - > fetch . cls . fcc TSRMLS_CC ) = = FAILURE ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " could not call class constructor " TSRMLS_CC ) ;
return 0 ;
} else {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . cls . retval ) ) {
2014-04-22 18:23:03 +08:00
zval_ptr_dtor ( & stmt - > fetch . cls . retval ) ;
2010-02-12 06:14:06 +08:00
}
}
}
if ( flags & PDO_FETCH_CLASSTYPE ) {
do_fetch_opt_finish ( stmt , 0 TSRMLS_CC ) ;
stmt - > fetch . cls . ce = old_ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & stmt - > fetch . cls . ctor_args , & old_ctor_args ) ;
2010-02-12 06:14:06 +08:00
stmt - > fetch . cls . fci . param_count = old_arg_count ;
}
break ;
2005-02-23 03:27:34 +08:00
case PDO_FETCH_FUNC :
stmt - > fetch . func . fci . param_count = idx ;
2014-04-22 18:23:03 +08:00
stmt - > fetch . func . fci . retval = & retval ;
2005-02-23 03:27:34 +08:00
if ( zend_call_function ( & stmt - > fetch . func . fci , & stmt - > fetch . func . fcc TSRMLS_CC ) = = FAILURE ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " could not call user-supplied function " TSRMLS_CC ) ;
2005-02-23 08:52:46 +08:00
return 0 ;
2005-02-23 03:27:34 +08:00
} else {
if ( return_all ) {
2014-04-22 18:23:03 +08:00
zval_ptr_dtor ( return_value ) ; /* we don't need that */
ZVAL_COPY_VALUE ( return_value , & retval ) ;
2014-05-03 16:06:27 +08:00
} else if ( ! Z_ISUNDEF ( retval ) ) {
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( return_value , & retval ) ;
2005-02-23 03:27:34 +08:00
}
}
2014-04-22 18:23:03 +08:00
while ( idx - - ) {
2005-02-23 03:27:34 +08:00
zval_ptr_dtor ( & stmt - > fetch . func . values [ idx ] ) ;
}
break ;
2005-02-20 23:28:09 +08:00
default :
break ;
}
2005-02-23 03:27:34 +08:00
if ( return_all ) {
if ( ( flags & PDO_FETCH_UNIQUE ) = = PDO_FETCH_UNIQUE ) {
add_assoc_zval ( return_all , Z_STRVAL ( grp_val ) , return_value ) ;
} else {
2014-04-22 18:23:03 +08:00
zval grp ;
if ( ( pgrp = zend_symtable_find ( Z_ARRVAL_P ( return_all ) , Z_STR ( grp_val ) ) ) = = NULL ) {
array_init ( & grp ) ;
add_assoc_zval ( return_all , Z_STRVAL ( grp_val ) , & grp ) ;
2005-02-23 03:27:34 +08:00
} else {
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & grp , pgrp ) ;
2005-02-23 03:27:34 +08:00
}
2014-04-22 18:23:03 +08:00
add_next_index_zval ( & grp , return_value ) ;
2005-02-23 03:27:34 +08:00
}
zval_dtor ( & grp_val ) ;
}
2004-05-17 23:41:51 +08:00
}
return 1 ;
}
2005-02-23 03:27:34 +08:00
/* }}} */
2007-10-12 04:54:41 +08:00
static int pdo_stmt_verify_mode ( pdo_stmt_t * stmt , long mode , int fetch_all TSRMLS_DC ) /* { { { */
2005-02-23 03:27:34 +08:00
{
int flags = mode & PDO_FETCH_FLAGS ;
2005-12-02 03:59:58 +08:00
2005-12-02 04:39:12 +08:00
mode = mode & ~ PDO_FETCH_FLAGS ;
2005-12-02 03:59:58 +08:00
if ( mode < 0 | | mode > PDO_FETCH__MAX ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " invalid fetch mode " TSRMLS_CC ) ;
return 0 ;
}
2005-02-23 03:27:34 +08:00
if ( mode = = PDO_FETCH_USE_DEFAULT ) {
2005-02-28 06:48:14 +08:00
flags = stmt - > default_fetch_type & PDO_FETCH_FLAGS ;
mode = stmt - > default_fetch_type & ~ PDO_FETCH_FLAGS ;
2005-02-23 03:27:34 +08:00
}
switch ( mode ) {
2014-04-22 18:23:03 +08:00
case PDO_FETCH_FUNC :
if ( ! fetch_all ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " PDO::FETCH_FUNC is only allowed in PDOStatement::fetchAll() " TSRMLS_CC ) ;
return 0 ;
}
return 1 ;
2005-11-28 05:01:58 +08:00
2014-04-22 18:23:03 +08:00
case PDO_FETCH_LAZY :
if ( fetch_all ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " PDO::FETCH_LAZY can't be used with PDOStatement::fetchAll() " TSRMLS_CC ) ;
return 0 ;
}
/* fall through */
default :
if ( ( flags & PDO_FETCH_SERIALIZE ) = = PDO_FETCH_SERIALIZE ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " PDO::FETCH_SERIALIZE can only be used together with PDO::FETCH_CLASS " TSRMLS_CC ) ;
return 0 ;
}
if ( ( flags & PDO_FETCH_CLASSTYPE ) = = PDO_FETCH_CLASSTYPE ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " PDO::FETCH_CLASSTYPE can only be used together with PDO::FETCH_CLASS " TSRMLS_CC ) ;
return 0 ;
}
if ( mode > = PDO_FETCH__MAX ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " invalid fetch mode " TSRMLS_CC ) ;
return 0 ;
}
/* no break; */
2005-02-28 06:32:11 +08:00
2014-04-22 18:23:03 +08:00
case PDO_FETCH_CLASS :
return 1 ;
2005-02-23 03:27:34 +08:00
}
}
/* }}} */
2004-05-17 23:41:51 +08:00
2005-01-12 12:49:12 +08:00
/* {{{ proto mixed PDOStatement::fetch([int $how = PDO_FETCH_BOTH [, int $orientation [, int $offset]]])
2004-05-17 23:41:51 +08:00
Fetches the next row and returns it , or false if there are no more rows */
static PHP_METHOD ( PDOStatement , fetch )
{
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
long how = PDO_FETCH_USE_DEFAULT ;
2005-01-12 12:49:12 +08:00
long ori = PDO_FETCH_ORI_NEXT ;
long off = 0 ;
2014-04-22 18:23:03 +08:00
PHP_STMT_GET_OBJ ;
2004-05-17 23:41:51 +08:00
2005-01-12 12:49:12 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |lll " , & how ,
& ori , & off ) ) {
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
2004-05-20 08:05:22 +08:00
PDO_STMT_CLEAR_ERR ( ) ;
2005-02-23 03:27:34 +08:00
if ( ! pdo_stmt_verify_mode ( stmt , how , 0 TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2005-02-20 07:11:23 +08:00
if ( ! do_fetch ( stmt , TRUE , return_value , how , ori , off , 0 TSRMLS_CC ) ) {
2004-05-20 08:05:22 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
2004-05-17 23:41:51 +08:00
RETURN_FALSE ;
}
}
/* }}} */
2008-09-24 07:07:52 +08:00
/* {{{ proto mixed PDOStatement::fetchObject([string class_name [, NULL|array ctor_args]])
2005-02-14 01:04:04 +08:00
Fetches the next row and returns it as an object . */
static PHP_METHOD ( PDOStatement , fetchObject )
{
long how = PDO_FETCH_CLASS ;
long ori = PDO_FETCH_ORI_NEXT ;
long off = 0 ;
2014-04-22 18:23:03 +08:00
zend_string * class_name = NULL ;
2005-02-14 01:04:04 +08:00
zend_class_entry * old_ce ;
2014-04-22 18:23:03 +08:00
zval old_ctor_args , * ctor_args = NULL ;
2005-02-23 08:52:46 +08:00
int error = 0 , old_arg_count ;
2005-02-14 01:04:04 +08:00
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2014-04-22 18:23:03 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |S!a " , & class_name , & ctor_args ) ) {
2005-02-14 01:04:04 +08:00
RETURN_FALSE ;
}
2005-02-23 03:27:34 +08:00
PDO_STMT_CLEAR_ERR ( ) ;
if ( ! pdo_stmt_verify_mode ( stmt , how , 0 TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2005-02-23 08:52:46 +08:00
old_ce = stmt - > fetch . cls . ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & old_ctor_args , & stmt - > fetch . cls . ctor_args ) ;
2005-02-23 08:52:46 +08:00
old_arg_count = stmt - > fetch . cls . fci . param_count ;
do_fetch_opt_finish ( stmt , 0 TSRMLS_CC ) ;
2011-09-14 00:36:29 +08:00
if ( ctor_args ) {
2005-02-14 01:04:04 +08:00
if ( Z_TYPE_P ( ctor_args ) = = IS_ARRAY & & zend_hash_num_elements ( Z_ARRVAL_P ( ctor_args ) ) ) {
2014-04-22 18:23:03 +08:00
ZVAL_DUP ( & stmt - > fetch . cls . ctor_args , ctor_args ) ;
2005-02-14 01:04:04 +08:00
} else {
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & stmt - > fetch . cls . ctor_args ) ;
2005-02-14 01:04:04 +08:00
}
2011-09-14 00:36:29 +08:00
}
if ( class_name & & ! error ) {
2014-04-22 18:23:03 +08:00
stmt - > fetch . cls . ce = zend_fetch_class ( class_name , ZEND_FETCH_CLASS_AUTO TSRMLS_CC ) ;
2005-02-14 01:04:04 +08:00
if ( ! stmt - > fetch . cls . ce ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " Could not find user-supplied class " TSRMLS_CC ) ;
2005-02-14 01:04:04 +08:00
error = 1 ;
}
2011-09-14 00:36:29 +08:00
} else if ( ! error ) {
stmt - > fetch . cls . ce = zend_standard_class_def ;
2005-02-14 01:04:04 +08:00
}
2005-02-20 07:11:23 +08:00
if ( ! error & & ! do_fetch ( stmt , TRUE , return_value , how , ori , off , 0 TSRMLS_CC ) ) {
2005-02-14 01:04:04 +08:00
error = 1 ;
2005-03-09 13:50:03 +08:00
}
if ( error ) {
2005-02-14 01:04:04 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
}
2005-02-23 08:52:46 +08:00
do_fetch_opt_finish ( stmt , 1 TSRMLS_CC ) ;
2005-02-14 01:04:04 +08:00
stmt - > fetch . cls . ce = old_ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & stmt - > fetch . cls . ctor_args , & old_ctor_args ) ;
2005-02-23 08:52:46 +08:00
stmt - > fetch . cls . fci . param_count = old_arg_count ;
2005-02-14 01:04:04 +08:00
if ( error ) {
RETURN_FALSE ;
}
}
/* }}} */
2005-05-17 09:41:51 +08:00
/* {{{ proto string PDOStatement::fetchColumn([int column_number])
Returns a data of the specified column in the result set . */
static PHP_METHOD ( PDOStatement , fetchColumn )
2004-05-20 04:38:53 +08:00
{
2005-05-17 09:41:51 +08:00
long col_n = 0 ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-20 04:38:53 +08:00
2005-05-17 09:41:51 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |l " , & col_n ) ) {
2004-05-20 04:38:53 +08:00
RETURN_FALSE ;
}
2004-05-20 08:05:22 +08:00
PDO_STMT_CLEAR_ERR ( ) ;
2005-02-23 03:27:34 +08:00
2005-01-12 12:49:12 +08:00
if ( ! do_fetch_common ( stmt , PDO_FETCH_ORI_NEXT , 0 , TRUE TSRMLS_CC ) ) {
2004-05-20 08:05:22 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
2004-05-20 04:38:53 +08:00
RETURN_FALSE ;
}
2005-09-12 04:32:28 +08:00
fetch_value ( stmt , return_value , col_n , NULL TSRMLS_CC ) ;
2004-05-20 04:38:53 +08:00
}
/* }}} */
2005-02-20 05:49:42 +08:00
/* {{{ proto array PDOStatement::fetchAll([int $how = PDO_FETCH_BOTH [, string class_name [, NULL|array ctor_args]]])
2004-05-20 04:38:53 +08:00
Returns an array of all of the results . */
static PHP_METHOD ( PDOStatement , fetchAll )
{
2005-02-20 07:36:58 +08:00
long how = PDO_FETCH_USE_DEFAULT ;
2014-04-22 18:23:03 +08:00
zval data , * return_all ;
2005-02-23 03:27:34 +08:00
zval * arg2 ;
2005-02-20 05:49:42 +08:00
zend_class_entry * old_ce ;
2014-04-22 18:23:03 +08:00
zval old_ctor_args , * ctor_args = NULL ;
2008-10-11 00:47:15 +08:00
int error = 0 , flags , old_arg_count ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2005-02-20 05:49:42 +08:00
2005-02-23 03:27:34 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |lzz " , & how , & arg2 , & ctor_args ) ) {
2004-05-20 04:38:53 +08:00
RETURN_FALSE ;
}
2005-02-23 03:27:34 +08:00
if ( ! pdo_stmt_verify_mode ( stmt , how , 1 TSRMLS_CC ) ) {
RETURN_FALSE ;
}
2005-02-23 08:52:46 +08:00
old_ce = stmt - > fetch . cls . ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & old_ctor_args , & stmt - > fetch . cls . ctor_args ) ;
2005-02-23 08:52:46 +08:00
old_arg_count = stmt - > fetch . cls . fci . param_count ;
do_fetch_opt_finish ( stmt , 0 TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
switch ( how & ~ PDO_FETCH_FLAGS ) {
case PDO_FETCH_CLASS :
switch ( ZEND_NUM_ARGS ( ) ) {
case 0 :
case 1 :
stmt - > fetch . cls . ce = zend_standard_class_def ;
2005-02-20 05:49:42 +08:00
break ;
2005-02-23 03:27:34 +08:00
case 3 :
if ( Z_TYPE_P ( ctor_args ) ! = IS_NULL & & Z_TYPE_P ( ctor_args ) ! = IS_ARRAY ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " ctor_args must be either NULL or an array " TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
error = 1 ;
break ;
}
2005-02-23 08:52:46 +08:00
if ( Z_TYPE_P ( ctor_args ) ! = IS_ARRAY | | ! zend_hash_num_elements ( Z_ARRVAL_P ( ctor_args ) ) ) {
ctor_args = NULL ;
2005-02-23 03:27:34 +08:00
}
/* no break */
case 2 :
2014-04-24 21:14:36 +08:00
if ( ctor_args ) {
ZVAL_COPY_VALUE ( & stmt - > fetch . cls . ctor_args , ctor_args ) ; /* we're not going to free these */
} else {
ZVAL_UNDEF ( & stmt - > fetch . cls . ctor_args ) ;
}
2005-02-23 03:27:34 +08:00
if ( Z_TYPE_P ( arg2 ) ! = IS_STRING ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " Invalid class name (should be a string) " TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
error = 1 ;
break ;
} else {
2014-04-22 18:23:03 +08:00
stmt - > fetch . cls . ce = zend_fetch_class ( Z_STR_P ( arg2 ) , ZEND_FETCH_CLASS_AUTO TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
if ( ! stmt - > fetch . cls . ce ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " could not find user-specified class " TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
error = 1 ;
break ;
}
}
2005-02-20 05:49:42 +08:00
}
2005-03-09 13:50:03 +08:00
if ( ! error ) {
do_fetch_class_prepare ( stmt TSRMLS_CC ) ;
}
2005-02-23 03:27:34 +08:00
break ;
case PDO_FETCH_FUNC :
2014-04-22 18:23:03 +08:00
switch ( ZEND_NUM_ARGS ( ) ) {
case 0 :
case 1 :
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " no fetch function specified " TSRMLS_CC ) ;
2009-12-14 11:44:33 +08:00
error = 1 ;
2014-04-22 18:23:03 +08:00
break ;
case 3 :
case 2 :
ZVAL_COPY_VALUE ( & stmt - > fetch . func . function , arg2 ) ;
if ( do_fetch_func_prepare ( stmt TSRMLS_CC ) = = 0 ) {
error = 1 ;
}
break ;
2005-02-20 05:49:42 +08:00
}
2005-02-23 03:27:34 +08:00
break ;
2005-02-28 06:32:11 +08:00
case PDO_FETCH_COLUMN :
switch ( ZEND_NUM_ARGS ( ) ) {
case 0 :
case 1 :
2008-01-11 09:47:18 +08:00
stmt - > fetch . column = how & PDO_FETCH_GROUP ? - 1 : 0 ;
2005-02-28 06:32:11 +08:00
break ;
case 2 :
convert_to_long ( arg2 ) ;
stmt - > fetch . column = Z_LVAL_P ( arg2 ) ;
break ;
case 3 :
2005-11-25 00:21:43 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " Third parameter not allowed for PDO::FETCH_COLUMN " TSRMLS_CC ) ;
2005-02-28 06:32:11 +08:00
error = 1 ;
}
break ;
2005-02-20 05:49:42 +08:00
2005-02-23 03:27:34 +08:00
default :
if ( ZEND_NUM_ARGS ( ) > 1 ) {
2005-03-09 13:50:03 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " Extraneous additional parameters " TSRMLS_CC ) ;
2005-02-20 05:49:42 +08:00
error = 1 ;
}
2004-05-20 04:38:53 +08:00
}
2008-10-11 00:47:15 +08:00
flags = how & PDO_FETCH_FLAGS ;
2007-10-31 20:57:51 +08:00
if ( ( how & ~ PDO_FETCH_FLAGS ) = = PDO_FETCH_USE_DEFAULT ) {
2008-10-11 00:47:15 +08:00
flags | = stmt - > default_fetch_type & PDO_FETCH_FLAGS ;
2007-10-31 20:57:51 +08:00
how | = stmt - > default_fetch_type & ~ PDO_FETCH_FLAGS ;
}
2005-02-23 08:52:46 +08:00
if ( ! error ) {
2005-02-20 05:49:42 +08:00
PDO_STMT_CLEAR_ERR ( ) ;
2014-04-22 18:23:03 +08:00
if ( ( how & PDO_FETCH_GROUP ) | | how = = PDO_FETCH_KEY_PAIR | |
2007-10-12 04:54:41 +08:00
( how = = PDO_FETCH_USE_DEFAULT & & stmt - > default_fetch_type = = PDO_FETCH_KEY_PAIR )
) {
2005-02-20 07:11:23 +08:00
array_init ( return_value ) ;
return_all = return_value ;
} else {
return_all = 0 ;
}
2014-04-22 18:23:03 +08:00
if ( ! do_fetch ( stmt , 1 , & data , how | flags , PDO_FETCH_ORI_NEXT , 0 , return_all TSRMLS_CC ) ) {
2005-07-07 23:14:10 +08:00
error = 2 ;
2005-02-20 05:49:42 +08:00
}
}
if ( ! error ) {
2007-07-22 23:50:17 +08:00
if ( ( how & PDO_FETCH_GROUP ) ) {
2005-02-20 07:11:23 +08:00
do {
2014-04-22 18:23:03 +08:00
//??? MAKE_STD_ZVAL(data);
} while ( do_fetch ( stmt , 1 , & data , how | flags , PDO_FETCH_ORI_NEXT , 0 , return_all TSRMLS_CC ) ) ;
2007-10-12 04:54:41 +08:00
} else if ( how = = PDO_FETCH_KEY_PAIR | | ( how = = PDO_FETCH_USE_DEFAULT & & stmt - > default_fetch_type = = PDO_FETCH_KEY_PAIR ) ) {
2014-04-22 18:23:03 +08:00
while ( do_fetch ( stmt , 1 , & data , how | flags , PDO_FETCH_ORI_NEXT , 0 , return_all TSRMLS_CC ) ) ;
2005-02-20 07:11:23 +08:00
} else {
array_init ( return_value ) ;
2014-05-08 18:34:40 +08:00
do {
2014-04-22 18:23:03 +08:00
add_next_index_zval ( return_value , & data ) ;
2014-05-08 18:34:40 +08:00
} while ( do_fetch ( stmt , 1 , & data , how | flags , PDO_FETCH_ORI_NEXT , 0 , 0 TSRMLS_CC ) ) ;
2005-02-20 07:11:23 +08:00
}
2005-02-20 05:49:42 +08:00
}
2005-02-20 07:11:23 +08:00
2005-02-23 08:52:46 +08:00
do_fetch_opt_finish ( stmt , 0 TSRMLS_CC ) ;
2005-02-23 03:27:34 +08:00
2005-02-20 05:49:42 +08:00
stmt - > fetch . cls . ce = old_ce ;
2014-04-22 18:23:03 +08:00
ZVAL_COPY_VALUE ( & stmt - > fetch . cls . ctor_args , & old_ctor_args ) ;
2005-02-23 08:52:46 +08:00
stmt - > fetch . cls . fci . param_count = old_arg_count ;
2005-02-20 05:49:42 +08:00
if ( error ) {
2005-03-09 13:50:03 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
2005-07-07 23:14:10 +08:00
if ( error ! = 2 ) {
RETURN_FALSE ;
} else { /* on no results, return an empty array */
2005-10-31 15:47:40 +08:00
if ( Z_TYPE_P ( return_value ) ! = IS_ARRAY ) {
array_init ( return_value ) ;
}
2005-07-07 23:14:10 +08:00
return ;
}
2005-02-20 05:49:42 +08:00
}
2004-05-20 04:38:53 +08:00
}
/* }}} */
2004-09-27 04:45:44 +08:00
static int register_bound_param ( INTERNAL_FUNCTION_PARAMETERS , pdo_stmt_t * stmt , int is_param ) /* { { { */
2004-05-17 23:41:51 +08:00
{
2004-06-15 18:06:41 +08:00
struct pdo_bound_param_data param = { 0 } ;
2009-12-12 06:30:46 +08:00
long param_type = PDO_PARAM_STR ;
2014-04-24 21:14:36 +08:00
zval * parameter ;
2004-05-17 23:41:51 +08:00
2004-06-15 18:06:41 +08:00
param . paramno = - 1 ;
2004-05-17 23:41:51 +08:00
2004-06-15 18:22:21 +08:00
if ( FAILURE = = zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC ,
2014-04-24 21:14:36 +08:00
" lz|llz! " , & param . paramno , & parameter , & param_type , & param . max_value_len ,
2004-06-15 18:22:21 +08:00
& param . driver_params ) ) {
2014-04-23 10:58:08 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " Sz|llz! " , & param . name ,
2014-04-24 21:14:36 +08:00
& parameter , & param_type , & param . max_value_len ,
2004-05-21 22:09:51 +08:00
& param . driver_params ) ) {
return 0 ;
}
2004-05-17 23:41:51 +08:00
}
2009-12-12 06:30:46 +08:00
param . param_type = ( int ) param_type ;
2004-05-17 23:41:51 +08:00
if ( param . paramno > 0 ) {
- - param . paramno ; /* make it zero-based internally */
} else if ( ! param . name ) {
2005-02-07 05:05:59 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY093 " , " Columns/Parameters are 1-based " TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
return 0 ;
}
2014-04-24 21:14:36 +08:00
ZVAL_COPY ( & param . parameter , parameter ) ;
2006-08-01 23:06:01 +08:00
if ( ! really_register_bound_param ( & param , stmt , is_param TSRMLS_CC ) ) {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( param . parameter ) ) {
2007-03-07 17:03:07 +08:00
zval_ptr_dtor ( & ( param . parameter ) ) ;
}
2006-08-01 23:06:01 +08:00
return 0 ;
}
return 1 ;
2004-09-27 04:45:44 +08:00
} /* }}} */
2004-05-17 23:41:51 +08:00
2005-09-10 23:32:04 +08:00
/* {{{ proto bool PDOStatement::bindValue(mixed $paramno, mixed $param [, int $type ])
bind an input parameter to the value of a PHP variable . $ paramno is the 1 - based position of the placeholder in the SQL statement ( but can be the parameter name for drivers that support named placeholders ) . It should be called prior to execute ( ) . */
static PHP_METHOD ( PDOStatement , bindValue )
{
struct pdo_bound_param_data param = { 0 } ;
2010-08-26 06:03:03 +08:00
long param_type = PDO_PARAM_STR ;
2014-04-24 21:14:36 +08:00
zval * parameter ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2005-09-10 23:32:04 +08:00
param . paramno = - 1 ;
2006-05-12 06:43:44 +08:00
2005-09-10 23:32:04 +08:00
if ( FAILURE = = zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC ,
2014-04-24 21:14:36 +08:00
" lz/|l " , & param . paramno , & parameter , & param_type ) ) {
2014-04-23 10:58:08 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " Sz/|l " , & param . name ,
2014-04-24 21:14:36 +08:00
& parameter , & param_type ) ) {
2005-09-10 23:32:04 +08:00
RETURN_FALSE ;
2006-01-23 07:57:41 +08:00
}
2005-09-10 23:32:04 +08:00
}
2010-08-26 06:03:03 +08:00
param . param_type = ( int ) param_type ;
2006-01-23 07:57:41 +08:00
2005-09-10 23:32:04 +08:00
if ( param . paramno > 0 ) {
- - param . paramno ; /* make it zero-based internally */
} else if ( ! param . name ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY093 " , " Columns/Parameters are 1-based " TSRMLS_CC ) ;
RETURN_FALSE ;
}
2006-01-23 07:57:41 +08:00
2014-04-24 21:14:36 +08:00
ZVAL_COPY ( & param . parameter , parameter ) ;
2006-08-01 23:06:01 +08:00
if ( ! really_register_bound_param ( & param , stmt , TRUE TSRMLS_CC ) ) {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( param . parameter ) ) {
2007-03-07 17:03:07 +08:00
zval_ptr_dtor ( & ( param . parameter ) ) ;
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & param . parameter ) ;
2007-03-07 17:03:07 +08:00
}
2006-08-01 23:06:01 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
2005-09-10 23:32:04 +08:00
}
/* }}} */
2004-05-17 23:41:51 +08:00
/* {{{ proto bool PDOStatement::bindParam(mixed $paramno, mixed &$param [, int $type [, int $maxlen [, mixed $driverdata]]])
bind a parameter to a PHP variable . $ paramno is the 1 - based position of the placeholder in the SQL statement ( but can be the parameter name for drivers that support named placeholders ) . This isn ' t supported by all drivers . It should be called prior to execute ( ) . */
static PHP_METHOD ( PDOStatement , bindParam )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-17 23:41:51 +08:00
RETURN_BOOL ( register_bound_param ( INTERNAL_FUNCTION_PARAM_PASSTHRU , stmt , TRUE ) ) ;
}
/* }}} */
/* {{{ proto bool PDOStatement::bindColumn(mixed $column, mixed &$param [, int $type [, int $maxlen [, mixed $driverdata]]])
bind a column to a PHP variable . On each row fetch $ param will contain the value of the corresponding column . $ column is the 1 - based offset of the column , or the column name . For portability , don ' t call this before execute ( ) . */
static PHP_METHOD ( PDOStatement , bindColumn )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2014-04-25 11:00:35 +08:00
RETURN_BOOL ( register_bound_param ( INTERNAL_FUNCTION_PARAM_PASSTHRU , stmt , 0 ) ) ;
2004-05-17 23:41:51 +08:00
}
/* }}} */
/* {{{ proto int PDOStatement::rowCount()
Returns the number of rows in a result set , or the number of rows affected by the last execute ( ) . It is not always meaningful . */
static PHP_METHOD ( PDOStatement , rowCount )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-17 23:41:51 +08:00
2005-01-18 08:58:15 +08:00
RETURN_LONG ( stmt - > row_count ) ;
2004-05-17 23:41:51 +08:00
}
/* }}} */
2005-02-06 05:29:42 +08:00
/* {{{ proto string PDOStatement::errorCode()
2004-05-21 01:22:13 +08:00
Fetch the error code associated with the last operation on the statement handle */
static PHP_METHOD ( PDOStatement , errorCode )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-21 01:22:13 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2004-05-21 01:22:13 +08:00
}
2008-11-11 02:47:28 +08:00
if ( stmt - > error_code [ 0 ] = = ' \0 ' ) {
RETURN_NULL ( ) ;
}
2014-04-22 18:23:03 +08:00
RETURN_STRING ( stmt - > error_code ) ;
2004-05-21 01:22:13 +08:00
}
/* }}} */
2004-07-10 01:49:08 +08:00
/* {{{ proto array PDOStatement::errorInfo()
2004-05-21 01:22:13 +08:00
Fetch extended error information associated with the last operation on the statement handle */
static PHP_METHOD ( PDOStatement , errorInfo )
{
2008-11-11 02:47:28 +08:00
int error_count ;
int error_count_diff = 0 ;
int error_expected_count = 3 ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-21 01:22:13 +08:00
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2004-05-21 01:22:13 +08:00
}
array_init ( return_value ) ;
2014-04-15 19:40:40 +08:00
add_next_index_string ( return_value , stmt - > error_code ) ;
2004-05-21 01:22:13 +08:00
if ( stmt - > dbh - > methods - > fetch_err ) {
stmt - > dbh - > methods - > fetch_err ( stmt - > dbh , stmt , return_value TSRMLS_CC ) ;
}
2008-11-11 02:47:28 +08:00
error_count = zend_hash_num_elements ( Z_ARRVAL_P ( return_value ) ) ;
if ( error_expected_count > error_count ) {
int current_index ;
2008-11-13 22:40:06 +08:00
error_count_diff = error_expected_count - error_count ;
2008-11-11 02:47:28 +08:00
for ( current_index = 0 ; current_index < error_count_diff ; current_index + + ) {
add_next_index_null ( return_value ) ;
}
}
2004-05-21 01:22:13 +08:00
}
/* }}} */
2004-05-26 02:32:48 +08:00
/* {{{ proto bool PDOStatement::setAttribute(long attribute, mixed value)
Set an attribute */
static PHP_METHOD ( PDOStatement , setAttribute )
{
long attr ;
zval * value = NULL ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-26 02:32:48 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " lz! " , & attr , & value ) ) {
RETURN_FALSE ;
}
if ( ! stmt - > methods - > set_attribute ) {
goto fail ;
}
PDO_STMT_CLEAR_ERR ( ) ;
if ( stmt - > methods - > set_attribute ( stmt , attr , value TSRMLS_CC ) ) {
RETURN_TRUE ;
}
fail :
if ( ! stmt - > methods - > set_attribute ) {
2005-02-07 05:05:59 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " , " This driver doesn't support setting attributes " TSRMLS_CC ) ;
2004-05-26 02:32:48 +08:00
} else {
PDO_HANDLE_STMT_ERR ( ) ;
}
RETURN_FALSE ;
}
/* }}} */
2004-05-17 23:41:51 +08:00
2004-05-26 02:32:48 +08:00
/* {{{ proto mixed PDOStatement::getAttribute(long attribute)
Get an attribute */
2006-04-09 16:05:01 +08:00
static int generic_stmt_attr_get ( pdo_stmt_t * stmt , zval * return_value , long attr )
{
switch ( attr ) {
case PDO_ATTR_EMULATE_PREPARES :
RETVAL_BOOL ( stmt - > supports_placeholders = = PDO_PLACEHOLDER_NONE ) ;
return 1 ;
}
return 0 ;
}
2004-05-26 02:32:48 +08:00
static PHP_METHOD ( PDOStatement , getAttribute )
{
long attr ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-05-26 02:32:48 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & attr ) ) {
RETURN_FALSE ;
}
if ( ! stmt - > methods - > get_attribute ) {
2006-04-09 16:05:01 +08:00
if ( ! generic_stmt_attr_get ( stmt , return_value , attr ) ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " ,
" This driver doesn't support getting attributes " TSRMLS_CC ) ;
RETURN_FALSE ;
}
return ;
2004-05-26 02:32:48 +08:00
}
PDO_STMT_CLEAR_ERR ( ) ;
switch ( stmt - > methods - > get_attribute ( stmt , attr , return_value TSRMLS_CC ) ) {
case - 1 :
PDO_HANDLE_STMT_ERR ( ) ;
RETURN_FALSE ;
case 0 :
2006-04-09 16:05:01 +08:00
if ( ! generic_stmt_attr_get ( stmt , return_value , attr ) ) {
/* XXX: should do something better here */
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " ,
" driver doesn't support getting that attribute " TSRMLS_CC ) ;
RETURN_FALSE ;
}
return ;
2004-05-26 02:32:48 +08:00
default :
return ;
}
}
/* }}} */
2004-05-17 23:41:51 +08:00
2004-09-27 04:45:44 +08:00
/* {{{ proto int PDOStatement::columnCount()
Returns the number of columns in the result set */
static PHP_METHOD ( PDOStatement , columnCount )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2004-09-27 04:45:44 +08:00
}
RETURN_LONG ( stmt - > column_count ) ;
}
/* }}} */
/* {{{ proto array PDOStatement::getColumnMeta(int $column)
Returns meta data for a numbered column */
static PHP_METHOD ( PDOStatement , getColumnMeta )
{
long colno ;
struct pdo_column_data * col ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2004-09-27 04:45:44 +08:00
if ( FAILURE = = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & colno ) ) {
RETURN_FALSE ;
}
2005-09-01 22:44:11 +08:00
if ( colno < 0 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " 42P10 " , " column number must be non-negative " TSRMLS_CC ) ;
RETURN_FALSE ;
}
2006-01-23 07:57:41 +08:00
2004-09-27 04:45:44 +08:00
if ( ! stmt - > methods - > get_column_meta ) {
2005-02-07 05:05:59 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " , " driver doesn't support meta data " TSRMLS_CC ) ;
2004-09-27 04:45:44 +08:00
RETURN_FALSE ;
}
PDO_STMT_CLEAR_ERR ( ) ;
if ( FAILURE = = stmt - > methods - > get_column_meta ( stmt , colno , return_value TSRMLS_CC ) ) {
PDO_HANDLE_STMT_ERR ( ) ;
RETURN_FALSE ;
}
/* add stock items */
col = & stmt - > columns [ colno ] ;
2014-04-15 19:40:40 +08:00
add_assoc_string ( return_value , " name " , col - > name ) ;
2004-09-27 04:45:44 +08:00
add_assoc_long ( return_value , " len " , col - > maxlen ) ; /* FIXME: unsigned ? */
add_assoc_long ( return_value , " precision " , col - > precision ) ;
2008-07-21 21:09:28 +08:00
if ( col - > param_type ! = PDO_PARAM_ZVAL ) {
/* if param_type is PDO_PARAM_ZVAL the driver has to provide correct data */
add_assoc_long ( return_value , " pdo_type " , col - > param_type ) ;
}
2004-09-27 04:45:44 +08:00
}
/* }}} */
2005-02-20 22:31:44 +08:00
/* {{{ proto bool PDOStatement::setFetchMode(int mode [mixed* params])
Changes the default fetch mode for subsequent fetches ( params have different meaning for different fetch modes ) */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
int pdo_stmt_setup_fetch_mode ( INTERNAL_FUNCTION_PARAMETERS , pdo_stmt_t * stmt , int skip )
{
long mode = PDO_FETCH_BOTH ;
2013-08-21 04:36:18 +08:00
int flags = 0 , argc = ZEND_NUM_ARGS ( ) - skip ;
2014-04-22 18:23:03 +08:00
zval * args ;
zend_class_entry * cep ;
2009-04-03 00:41:23 +08:00
int retval ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2005-02-23 08:52:46 +08:00
do_fetch_opt_finish ( stmt , 1 TSRMLS_CC ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2005-02-23 08:52:46 +08:00
switch ( stmt - > default_fetch_type ) {
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_INTO :
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . into ) ) {
2010-07-30 07:38:55 +08:00
zval_ptr_dtor ( & stmt - > fetch . into ) ;
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & stmt - > fetch . into ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
break ;
default :
;
}
stmt - > default_fetch_type = PDO_FETCH_BOTH ;
if ( argc = = 0 ) {
return SUCCESS ;
}
2014-04-24 21:14:36 +08:00
args = safe_emalloc ( ZEND_NUM_ARGS ( ) , sizeof ( zval ) , 0 ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2009-04-03 00:41:23 +08:00
retval = zend_get_parameters_array_ex ( ZEND_NUM_ARGS ( ) , args ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2009-04-03 00:41:23 +08:00
if ( SUCCESS = = retval ) {
2014-04-22 18:23:03 +08:00
if ( Z_TYPE ( args [ skip ] ) ! = IS_LONG ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " mode must be an integer " TSRMLS_CC ) ;
retval = FAILURE ;
} else {
2014-04-22 18:23:03 +08:00
mode = Z_LVAL ( args [ skip ] ) ;
2009-04-03 00:41:23 +08:00
flags = mode & PDO_FETCH_FLAGS ;
2005-02-23 03:27:34 +08:00
2009-04-03 00:41:23 +08:00
retval = pdo_stmt_verify_mode ( stmt , mode , 0 TSRMLS_CC ) ;
}
}
if ( FAILURE = = retval ) {
PDO_STMT_CLEAR_ERR ( ) ;
2005-12-02 03:59:58 +08:00
efree ( args ) ;
2005-02-23 03:27:34 +08:00
return FAILURE ;
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2009-04-03 00:41:23 +08:00
retval = FAILURE ;
2005-02-20 22:31:44 +08:00
switch ( mode & ~ PDO_FETCH_FLAGS ) {
2005-12-02 03:59:58 +08:00
case PDO_FETCH_USE_DEFAULT :
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
case PDO_FETCH_LAZY :
case PDO_FETCH_ASSOC :
case PDO_FETCH_NUM :
case PDO_FETCH_BOTH :
case PDO_FETCH_OBJ :
case PDO_FETCH_BOUND :
2005-09-11 03:32:15 +08:00
case PDO_FETCH_NAMED :
2007-10-12 04:54:41 +08:00
case PDO_FETCH_KEY_PAIR :
2009-04-03 00:41:23 +08:00
if ( argc ! = 1 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " fetch mode doesn't allow any extra arguments " TSRMLS_CC ) ;
} else {
retval = SUCCESS ;
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
case PDO_FETCH_COLUMN :
if ( argc ! = 2 ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " fetch mode requires the colno argument " TSRMLS_CC ) ;
2014-04-22 18:23:03 +08:00
} else if ( Z_TYPE ( args [ skip + 1 ] ) ! = IS_LONG ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " colno must be an integer " TSRMLS_CC ) ;
} else {
2014-04-22 18:23:03 +08:00
stmt - > fetch . column = Z_LVAL ( args [ skip + 1 ] ) ;
2009-04-03 00:41:23 +08:00
retval = SUCCESS ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
break ;
case PDO_FETCH_CLASS :
2008-10-15 01:36:02 +08:00
/* Gets its class name from 1st column */
if ( ( flags & PDO_FETCH_CLASSTYPE ) = = PDO_FETCH_CLASSTYPE ) {
if ( argc ! = 1 ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " fetch mode doesn't allow any extra arguments " TSRMLS_CC ) ;
} else {
stmt - > fetch . cls . ce = NULL ;
retval = SUCCESS ;
2008-10-15 01:36:02 +08:00
}
} else {
2009-04-03 00:41:23 +08:00
if ( argc < 2 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " fetch mode requires the classname argument " TSRMLS_CC ) ;
} else if ( argc > 3 ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " too many arguments " TSRMLS_CC ) ;
2014-04-22 18:23:03 +08:00
} else if ( Z_TYPE ( args [ skip + 1 ] ) ! = IS_STRING ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " classname must be a string " TSRMLS_CC ) ;
} else {
2014-04-22 18:23:03 +08:00
cep = zend_lookup_class ( Z_STR ( args [ skip + 1 ] ) TSRMLS_CC ) ;
if ( cep ) {
retval = SUCCESS ;
stmt - > fetch . cls . ce = cep ;
2009-04-03 00:41:23 +08:00
}
2008-10-15 01:36:02 +08:00
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2008-10-15 01:36:02 +08:00
2009-04-03 00:41:23 +08:00
if ( SUCCESS = = retval ) {
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & stmt - > fetch . cls . ctor_args ) ;
2006-12-04 11:07:44 +08:00
# ifdef ilia_0 /* we'll only need this when we have persistent statements, if ever */
2009-04-03 00:41:23 +08:00
if ( stmt - > dbh - > is_persistent ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " PHP might crash if you don't call $stmt->setFetchMode() to reset to defaults on this persistent statement. This will be fixed in a later release " ) ;
}
2006-12-04 11:07:44 +08:00
# endif
2009-04-03 00:41:23 +08:00
if ( argc = = 3 ) {
2014-04-22 18:23:03 +08:00
if ( Z_TYPE ( args [ skip + 2 ] ) ! = IS_NULL & & Z_TYPE ( args [ skip + 2 ] ) ! = IS_ARRAY ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " ctor_args must be either NULL or an array " TSRMLS_CC ) ;
retval = FAILURE ;
2014-04-22 18:23:03 +08:00
} else if ( Z_TYPE ( args [ skip + 2 ] ) = = IS_ARRAY & & zend_hash_num_elements ( Z_ARRVAL ( args [ skip + 2 ] ) ) ) {
ZVAL_DUP ( & stmt - > fetch . cls . ctor_args , & args [ skip + 2 ] ) ;
2009-04-03 00:41:23 +08:00
}
}
if ( SUCCESS = = retval ) {
do_fetch_class_prepare ( stmt TSRMLS_CC ) ;
2005-02-14 01:04:04 +08:00
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2005-02-20 22:31:44 +08:00
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
case PDO_FETCH_INTO :
if ( argc ! = 2 ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " fetch mode requires the object parameter " TSRMLS_CC ) ;
2014-04-22 18:23:03 +08:00
} else if ( Z_TYPE ( args [ skip + 1 ] ) ! = IS_OBJECT ) {
2009-04-03 00:41:23 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " object must be an object " TSRMLS_CC ) ;
} else {
retval = SUCCESS ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2009-04-03 00:41:23 +08:00
if ( SUCCESS = = retval ) {
2006-12-04 11:07:44 +08:00
# ifdef ilia_0 /* we'll only need this when we have persistent statements, if ever */
2009-04-03 00:41:23 +08:00
if ( stmt - > dbh - > is_persistent ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " PHP might crash if you don't call $stmt->setFetchMode() to reset to defaults on this persistent statement. This will be fixed in a later release " ) ;
}
2006-12-04 11:07:44 +08:00
# endif
2014-04-25 11:45:23 +08:00
ZVAL_COPY ( & stmt - > fetch . into , & args [ skip + 1 ] ) ;
2009-04-03 00:41:23 +08:00
}
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
break ;
default :
2005-12-16 06:33:02 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " 22003 " , " Invalid fetch mode specified " TSRMLS_CC ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2009-04-03 00:41:23 +08:00
if ( SUCCESS = = retval ) {
stmt - > default_fetch_type = mode ;
}
/*
* PDO error ( if any ) has already been raised at this point .
*
* The error_code is cleared , otherwise the caller will read the
* last error message from the driver .
*
*/
PDO_STMT_CLEAR_ERR ( ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2009-04-03 00:41:23 +08:00
efree ( args ) ;
return retval ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
static PHP_METHOD ( PDOStatement , setFetchMode )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
RETVAL_BOOL (
pdo_stmt_setup_fetch_mode ( INTERNAL_FUNCTION_PARAM_PASSTHRU ,
stmt , 0 ) = = SUCCESS ? 1 : 0
) ;
}
/* }}} */
2005-01-19 09:12:52 +08:00
/* {{{ proto bool PDOStatement::nextRowset()
Advances to the next rowset in a multi - rowset statement handle . Returns true if it succeded , false otherwise */
2005-07-09 11:52:41 +08:00
static int pdo_stmt_do_next_rowset ( pdo_stmt_t * stmt TSRMLS_DC )
{
2005-01-19 09:12:52 +08:00
/* un-describe */
if ( stmt - > columns ) {
int i ;
struct pdo_column_data * cols = stmt - > columns ;
for ( i = 0 ; i < stmt - > column_count ; i + + ) {
efree ( cols [ i ] . name ) ;
}
efree ( stmt - > columns ) ;
2005-07-09 11:52:41 +08:00
stmt - > columns = NULL ;
stmt - > column_count = 0 ;
2005-01-19 09:12:52 +08:00
}
2006-12-09 03:50:40 +08:00
if ( ! stmt - > methods - > next_rowset ( stmt TSRMLS_CC ) ) {
2010-04-27 13:56:56 +08:00
/* Set the executed flag to 0 to reallocate columns on next execute */
stmt - > executed = 0 ;
2006-12-09 03:50:40 +08:00
return 0 ;
}
2005-07-09 11:52:41 +08:00
pdo_stmt_describe_columns ( stmt TSRMLS_CC ) ;
return 1 ;
}
static PHP_METHOD ( PDOStatement , nextRowset )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2005-07-09 11:52:41 +08:00
if ( ! stmt - > methods - > next_rowset ) {
pdo_raise_impl_error ( stmt - > dbh , stmt , " IM001 " , " driver does not support multiple rowsets " TSRMLS_CC ) ;
RETURN_FALSE ;
}
PDO_STMT_CLEAR_ERR ( ) ;
if ( ! pdo_stmt_do_next_rowset ( stmt TSRMLS_CC ) ) {
2005-01-19 09:12:52 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2005-07-09 11:52:41 +08:00
/* {{{ proto bool PDOStatement::closeCursor()
Closes the cursor , leaving the statement ready for re - execution . */
static PHP_METHOD ( PDOStatement , closeCursor )
{
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2005-07-09 11:52:41 +08:00
if ( ! stmt - > methods - > cursor_closer ) {
/* emulate it by fetching and discarding rows */
do {
while ( stmt - > methods - > fetcher ( stmt , PDO_FETCH_ORI_NEXT , 0 TSRMLS_CC ) )
;
if ( ! stmt - > methods - > next_rowset ) {
break ;
}
if ( ! pdo_stmt_do_next_rowset ( stmt TSRMLS_CC ) ) {
break ;
}
} while ( 1 ) ;
2006-11-29 00:27:53 +08:00
stmt - > executed = 0 ;
2005-07-09 11:52:41 +08:00
RETURN_TRUE ;
}
PDO_STMT_CLEAR_ERR ( ) ;
if ( ! stmt - > methods - > cursor_closer ( stmt TSRMLS_CC ) ) {
PDO_HANDLE_STMT_ERR ( ) ;
RETURN_FALSE ;
}
2006-11-29 00:27:53 +08:00
stmt - > executed = 0 ;
2005-07-09 11:52:41 +08:00
RETURN_TRUE ;
}
/* }}} */
2005-07-18 22:46:55 +08:00
/* {{{ proto void PDOStatement::debugDumpParams()
A utility for internals hackers to debug parameter internals */
static PHP_METHOD ( PDOStatement , debugDumpParams )
{
php_stream * out = php_stream_open_wrapper ( " php://output " , " w " , 0 , NULL ) ;
struct pdo_bound_param_data * param ;
2005-11-08 00:53:15 +08:00
PHP_STMT_GET_OBJ ;
2005-07-18 22:46:55 +08:00
2006-03-19 06:24:05 +08:00
if ( out = = NULL ) {
RETURN_FALSE ;
}
2005-07-18 22:46:55 +08:00
php_stream_printf ( out TSRMLS_CC , " SQL: [%d] %.*s \n " ,
stmt - > query_stringlen ,
stmt - > query_stringlen , stmt - > query_string ) ;
php_stream_printf ( out TSRMLS_CC , " Params: %d \n " ,
stmt - > bound_params ? zend_hash_num_elements ( stmt - > bound_params ) : 0 ) ;
if ( stmt - > bound_params ) {
2014-04-22 18:23:03 +08:00
ulong num ;
zend_string * key = NULL ;
ZEND_HASH_FOREACH_KEY_PTR ( stmt - > bound_params , num , key , param ) {
if ( key ) {
php_stream_printf ( out TSRMLS_CC , " Key: Name: [%d] %.*s \n " , key - > len , key - > len , key - > val ) ;
} else {
2008-11-06 07:40:38 +08:00
php_stream_printf ( out TSRMLS_CC , " Key: Position #%ld: \n " , num ) ;
2005-07-18 22:46:55 +08:00
}
2010-12-23 22:38:15 +08:00
php_stream_printf ( out TSRMLS_CC , " paramno=%ld \n name=[%d] \" %.*s \" \n is_param=%d \n param_type=%d \n " ,
2014-04-24 21:14:36 +08:00
param - > paramno , param - > name ? param - > name - > len : 0 , param - > name ? param - > name - > len : 0 ,
param - > name ? param - > name - > val : " " ,
2014-04-22 18:23:03 +08:00
param - > is_param ,
param - > param_type ) ;
} ZEND_HASH_FOREACH_END ( ) ;
2005-07-18 22:46:55 +08:00
}
php_stream_close ( out ) ;
}
/* }}} */
2005-09-11 01:48:45 +08:00
/* {{{ proto int PDOStatement::__wakeup()
Prevents use of a PDOStatement instance that has been unserialized */
static PHP_METHOD ( PDOStatement , __wakeup )
{
zend_throw_exception_ex ( php_pdo_get_exception ( ) , 0 TSRMLS_CC , " You cannot serialize or unserialize PDOStatement instances " ) ;
}
/* }}} */
/* {{{ proto int PDOStatement::__sleep()
Prevents serialization of a PDOStatement instance */
static PHP_METHOD ( PDOStatement , __sleep )
{
zend_throw_exception_ex ( php_pdo_get_exception ( ) , 0 TSRMLS_CC , " You cannot serialize or unserialize PDOStatement instances " ) ;
}
/* }}} */
2005-07-09 11:52:41 +08:00
2007-09-28 02:00:48 +08:00
const zend_function_entry pdo_dbstmt_functions [ ] = {
2007-08-30 22:06:12 +08:00
PHP_ME ( PDOStatement , execute , arginfo_pdostatement_execute , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , fetch , arginfo_pdostatement_fetch , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , bindParam , arginfo_pdostatement_bindparam , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , bindColumn , arginfo_pdostatement_bindcolumn , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , bindValue , arginfo_pdostatement_bindvalue , ZEND_ACC_PUBLIC )
2011-06-18 23:56:14 +08:00
PHP_ME ( PDOStatement , rowCount , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
2007-08-30 22:06:12 +08:00
PHP_ME ( PDOStatement , fetchColumn , arginfo_pdostatement_fetchcolumn , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , fetchAll , arginfo_pdostatement_fetchall , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , fetchObject , arginfo_pdostatement_fetchobject , ZEND_ACC_PUBLIC )
2011-06-18 23:56:14 +08:00
PHP_ME ( PDOStatement , errorCode , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , errorInfo , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
2007-08-30 22:06:12 +08:00
PHP_ME ( PDOStatement , setAttribute , arginfo_pdostatement_setattribute , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , getAttribute , arginfo_pdostatement_getattribute , ZEND_ACC_PUBLIC )
2011-06-18 23:56:14 +08:00
PHP_ME ( PDOStatement , columnCount , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
2007-08-30 22:06:12 +08:00
PHP_ME ( PDOStatement , getColumnMeta , arginfo_pdostatement_getcolumnmeta , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , setFetchMode , arginfo_pdostatement_setfetchmode , ZEND_ACC_PUBLIC )
2011-06-18 23:56:14 +08:00
PHP_ME ( PDOStatement , nextRowset , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , closeCursor , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , debugDumpParams , arginfo_pdostatement__void , ZEND_ACC_PUBLIC )
PHP_ME ( PDOStatement , __wakeup , arginfo_pdostatement__void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
PHP_ME ( PDOStatement , __sleep , arginfo_pdostatement__void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
2004-05-17 23:41:51 +08:00
{ NULL , NULL , NULL }
} ;
/* {{{ overloaded handlers for PDOStatement class */
2014-04-22 18:23:03 +08:00
static void dbstmt_prop_write ( zval * object , zval * member , zval * value , zend_uint cache_slot TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2014-04-22 18:23:03 +08:00
pdo_stmt_t * stmt = Z_PDO_STMT_P ( object ) ;
2004-05-17 23:41:51 +08:00
2004-05-19 04:26:24 +08:00
convert_to_string ( member ) ;
2004-05-17 23:41:51 +08:00
2014-04-24 21:14:36 +08:00
if ( strcmp ( Z_STRVAL_P ( member ) , " queryString " ) = = 0 ) {
2005-03-21 08:29:06 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " property queryString is read only " TSRMLS_CC ) ;
2004-05-21 22:09:51 +08:00
} else {
2014-04-22 18:23:03 +08:00
std_object_handlers . write_property ( object , member , value , cache_slot TSRMLS_CC ) ;
2004-05-19 04:26:24 +08:00
}
2004-05-17 23:41:51 +08:00
}
2014-04-22 18:23:03 +08:00
static void dbstmt_prop_delete ( zval * object , zval * member , zend_uint cache_slot TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2014-04-22 18:23:03 +08:00
pdo_stmt_t * stmt = Z_PDO_STMT_P ( object ) ;
2004-05-17 23:41:51 +08:00
2005-03-21 08:29:06 +08:00
convert_to_string ( member ) ;
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
if ( strcmp ( Z_STRVAL_P ( member ) , " queryString " ) = = 0 ) {
2005-03-21 08:29:06 +08:00
pdo_raise_impl_error ( stmt - > dbh , stmt , " HY000 " , " property queryString is read only " TSRMLS_CC ) ;
} else {
2014-04-22 18:23:03 +08:00
std_object_handlers . unset_property ( object , member , cache_slot TSRMLS_CC ) ;
2005-03-21 08:29:06 +08:00
}
2004-05-17 23:41:51 +08:00
}
2014-04-22 18:23:03 +08:00
static union _zend_function * dbstmt_method_get ( zend_object * * object_pp , zend_string * method_name , const zval * key TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2005-01-07 13:23:10 +08:00
zend_function * fbc = NULL ;
2014-04-22 18:23:03 +08:00
zend_string * lc_method_name ;
zend_object * object = * object_pp ;
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
lc_method_name = STR_ALLOC ( method_name - > len , 0 ) ;
zend_str_tolower_copy ( lc_method_name - > val , method_name - > val , method_name - > len ) ;
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
if ( ( fbc = zend_hash_find_ptr ( & object - > ce - > function_table , lc_method_name ) ) = = NULL ) {
pdo_stmt_t * stmt = php_pdo_stmt_fetch_object ( object ) ;
2010-06-17 07:13:29 +08:00
/* instance not created by PDO object */
if ( ! stmt - > dbh ) {
goto out ;
}
2005-01-07 13:23:10 +08:00
/* not a pre-defined method, nor a user-defined method; check
* the driver specific methods */
if ( ! stmt - > dbh - > cls_methods [ PDO_DBH_DRIVER_METHOD_KIND_STMT ] ) {
2005-01-18 07:59:16 +08:00
if ( ! pdo_hash_methods ( stmt - > dbh ,
PDO_DBH_DRIVER_METHOD_KIND_STMT TSRMLS_CC )
| | ! stmt - > dbh - > cls_methods [ PDO_DBH_DRIVER_METHOD_KIND_STMT ] ) {
2005-01-07 13:23:10 +08:00
goto out ;
}
}
2014-04-22 18:23:03 +08:00
if ( ( fbc = zend_hash_find_ptr ( stmt - > dbh - > cls_methods [ PDO_DBH_DRIVER_METHOD_KIND_STMT ] , lc_method_name ) ) = = NULL ) {
2005-01-07 13:23:10 +08:00
goto out ;
}
/* got it */
2004-05-17 23:41:51 +08:00
}
2005-01-07 13:23:10 +08:00
out :
2014-04-22 18:23:03 +08:00
STR_RELEASE ( lc_method_name ) ;
2004-05-17 23:41:51 +08:00
return fbc ;
}
2005-03-21 08:29:06 +08:00
static int dbstmt_compare ( zval * object1 , zval * object2 TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2005-03-21 08:29:06 +08:00
return - 1 ;
2004-05-17 23:41:51 +08:00
}
2014-04-22 18:23:03 +08:00
static zend_object * dbstmt_clone_obj ( zval * zobject TSRMLS_DC )
2006-01-02 04:07:41 +08:00
{
pdo_stmt_t * stmt ;
pdo_stmt_t * old_stmt ;
2014-04-22 18:23:03 +08:00
stmt = ecalloc ( 1 , sizeof ( pdo_stmt_t ) + sizeof ( zval ) * ( Z_OBJCE_P ( zobject ) - > default_properties_count - 1 ) ) ;
2010-05-06 16:37:41 +08:00
zend_object_std_init ( & stmt - > std , Z_OBJCE_P ( zobject ) TSRMLS_CC ) ;
2010-05-24 22:11:39 +08:00
object_properties_init ( & stmt - > std , Z_OBJCE_P ( zobject ) ) ;
2006-01-02 04:07:41 +08:00
2014-04-22 18:23:03 +08:00
old_stmt = Z_PDO_STMT_P ( zobject ) ;
2006-01-02 04:07:41 +08:00
2014-04-22 18:23:03 +08:00
zend_objects_clone_members ( & stmt - > std , & old_stmt - > std TSRMLS_CC ) ;
2006-01-02 04:07:41 +08:00
2014-04-22 18:23:03 +08:00
return & stmt - > std ;
2006-01-02 04:07:41 +08:00
}
2005-04-22 10:40:48 +08:00
zend_object_handlers pdo_dbstmt_object_handlers ;
2011-09-25 20:39:05 +08:00
static int pdo_row_serialize ( zval * object , unsigned char * * buffer , zend_uint * buf_len , zend_serialize_data * data TSRMLS_DC ) ;
2004-05-17 23:41:51 +08:00
2005-03-21 08:29:06 +08:00
void pdo_stmt_init ( TSRMLS_D )
2004-05-17 23:41:51 +08:00
{
2005-03-21 08:29:06 +08:00
zend_class_entry ce ;
2004-05-17 23:41:51 +08:00
2005-03-21 08:29:06 +08:00
INIT_CLASS_ENTRY ( ce , " PDOStatement " , pdo_dbstmt_functions ) ;
pdo_dbstmt_ce = zend_register_internal_class ( & ce TSRMLS_CC ) ;
pdo_dbstmt_ce - > get_iterator = pdo_stmt_iter_get ;
pdo_dbstmt_ce - > create_object = pdo_dbstmt_new ;
zend_class_implements ( pdo_dbstmt_ce TSRMLS_CC , 1 , zend_ce_traversable ) ;
zend_declare_property_null ( pdo_dbstmt_ce , " queryString " , sizeof ( " queryString " ) - 1 , ZEND_ACC_PUBLIC TSRMLS_CC ) ;
2004-05-17 23:41:51 +08:00
2005-03-21 08:29:06 +08:00
memcpy ( & pdo_dbstmt_object_handlers , & std_object_handlers , sizeof ( zend_object_handlers ) ) ;
2014-04-22 18:23:03 +08:00
pdo_dbstmt_object_handlers . offset = XtOffsetOf ( pdo_stmt_t , std ) ;
pdo_dbstmt_object_handlers . dtor_obj = zend_objects_destroy_object ;
pdo_dbstmt_object_handlers . free_obj = pdo_dbstmt_free_storage ;
2005-03-21 08:29:06 +08:00
pdo_dbstmt_object_handlers . write_property = dbstmt_prop_write ;
pdo_dbstmt_object_handlers . unset_property = dbstmt_prop_delete ;
pdo_dbstmt_object_handlers . get_method = dbstmt_method_get ;
pdo_dbstmt_object_handlers . compare_objects = dbstmt_compare ;
2006-01-02 04:07:41 +08:00
pdo_dbstmt_object_handlers . clone_obj = dbstmt_clone_obj ;
2004-05-17 23:41:51 +08:00
2005-03-21 08:29:06 +08:00
INIT_CLASS_ENTRY ( ce , " PDORow " , pdo_row_functions ) ;
pdo_row_ce = zend_register_internal_class ( & ce TSRMLS_CC ) ;
pdo_row_ce - > ce_flags | = ZEND_ACC_FINAL_CLASS ; /* when removing this a lot of handlers need to be redone */
pdo_row_ce - > create_object = pdo_row_new ;
2011-09-25 20:39:05 +08:00
pdo_row_ce - > serialize = pdo_row_serialize ;
2005-03-21 08:29:06 +08:00
}
2004-05-17 23:41:51 +08:00
2004-05-26 01:43:24 +08:00
static void free_statement ( pdo_stmt_t * stmt TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2005-07-08 23:25:15 +08:00
if ( stmt - > bound_params ) {
zend_hash_destroy ( stmt - > bound_params ) ;
FREE_HASHTABLE ( stmt - > bound_params ) ;
2005-07-12 10:40:59 +08:00
stmt - > bound_params = NULL ;
2005-07-08 23:25:15 +08:00
}
if ( stmt - > bound_param_map ) {
zend_hash_destroy ( stmt - > bound_param_map ) ;
FREE_HASHTABLE ( stmt - > bound_param_map ) ;
2005-07-12 10:40:59 +08:00
stmt - > bound_param_map = NULL ;
2005-07-08 23:25:15 +08:00
}
if ( stmt - > bound_columns ) {
zend_hash_destroy ( stmt - > bound_columns ) ;
FREE_HASHTABLE ( stmt - > bound_columns ) ;
2005-07-12 10:40:59 +08:00
stmt - > bound_columns = NULL ;
2005-07-08 23:25:15 +08:00
}
2004-05-17 23:41:51 +08:00
if ( stmt - > methods & & stmt - > methods - > dtor ) {
stmt - > methods - > dtor ( stmt TSRMLS_CC ) ;
}
2004-05-21 21:26:58 +08:00
if ( stmt - > query_string ) {
2004-05-19 04:33:30 +08:00
efree ( stmt - > query_string ) ;
}
2004-05-25 22:35:49 +08:00
2005-01-19 11:44:49 +08:00
if ( stmt - > columns ) {
2004-05-25 22:35:49 +08:00
int i ;
struct pdo_column_data * cols = stmt - > columns ;
for ( i = 0 ; i < stmt - > column_count ; i + + ) {
2005-07-27 22:18:01 +08:00
if ( cols [ i ] . name ) {
efree ( cols [ i ] . name ) ;
cols [ i ] . name = NULL ;
}
2004-05-25 22:35:49 +08:00
}
efree ( stmt - > columns ) ;
2005-07-27 22:18:01 +08:00
stmt - > columns = NULL ;
2004-05-25 22:35:49 +08:00
}
2004-05-26 00:38:28 +08:00
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > fetch . into ) & & stmt - > default_fetch_type = = PDO_FETCH_INTO ) {
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & stmt - > fetch . into ) ;
2005-08-04 02:26:16 +08:00
}
2004-05-25 22:35:49 +08:00
2005-02-23 03:27:34 +08:00
do_fetch_opt_finish ( stmt , 1 TSRMLS_CC ) ;
2005-02-20 22:31:44 +08:00
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( stmt - > database_object_handle ) ) {
2014-04-25 10:27:23 +08:00
zval_ptr_dtor ( & stmt - > database_object_handle ) ;
2006-08-24 03:15:57 +08:00
}
2010-05-06 16:37:41 +08:00
zend_object_std_dtor ( & stmt - > std TSRMLS_CC ) ;
2004-05-26 01:43:24 +08:00
}
2014-04-22 18:23:03 +08:00
void pdo_dbstmt_free_storage ( zend_object * std TSRMLS_DC )
2005-10-31 10:07:38 +08:00
{
2014-04-22 18:23:03 +08:00
pdo_stmt_t * stmt = php_pdo_stmt_fetch_object ( std ) ;
2014-04-24 21:14:36 +08:00
free_statement ( stmt TSRMLS_CC ) ;
2005-10-31 10:07:38 +08:00
}
2014-04-22 18:23:03 +08:00
zend_object * pdo_dbstmt_new ( zend_class_entry * ce TSRMLS_DC )
2004-05-17 23:41:51 +08:00
{
2005-02-23 03:27:34 +08:00
pdo_stmt_t * stmt ;
2014-04-22 18:23:03 +08:00
stmt = ecalloc ( 1 , sizeof ( pdo_stmt_t ) + sizeof ( zval ) * ( ce - > default_properties_count - 1 ) ) ;
2010-05-06 16:37:41 +08:00
zend_object_std_init ( & stmt - > std , ce TSRMLS_CC ) ;
2010-05-24 22:11:39 +08:00
object_properties_init ( & stmt - > std , ce ) ;
2005-02-23 03:27:34 +08:00
2014-04-22 18:23:03 +08:00
stmt - > std . handlers = & pdo_dbstmt_object_handlers ;
2004-05-17 23:41:51 +08:00
2014-04-22 18:23:03 +08:00
return & stmt - > std ;
2004-05-17 23:41:51 +08:00
}
/* }}} */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
/* {{{ statement iterator */
struct php_pdo_iterator {
zend_object_iterator iter ;
ulong key ;
2014-04-22 18:23:03 +08:00
zval fetch_ahead ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
} ;
static void pdo_stmt_iter_dtor ( zend_object_iterator * iter TSRMLS_DC )
{
2014-04-24 21:14:36 +08:00
struct php_pdo_iterator * I = ( struct php_pdo_iterator * ) iter ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-04-24 21:14:36 +08:00
zval_ptr_dtor ( & I - > iter . data ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( I - > fetch_ahead ) ) {
2005-07-07 19:19:56 +08:00
zval_ptr_dtor ( & I - > fetch_ahead ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
}
static int pdo_stmt_iter_valid ( zend_object_iterator * iter TSRMLS_DC )
{
2014-04-24 21:14:36 +08:00
struct php_pdo_iterator * I = ( struct php_pdo_iterator * ) iter ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-05-03 16:06:27 +08:00
return Z_ISUNDEF ( I - > fetch_ahead ) ? FAILURE : SUCCESS ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2014-04-22 18:23:03 +08:00
static zval * pdo_stmt_iter_get_data ( zend_object_iterator * iter TSRMLS_DC )
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
{
2014-04-24 21:14:36 +08:00
struct php_pdo_iterator * I = ( struct php_pdo_iterator * ) iter ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
/* sanity */
2014-05-03 16:06:27 +08:00
if ( Z_ISUNDEF ( I - > fetch_ahead ) ) {
2014-04-22 18:23:03 +08:00
return NULL ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2014-04-22 18:23:03 +08:00
return & I - > fetch_ahead ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2013-02-17 02:13:36 +08:00
static void pdo_stmt_iter_get_key ( zend_object_iterator * iter , zval * key TSRMLS_DC )
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
{
2014-04-24 21:14:36 +08:00
struct php_pdo_iterator * I = ( struct php_pdo_iterator * ) iter ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
if ( I - > key = = ( ulong ) - 1 ) {
2013-02-17 02:13:36 +08:00
ZVAL_NULL ( key ) ;
} else {
ZVAL_LONG ( key , I - > key ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
}
static void pdo_stmt_iter_move_forwards ( zend_object_iterator * iter TSRMLS_DC )
{
2014-04-24 21:14:36 +08:00
struct php_pdo_iterator * I = ( struct php_pdo_iterator * ) iter ;
pdo_stmt_t * stmt = Z_PDO_STMT_P ( & I - > iter . data ) ; /* for PDO_HANDLE_STMT_ERR() */
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( I - > fetch_ahead ) ) {
2005-07-07 19:19:56 +08:00
zval_ptr_dtor ( & I - > fetch_ahead ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
2014-04-24 21:14:36 +08:00
if ( ! do_fetch ( stmt , TRUE , & I - > fetch_ahead , PDO_FETCH_USE_DEFAULT ,
2005-02-20 07:11:23 +08:00
PDO_FETCH_ORI_NEXT , 0 , 0 TSRMLS_CC ) ) {
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
I - > key = ( ulong ) - 1 ;
2014-04-24 21:14:36 +08:00
ZVAL_UNDEF ( & I - > fetch_ahead ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
return ;
}
I - > key + + ;
}
static zend_object_iterator_funcs pdo_stmt_iter_funcs = {
pdo_stmt_iter_dtor ,
pdo_stmt_iter_valid ,
pdo_stmt_iter_get_data ,
pdo_stmt_iter_get_key ,
pdo_stmt_iter_move_forwards ,
NULL
} ;
2006-05-12 06:43:44 +08:00
zend_object_iterator * pdo_stmt_iter_get ( zend_class_entry * ce , zval * object , int by_ref TSRMLS_DC )
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
{
2014-04-22 18:23:03 +08:00
pdo_stmt_t * stmt = Z_PDO_STMT_P ( object ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
struct php_pdo_iterator * I ;
2006-05-12 06:43:44 +08:00
if ( by_ref ) {
zend_error ( E_ERROR , " An iterator cannot be used with foreach by reference " ) ;
}
2014-04-22 18:23:03 +08:00
I = ecalloc ( 1 , sizeof ( struct php_pdo_iterator ) ) ;
2014-04-24 21:14:36 +08:00
zend_iterator_init ( & I - > iter TSRMLS_CC ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
I - > iter . funcs = & pdo_stmt_iter_funcs ;
2014-04-24 21:14:36 +08:00
ZVAL_COPY ( & I - > iter . data , object ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
2014-04-24 21:14:36 +08:00
if ( ! do_fetch ( stmt , 1 , & I - > fetch_ahead , PDO_FETCH_USE_DEFAULT ,
2005-02-20 07:11:23 +08:00
PDO_FETCH_ORI_NEXT , 0 , 0 TSRMLS_CC ) ) {
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
PDO_HANDLE_STMT_ERR ( ) ;
I - > key = ( ulong ) - 1 ;
2014-04-22 18:23:03 +08:00
ZVAL_UNDEF ( & I - > fetch_ahead ) ;
Synopsis:
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
2004-10-27 18:26:27 +08:00
}
return & I - > iter ;
}
/* }}} */
2004-05-21 21:26:58 +08:00
/* {{{ overloaded handlers for PDORow class (used by PDO_FETCH_LAZY) */
2007-09-28 02:00:48 +08:00
const zend_function_entry pdo_row_functions [ ] = {
2004-05-21 21:26:58 +08:00
{ NULL , NULL , NULL }
} ;
2014-04-22 18:23:03 +08:00
static zval * row_prop_read ( zval * object , zval * member , int type , zend_uint cache_slot , zval * rv TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2014-04-24 21:14:36 +08:00
pdo_row_t * row = ( pdo_row_t * ) Z_OBJ_P ( object ) ;
pdo_stmt_t * stmt = row - > stmt ;
2004-05-21 21:26:58 +08:00
int colno = - 1 ;
2014-04-24 21:14:36 +08:00
zval zobj ;
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
ZVAL_NULL ( rv ) ;
2009-10-13 01:09:11 +08:00
if ( stmt ) {
if ( Z_TYPE_P ( member ) = = IS_LONG ) {
if ( Z_LVAL_P ( member ) > = 0 & & Z_LVAL_P ( member ) < stmt - > column_count ) {
2014-04-22 18:23:03 +08:00
fetch_value ( stmt , rv , Z_LVAL_P ( member ) , NULL TSRMLS_CC ) ;
2009-10-13 01:09:11 +08:00
}
} else {
convert_to_string ( member ) ;
/* TODO: replace this with a hash of available column names to column
* numbers */
for ( colno = 0 ; colno < stmt - > column_count ; colno + + ) {
if ( strcmp ( stmt - > columns [ colno ] . name , Z_STRVAL_P ( member ) ) = = 0 ) {
2014-04-22 18:23:03 +08:00
fetch_value ( stmt , rv , colno , NULL TSRMLS_CC ) ;
//???
//Z_SET_REFCOUNT_P(rv, 0);
//Z_UNSET_ISREF_P(rv);
return rv ;
2009-10-13 01:09:11 +08:00
}
}
if ( strcmp ( Z_STRVAL_P ( member ) , " queryString " ) = = 0 ) {
2014-04-24 21:14:36 +08:00
ZVAL_OBJ ( & zobj , & stmt - > std ) ;
//zval_ptr_dtor(rv);
return std_object_handlers . read_property ( & zobj , member , type , cache_slot , rv TSRMLS_CC ) ;
2004-05-21 22:31:51 +08:00
}
2008-11-04 07:44:38 +08:00
}
2004-05-21 21:26:58 +08:00
}
2005-07-22 10:09:19 +08:00
2014-04-22 18:23:03 +08:00
//???
//Z_SET_REFCOUNT_P(return_value, 0);
//Z_UNSET_ISREF_P(return_value);
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
return rv ;
2004-05-21 21:26:58 +08:00
}
2014-04-22 18:23:03 +08:00
static zval * row_dim_read ( zval * object , zval * member , int type , zval * rv TSRMLS_DC )
2010-04-20 18:57:45 +08:00
{
2014-04-22 18:23:03 +08:00
return row_prop_read ( object , member , type , - 1 , rv TSRMLS_CC ) ;
2010-04-20 18:57:45 +08:00
}
2014-04-22 18:23:03 +08:00
static void row_prop_write ( zval * object , zval * member , zval * value , zend_uint cache_slot TSRMLS_DC )
2010-04-20 18:57:45 +08:00
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " This PDORow is not from a writable result set " ) ;
}
static void row_dim_write ( zval * object , zval * member , zval * value TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " This PDORow is not from a writable result set " ) ;
}
2014-04-22 18:23:03 +08:00
static int row_prop_exists ( zval * object , zval * member , int check_empty , zend_uint cache_slot TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2014-04-24 21:14:36 +08:00
pdo_row_t * row = ( pdo_row_t * ) Z_OBJ_P ( object ) ;
pdo_stmt_t * stmt = row - > stmt ;
2004-05-21 21:26:58 +08:00
int colno = - 1 ;
2009-10-13 01:09:11 +08:00
if ( stmt ) {
if ( Z_TYPE_P ( member ) = = IS_LONG ) {
return Z_LVAL_P ( member ) > = 0 & & Z_LVAL_P ( member ) < stmt - > column_count ;
} else {
convert_to_string ( member ) ;
2004-05-21 21:26:58 +08:00
2009-10-13 01:09:11 +08:00
/* TODO: replace this with a hash of available column names to column
* numbers */
for ( colno = 0 ; colno < stmt - > column_count ; colno + + ) {
if ( strcmp ( stmt - > columns [ colno ] . name , Z_STRVAL_P ( member ) ) = = 0 ) {
return 1 ;
}
2004-05-21 22:31:51 +08:00
}
2004-05-21 21:26:58 +08:00
}
}
return 0 ;
}
2010-04-20 18:57:45 +08:00
static int row_dim_exists ( zval * object , zval * member , int check_empty TSRMLS_DC )
{
2014-04-22 18:23:03 +08:00
return row_prop_exists ( object , member , check_empty , - 1 TSRMLS_CC ) ;
2010-04-20 18:57:45 +08:00
}
2014-04-22 18:23:03 +08:00
static void row_prop_delete ( zval * object , zval * offset , zend_uint cache_slot TSRMLS_DC )
2010-04-20 18:57:45 +08:00
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot delete properties from a PDORow " ) ;
}
static void row_dim_delete ( zval * object , zval * offset TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot delete properties from a PDORow " ) ;
}
static HashTable * row_get_properties ( zval * object TSRMLS_DC )
{
2014-04-24 21:14:36 +08:00
pdo_row_t * row = ( pdo_row_t * ) Z_OBJ_P ( object ) ;
pdo_stmt_t * stmt = row - > stmt ;
2004-05-21 21:26:58 +08:00
int i ;
2009-10-13 01:09:11 +08:00
if ( stmt = = NULL ) {
return NULL ;
}
2010-05-24 22:11:39 +08:00
if ( ! stmt - > std . properties ) {
rebuild_object_properties ( & stmt - > std ) ;
}
2004-05-21 21:26:58 +08:00
for ( i = 0 ; i < stmt - > column_count ; i + + ) {
2014-04-22 18:23:03 +08:00
zval val ;
fetch_value ( stmt , & val , i , NULL TSRMLS_CC ) ;
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
zend_hash_str_update ( stmt - > std . properties , stmt - > columns [ i ] . name , stmt - > columns [ i ] . namelen , & val ) ;
2004-05-21 21:26:58 +08:00
}
2010-05-06 16:37:41 +08:00
return stmt - > std . properties ;
2004-05-21 21:26:58 +08:00
}
2004-12-28 06:04:54 +08:00
static union _zend_function * row_method_get (
2014-04-22 18:23:03 +08:00
zend_object * * object_pp ,
zend_string * method_name , const zval * key TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
zend_function * fbc ;
2014-04-22 18:23:03 +08:00
zend_string * lc_method_name ;
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
lc_method_name = STR_ALLOC ( method_name - > len , 0 ) ;
zend_str_tolower_copy ( lc_method_name - > val , method_name - > val , method_name - > len ) ;
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
if ( ( fbc = zend_hash_find_ptr ( & pdo_row_ce - > function_table , lc_method_name ) ) = = NULL ) {
STR_RELEASE ( lc_method_name ) ;
2004-05-21 21:26:58 +08:00
return NULL ;
}
2014-04-22 18:23:03 +08:00
STR_RELEASE ( lc_method_name ) ;
2004-05-21 21:26:58 +08:00
return fbc ;
}
2014-04-22 18:23:03 +08:00
static int row_call_method ( zend_string * method , zend_object * object , INTERNAL_FUNCTION_PARAMETERS )
2004-05-21 21:26:58 +08:00
{
return FAILURE ;
}
2014-04-22 18:23:03 +08:00
static union _zend_function * row_get_ctor ( zend_object * object TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
static zend_internal_function ctor = { 0 } ;
ctor . type = ZEND_INTERNAL_FUNCTION ;
2014-04-22 18:23:03 +08:00
ctor . function_name = STR_INIT ( " __construct " , sizeof ( " __construct " ) - 1 , 0 ) ;
2004-05-21 21:26:58 +08:00
ctor . scope = pdo_row_ce ;
ctor . handler = ZEND_FN ( dbstmt_constructor ) ;
2013-01-22 16:58:40 +08:00
ctor . fn_flags = ZEND_ACC_PUBLIC ;
2004-05-21 21:26:58 +08:00
return ( union _zend_function * ) & ctor ;
}
2014-04-22 18:23:03 +08:00
static zend_class_entry * row_get_ce ( const zend_object * object TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2009-03-13 00:13:17 +08:00
return pdo_row_ce ;
2004-05-21 21:26:58 +08:00
}
2014-04-22 18:23:03 +08:00
static zend_string * row_get_classname ( const zend_object * object , int parent TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2008-03-04 03:00:45 +08:00
if ( parent ) {
2014-04-22 18:23:03 +08:00
return NULL ;
2008-03-04 03:00:45 +08:00
} else {
2014-04-22 18:23:03 +08:00
return STR_INIT ( " PDORow " , sizeof ( " PDORow " ) - 1 , 0 ) ;
2008-03-04 03:00:45 +08:00
}
2004-05-21 21:26:58 +08:00
}
static int row_compare ( zval * object1 , zval * object2 TSRMLS_DC )
{
return - 1 ;
}
2005-04-22 10:40:48 +08:00
zend_object_handlers pdo_row_object_handlers = {
2014-04-22 18:23:03 +08:00
0 ,
zend_objects_destroy_object ,
pdo_row_free_storage ,
2010-06-03 00:54:13 +08:00
NULL ,
2010-04-20 18:57:45 +08:00
row_prop_read ,
row_prop_write ,
row_dim_read ,
row_dim_write ,
2004-05-21 21:26:58 +08:00
NULL ,
NULL ,
NULL ,
2010-04-20 18:57:45 +08:00
row_prop_exists ,
row_prop_delete ,
row_dim_exists ,
row_dim_delete ,
2004-05-21 21:26:58 +08:00
row_get_properties ,
row_method_get ,
row_call_method ,
row_get_ctor ,
row_get_ce ,
row_get_classname ,
row_compare ,
NULL , /* cast */
NULL
} ;
2014-04-22 18:23:03 +08:00
void pdo_row_free_storage ( zend_object * std TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2014-04-24 21:14:36 +08:00
pdo_row_t * row = ( pdo_row_t * ) std ;
if ( row - > stmt ) {
ZVAL_UNDEF ( & row - > stmt - > lazy_object_ref ) ;
OBJ_RELEASE ( & row - > stmt - > std ) ;
2004-05-26 01:43:24 +08:00
}
2004-05-21 21:26:58 +08:00
}
2014-04-22 18:23:03 +08:00
zend_object * pdo_row_new ( zend_class_entry * ce TSRMLS_DC )
2004-05-21 21:26:58 +08:00
{
2014-04-22 18:23:03 +08:00
pdo_row_t * row = ecalloc ( 1 , sizeof ( pdo_row_t ) ) ;
2014-04-24 21:14:36 +08:00
zend_object_std_init ( & row - > std , ce TSRMLS_CC ) ;
2014-04-22 18:23:03 +08:00
row - > std . handlers = & pdo_row_object_handlers ;
2004-05-21 21:26:58 +08:00
2014-04-22 18:23:03 +08:00
return & row - > std ;
2004-05-21 21:26:58 +08:00
}
2011-09-25 20:39:05 +08:00
static int pdo_row_serialize ( zval * object , unsigned char * * buffer , zend_uint * buf_len , zend_serialize_data * data TSRMLS_DC )
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " PDORow instances may not be serialized " ) ;
return FAILURE ;
}
2004-05-21 21:26:58 +08:00
/* }}} */
2004-05-17 23:41:51 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
* vim600 : noet sw = 4 ts = 4 fdm = marker
* vim < 600 : noet sw = 4 ts = 4
*/