2003-02-12 08:45:53 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2003-02-22 15:31:01 +08:00
| PHP Version 5 |
2003-02-12 08:45:53 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2010-01-03 17:23:27 +08:00
| Copyright ( c ) 1997 - 2010 The PHP Group |
2003-02-12 08:45:53 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
2003-02-12 08:45:53 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| 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 |
2003-02-12 08:45:53 +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 . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-10-06 05:23:56 +08:00
| Authors : Georg Richter < georg @ php . net > |
| Andrey Hristov < andrey @ php . net > |
| Ulf Wendel < uw @ php . net > |
2003-02-12 08:45:53 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
$ Id $
*/
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
# include <signal.h>
# include "php.h"
# include "php_ini.h"
2007-10-06 05:23:56 +08:00
# include "php_globals.h"
2003-02-12 08:45:53 +08:00
# include "ext/standard/info.h"
2007-10-06 05:23:56 +08:00
# include "php_mysqli_structs.h"
2003-02-12 08:45:53 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto mixed mysqli_affected_rows(object link)
2003-03-16 06:51:49 +08:00
Get number of affected rows in previous MySQL operation */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_affected_rows )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2003-02-16 20:03:37 +08:00
zval * mysql_link ;
2003-03-09 07:33:12 +08:00
my_ulonglong rc ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
2003-12-13 08:28:21 +08:00
return ;
2003-02-12 08:45:53 +08:00
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
rc = mysql_affected_rows ( mysql - > mysql ) ;
2005-01-29 01:35:37 +08:00
if ( rc = = ( my_ulonglong ) - 1 ) {
RETURN_LONG ( - 1 ) ;
}
2003-02-16 23:56:57 +08:00
MYSQLI_RETURN_LONG_LONG ( rc ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_autocommit(object link, bool mode)
2003-03-16 06:51:49 +08:00
Turn auto commit on or of */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_autocommit )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
zend_bool automode ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ob " , & mysql_link , mysqli_link_class_entry , & automode ) = = FAILURE ) {
2007-10-06 05:23:56 +08:00
return ;
2003-02-12 08:45:53 +08:00
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2006-07-12 17:51:47 +08:00
if ( mysql_autocommit ( mysql - > mysql , ( my_bool ) automode ) ) {
2005-01-27 18:18:28 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ mysqli_stmt_bind_param_do_bind */
2008-03-11 04:15:38 +08:00
# ifndef MYSQLI_USE_MYSQLND
2007-10-06 05:23:56 +08:00
static
int mysqli_stmt_bind_param_do_bind ( MY_STMT * stmt , unsigned int argc , unsigned int num_vars ,
zval * * * args , unsigned int start , const char * const types TSRMLS_DC )
2003-02-12 08:45:53 +08:00
{
2007-10-06 05:23:56 +08:00
int i , ofs ;
2003-03-09 07:33:12 +08:00
MYSQL_BIND * bind ;
unsigned long rc ;
2003-02-12 08:45:53 +08:00
/* prevent leak if variables are already bound */
2003-07-15 18:37:19 +08:00
if ( stmt - > param . var_cnt ) {
php_free_stmt_bind_buffer ( stmt - > param , FETCH_SIMPLE ) ;
2003-02-12 08:45:53 +08:00
}
2003-07-15 18:37:19 +08:00
stmt - > param . is_null = ecalloc ( num_vars , sizeof ( char ) ) ;
2007-10-06 05:23:56 +08:00
bind = ( MYSQL_BIND * ) ecalloc ( num_vars , sizeof ( MYSQL_BIND ) ) ;
2003-02-12 08:45:53 +08:00
2003-06-29 05:27:08 +08:00
ofs = 0 ;
2007-10-06 05:23:56 +08:00
for ( i = start ; i < argc ; i + + ) {
2003-02-12 08:45:53 +08:00
/* set specified type */
2004-02-11 15:38:43 +08:00
switch ( types [ ofs ] ) {
case ' d ' : /* Double */
2003-02-12 08:45:53 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_DOUBLE ;
2007-10-06 05:23:56 +08:00
bind [ ofs ] . buffer = & Z_DVAL_PP ( args [ i ] ) ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > param . is_null [ ofs ] ;
2003-02-12 08:45:53 +08:00
break ;
2004-02-11 15:38:43 +08:00
case ' i ' : /* Integer */
2007-10-29 17:51:08 +08:00
# if SIZEOF_LONG==8
bind [ ofs ] . buffer_type = MYSQL_TYPE_LONGLONG ;
# elif SIZEOF_LONG==4
bind [ ofs ] . buffer_type = MYSQL_TYPE_LONG ;
# endif
2007-10-06 05:23:56 +08:00
bind [ ofs ] . buffer = & Z_LVAL_PP ( args [ i ] ) ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > param . is_null [ ofs ] ;
2003-02-12 08:45:53 +08:00
break ;
2004-02-11 15:38:43 +08:00
case ' b ' : /* Blob (send data) */
2005-01-07 22:59:59 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_LONG_BLOB ;
2006-05-08 23:06:51 +08:00
/* don't initialize is_null and length to 0 because we use ecalloc */
2003-02-12 08:45:53 +08:00
break ;
2004-02-11 15:38:43 +08:00
case ' s ' : /* string */
2003-02-12 08:45:53 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_VAR_STRING ;
2006-05-08 23:06:51 +08:00
/* don't initialize buffer and buffer_length because we use ecalloc */
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > param . is_null [ ofs ] ;
2003-02-12 08:45:53 +08:00
break ;
default :
2004-02-11 15:38:43 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Undefined fieldtype %c (parameter %d) " , types [ ofs ] , i + 1 ) ;
2007-10-06 05:23:56 +08:00
rc = 1 ;
goto end_1 ;
2003-02-12 08:45:53 +08:00
}
2003-06-29 05:27:08 +08:00
ofs + + ;
2003-02-12 08:45:53 +08:00
}
2004-03-09 20:01:23 +08:00
rc = mysql_stmt_bind_param ( stmt - > stmt , bind ) ;
2003-03-09 07:33:12 +08:00
2007-10-06 05:23:56 +08:00
end_1 :
2003-03-09 07:33:12 +08:00
if ( rc ) {
2007-10-06 05:23:56 +08:00
efree ( stmt - > param . is_null ) ;
} else {
stmt - > param . var_cnt = num_vars ;
stmt - > param . vars = ( zval * * ) safe_emalloc ( num_vars , sizeof ( zval ) , 0 ) ;
for ( i = 0 ; i < num_vars ; i + + ) {
if ( bind [ i ] . buffer_type ! = MYSQL_TYPE_LONG_BLOB ) {
2007-10-07 16:30:47 +08:00
Z_ADDREF_P ( * args [ i + start ] ) ;
2007-10-06 05:23:56 +08:00
stmt - > param . vars [ i ] = * args [ i + start ] ;
} else {
stmt - > param . vars [ i ] = NULL ;
}
}
2003-02-12 08:45:53 +08:00
}
2007-10-06 05:23:56 +08:00
efree ( bind ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
return rc ;
}
# else
static
int mysqli_stmt_bind_param_do_bind ( MY_STMT * stmt , unsigned int argc , unsigned int num_vars ,
zval * * * args , unsigned int start , const char * const types TSRMLS_DC )
{
2009-05-20 16:30:12 +08:00
unsigned int i ;
2007-10-06 05:23:56 +08:00
MYSQLND_PARAM_BIND * params ;
enum_func_status ret = FAIL ;
/* If no params -> skip binding and return directly */
if ( argc = = start ) {
return PASS ;
}
2010-03-12 21:03:46 +08:00
params = mysqlnd_stmt_alloc_param_bind ( stmt - > stmt ) ;
2007-10-06 05:23:56 +08:00
for ( i = 0 ; i < ( argc - start ) ; i + + ) {
zend_uchar type ;
switch ( types [ i ] ) {
case ' d ' : /* Double */
type = MYSQL_TYPE_DOUBLE ;
break ;
case ' i ' : /* Integer */
# if SIZEOF_LONG==8
type = MYSQL_TYPE_LONGLONG ;
# elif SIZEOF_LONG==4
type = MYSQL_TYPE_LONG ;
# endif
break ;
case ' b ' : /* Blob (send data) */
type = MYSQL_TYPE_LONG_BLOB ;
break ;
case ' s ' : /* string */
type = MYSQL_TYPE_VAR_STRING ;
break ;
default :
/* We count parameters from 1 */
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Undefined fieldtype %c (parameter %d) " , types [ i ] , i + start + 1 ) ;
ret = FAIL ;
2010-03-12 21:03:46 +08:00
mysqlnd_stmt_free_param_bind ( stmt - > stmt , params ) ;
2007-10-06 05:23:56 +08:00
goto end ;
2003-02-15 00:49:09 +08:00
}
2007-10-06 05:23:56 +08:00
params [ i ] . zv = * ( args [ i + start ] ) ;
params [ i ] . type = type ;
2003-02-12 08:45:53 +08:00
}
2007-10-06 05:23:56 +08:00
ret = mysqlnd_stmt_bind_param ( stmt - > stmt , params ) ;
2006-05-08 23:06:51 +08:00
end :
2007-10-06 05:23:56 +08:00
return ret ;
2003-02-12 08:45:53 +08:00
}
2007-10-06 05:23:56 +08:00
# endif
2003-02-12 08:45:53 +08:00
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....]) U
Bind variables to a prepared statement as parameters */
PHP_FUNCTION ( mysqli_stmt_bind_param )
2003-02-12 08:45:53 +08:00
{
2007-10-06 05:23:56 +08:00
zval * * * args ;
int argc = ZEND_NUM_ARGS ( ) ;
int num_vars ;
int start = 2 ;
MY_STMT * stmt ;
zval * mysql_stmt ;
char * types ;
int types_len ;
unsigned long rc ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
/* calculate and check number of parameters */
if ( argc < 2 ) {
/* there has to be at least one pair */
WRONG_PARAM_COUNT ;
2004-11-01 15:19:26 +08:00
}
2007-10-06 05:23:56 +08:00
if ( zend_parse_method_parameters ( ( getThis ( ) ) ? 1 : 2 TSRMLS_CC , getThis ( ) , " Os " , & mysql_stmt , mysqli_stmt_class_entry ,
& types , & types_len ) = = FAILURE ) {
2004-11-01 15:19:26 +08:00
return ;
}
2007-10-06 05:23:56 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-11-01 15:19:26 +08:00
2007-10-06 05:23:56 +08:00
num_vars = argc - 1 ;
if ( getThis ( ) ) {
start = 1 ;
} else {
/* ignore handle parameter in procedural interface*/
- - num_vars ;
}
if ( ! types_len ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid type or no types specified " ) ;
RETURN_FALSE ;
}
if ( types_len ! = argc - start ) {
/* number of bind variables doesn't match number of elements in type definition string */
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Number of elements in type definition string doesn't match number of bind variables " ) ;
RETURN_FALSE ;
}
if ( types_len ! = mysql_stmt_param_count ( stmt - > stmt ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Number of variables doesn't match number of parameters in prepared statement " ) ;
RETURN_FALSE ;
2003-02-12 08:45:53 +08:00
}
2003-06-29 05:27:08 +08:00
2003-08-12 08:58:52 +08:00
args = ( zval * * * ) safe_emalloc ( argc , sizeof ( zval * * ) , 0 ) ;
2003-02-12 08:45:53 +08:00
if ( zend_get_parameters_array_ex ( argc , args ) = = FAILURE ) {
2007-10-06 05:23:56 +08:00
zend_wrong_param_count ( TSRMLS_C ) ;
rc = 1 ;
} else {
rc = mysqli_stmt_bind_param_do_bind ( stmt , argc , num_vars , args , start , types TSRMLS_CC ) ;
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
2003-02-12 08:45:53 +08:00
}
2007-10-06 05:23:56 +08:00
efree ( args ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
RETURN_BOOL ( ! rc ) ;
}
/* }}} */
/* {{{ mysqli_stmt_bind_result_do_bind */
2008-03-11 04:15:38 +08:00
# ifndef MYSQLI_USE_MYSQLND
2007-10-06 05:23:56 +08:00
/* TODO:
do_alloca , free_alloca
*/
static int
mysqli_stmt_bind_result_do_bind ( MY_STMT * stmt , zval * * * args , unsigned int argc , unsigned int start TSRMLS_DC )
{
MYSQL_BIND * bind ;
int i , ofs ;
int var_cnt = argc - start ;
long col_type ;
ulong rc ;
2004-02-16 04:23:05 +08:00
2003-02-12 08:45:53 +08:00
/* prevent leak if variables are already bound */
2003-07-15 18:37:19 +08:00
if ( stmt - > result . var_cnt ) {
php_free_stmt_bind_buffer ( stmt - > result , FETCH_RESULT ) ;
2003-02-12 08:45:53 +08:00
}
bind = ( MYSQL_BIND * ) ecalloc ( var_cnt , sizeof ( MYSQL_BIND ) ) ;
2006-05-10 19:53:13 +08:00
{
int size ;
char * p = emalloc ( size = var_cnt * ( sizeof ( char ) + sizeof ( VAR_BUFFER ) ) ) ;
stmt - > result . buf = ( VAR_BUFFER * ) p ;
stmt - > result . is_null = p + var_cnt * sizeof ( VAR_BUFFER ) ;
memset ( p , 0 , size ) ;
}
2003-02-12 08:45:53 +08:00
for ( i = start ; i < var_cnt + start ; i + + ) {
ofs = i - start ;
col_type = ( stmt - > stmt - > fields ) ? stmt - > stmt - > fields [ ofs ] . type : MYSQL_TYPE_STRING ;
switch ( col_type ) {
case MYSQL_TYPE_DOUBLE :
case MYSQL_TYPE_FLOAT :
convert_to_double_ex ( args [ i ] ) ;
2003-07-15 18:37:19 +08:00
stmt - > result . buf [ ofs ] . type = IS_DOUBLE ;
2004-03-09 20:01:23 +08:00
stmt - > result . buf [ ofs ] . buflen = sizeof ( double ) ;
2007-10-06 05:23:56 +08:00
2004-03-09 20:01:23 +08:00
/* allocate buffer for double */
stmt - > result . buf [ ofs ] . val = ( char * ) emalloc ( sizeof ( double ) ) ;
2003-02-12 08:45:53 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_DOUBLE ;
2004-03-09 20:01:23 +08:00
bind [ ofs ] . buffer = stmt - > result . buf [ ofs ] . val ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > result . is_null [ ofs ] ;
2003-02-12 08:45:53 +08:00
break ;
2005-05-05 21:02:32 +08:00
case MYSQL_TYPE_NULL :
2006-05-08 23:06:51 +08:00
stmt - > result . buf [ ofs ] . type = IS_NULL ;
/*
don ' t initialize to 0 :
1. stmt - > result . buf [ ofs ] . buflen
2. bind [ ofs ] . buffer
3. bind [ ofs ] . buffer_length
because memory was allocated with ecalloc
*/
2005-05-05 21:02:32 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_NULL ;
bind [ ofs ] . is_null = & stmt - > result . is_null [ ofs ] ;
2005-12-24 06:22:42 +08:00
break ;
2005-05-05 21:02:32 +08:00
2003-02-12 08:45:53 +08:00
case MYSQL_TYPE_SHORT :
case MYSQL_TYPE_TINY :
case MYSQL_TYPE_LONG :
case MYSQL_TYPE_INT24 :
case MYSQL_TYPE_YEAR :
convert_to_long_ex ( args [ i ] ) ;
2003-07-15 18:37:19 +08:00
stmt - > result . buf [ ofs ] . type = IS_LONG ;
2006-05-08 23:06:51 +08:00
/* don't set stmt->result.buf[ofs].buflen to 0, we used ecalloc */
2006-03-14 23:53:16 +08:00
stmt - > result . buf [ ofs ] . val = ( char * ) emalloc ( sizeof ( int ) ) ;
2003-02-12 08:45:53 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_LONG ;
2004-03-09 20:01:23 +08:00
bind [ ofs ] . buffer = stmt - > result . buf [ ofs ] . val ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > result . is_null [ ofs ] ;
2005-12-29 17:49:19 +08:00
bind [ ofs ] . is_unsigned = ( stmt - > stmt - > fields [ ofs ] . flags & UNSIGNED_FLAG ) ? 1 : 0 ;
2003-02-12 08:45:53 +08:00
break ;
case MYSQL_TYPE_LONGLONG :
2008-03-11 04:15:38 +08:00
# if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
2006-08-05 06:13:59 +08:00
case MYSQL_TYPE_BIT :
# endif
2003-07-15 18:37:19 +08:00
stmt - > result . buf [ ofs ] . type = IS_STRING ;
stmt - > result . buf [ ofs ] . buflen = sizeof ( my_ulonglong ) ;
2004-03-09 20:01:23 +08:00
stmt - > result . buf [ ofs ] . val = ( char * ) emalloc ( stmt - > result . buf [ ofs ] . buflen ) ;
2006-08-05 06:13:59 +08:00
bind [ ofs ] . buffer_type = col_type ;
2004-03-09 20:01:23 +08:00
bind [ ofs ] . buffer = stmt - > result . buf [ ofs ] . val ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > result . is_null [ ofs ] ;
bind [ ofs ] . buffer_length = stmt - > result . buf [ ofs ] . buflen ;
2005-12-29 17:49:19 +08:00
bind [ ofs ] . is_unsigned = ( stmt - > stmt - > fields [ ofs ] . flags & UNSIGNED_FLAG ) ? 1 : 0 ;
2009-09-22 21:59:29 +08:00
bind [ ofs ] . length = & stmt - > result . buf [ ofs ] . output_len ;
2003-02-12 08:45:53 +08:00
break ;
2003-07-15 18:37:19 +08:00
2003-02-12 08:45:53 +08:00
case MYSQL_TYPE_DATE :
case MYSQL_TYPE_TIME :
case MYSQL_TYPE_DATETIME :
case MYSQL_TYPE_NEWDATE :
case MYSQL_TYPE_VAR_STRING :
case MYSQL_TYPE_STRING :
2007-09-05 20:36:44 +08:00
case MYSQL_TYPE_TINY_BLOB :
2007-10-06 05:23:56 +08:00
case MYSQL_TYPE_BLOB :
2007-09-05 20:36:44 +08:00
case MYSQL_TYPE_MEDIUM_BLOB :
case MYSQL_TYPE_LONG_BLOB :
2003-02-12 08:45:53 +08:00
case MYSQL_TYPE_TIMESTAMP :
2004-01-31 15:51:03 +08:00
case MYSQL_TYPE_DECIMAL :
2009-09-11 21:38:47 +08:00
case MYSQL_TYPE_GEOMETRY :
2005-04-19 20:59:16 +08:00
# ifdef FIELD_TYPE_NEWDECIMAL
case MYSQL_TYPE_NEWDECIMAL :
# endif
2005-12-23 02:11:39 +08:00
{
2006-03-24 17:32:24 +08:00
# if MYSQL_VERSION_ID > 50099
2006-03-11 19:16:03 +08:00
/* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
my_bool tmp ;
# else
2006-03-24 17:32:24 +08:00
ulong tmp = 0 ;
2006-03-11 19:16:03 +08:00
# endif
2005-04-28 01:53:15 +08:00
stmt - > result . buf [ ofs ] . type = IS_STRING ;
/*
If the user has called $ stmt - > store_result ( ) then we have asked
max_length to be updated . this is done only for BLOBS because we don ' t want to allocate
big chunkgs of memory 2 ^ 16 or 2 ^ 24
*/
2005-12-23 02:11:39 +08:00
if ( stmt - > stmt - > fields [ ofs ] . max_length = = 0 & &
! mysql_stmt_attr_get ( stmt - > stmt , STMT_ATTR_UPDATE_MAX_LENGTH , & tmp ) & & ! tmp )
{
2008-07-25 20:46:03 +08:00
/*
Allocate directly 256 because it ' s easier to allocate a bit more
than update max length even for text columns . Try SELECT UNION SELECT UNION with
different lengths and you will see that we get different lengths in stmt - > stmt - > fields [ ofs ] . length
The just take 256 and saves us from realloc - ing .
*/
2009-09-11 20:28:47 +08:00
stmt - > result . buf [ ofs ] . buflen =
( stmt - > stmt - > fields ) ? ( stmt - > stmt - > fields [ ofs ] . length ) ? stmt - > stmt - > fields [ ofs ] . length + 1 : 256 : 256 ;
2005-04-28 01:53:15 +08:00
} else {
/*
the user has called store_result ( ) . if he does not there is no way to determine the
2005-12-23 02:11:39 +08:00
libmysql does not allow us to allocate 0 bytes for a buffer so we try 1
2005-04-28 01:53:15 +08:00
*/
2005-12-23 02:11:39 +08:00
if ( ! ( stmt - > result . buf [ ofs ] . buflen = stmt - > stmt - > fields [ ofs ] . max_length ) )
+ + stmt - > result . buf [ ofs ] . buflen ;
2005-04-28 01:53:15 +08:00
}
2004-03-09 20:01:23 +08:00
stmt - > result . buf [ ofs ] . val = ( char * ) emalloc ( stmt - > result . buf [ ofs ] . buflen ) ;
2003-02-12 08:45:53 +08:00
bind [ ofs ] . buffer_type = MYSQL_TYPE_STRING ;
2004-03-09 20:01:23 +08:00
bind [ ofs ] . buffer = stmt - > result . buf [ ofs ] . val ;
2003-07-15 18:37:19 +08:00
bind [ ofs ] . is_null = & stmt - > result . is_null [ ofs ] ;
bind [ ofs ] . buffer_length = stmt - > result . buf [ ofs ] . buflen ;
2009-09-11 20:16:56 +08:00
bind [ ofs ] . length = & stmt - > result . buf [ ofs ] . output_len ;
2003-02-12 08:45:53 +08:00
break ;
2005-12-23 02:11:39 +08:00
}
2005-11-30 23:26:41 +08:00
default :
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Server returned unknown type %ld. Probably your client library is incompatible with the server version you use! " , col_type ) ;
break ;
2003-02-12 08:45:53 +08:00
}
}
2004-03-09 20:01:23 +08:00
rc = mysql_stmt_bind_result ( stmt - > stmt , bind ) ;
2003-12-13 08:28:21 +08:00
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
2003-03-09 07:33:12 +08:00
if ( rc ) {
2005-11-30 23:26:41 +08:00
/* dont close the statement or subsequent usage (for example ->execute()) will lead to crash */
for ( i = 0 ; i < var_cnt ; i + + ) {
2006-05-08 23:06:51 +08:00
if ( stmt - > result . buf [ i ] . val ) {
2005-11-30 23:26:41 +08:00
efree ( stmt - > result . buf [ i ] . val ) ;
2006-05-08 23:06:51 +08:00
}
2005-11-30 23:26:41 +08:00
}
2006-05-10 19:53:13 +08:00
/* Don't free stmt->result.is_null because is_null & buf are one block of memory */
2005-11-30 23:26:41 +08:00
efree ( stmt - > result . buf ) ;
2006-05-08 23:06:51 +08:00
} else {
stmt - > result . var_cnt = var_cnt ;
stmt - > result . vars = ( zval * * ) safe_emalloc ( ( var_cnt ) , sizeof ( zval ) , 0 ) ;
for ( i = start ; i < var_cnt + start ; i + + ) {
ofs = i - start ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_PP ( args [ i ] ) ;
2006-05-08 23:06:51 +08:00
stmt - > result . vars [ ofs ] = * args [ i ] ;
}
2003-02-12 08:45:53 +08:00
}
efree ( bind ) ;
2007-10-06 05:23:56 +08:00
return rc ;
}
# else
static int
mysqli_stmt_bind_result_do_bind ( MY_STMT * stmt , zval * * * args , unsigned int argc , unsigned int start TSRMLS_DC )
{
unsigned int i ;
2010-03-12 21:03:46 +08:00
MYSQLND_RESULT_BIND * params = mysqlnd_stmt_alloc_result_bind ( stmt - > stmt ) ;
2007-10-06 05:23:56 +08:00
for ( i = 0 ; i < ( argc - start ) ; i + + ) {
params [ i ] . zv = * ( args [ i + start ] ) ;
}
return mysqlnd_stmt_bind_result ( stmt - > stmt , params ) ;
}
# endif
/* }}} */
/* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...]) U
Bind variables to a prepared statement for result storage */
PHP_FUNCTION ( mysqli_stmt_bind_result )
{
zval * * * args ;
int argc = ZEND_NUM_ARGS ( ) ;
int start = 1 ;
ulong rc ;
MY_STMT * stmt ;
zval * mysql_stmt ;
if ( getThis ( ) ) {
start = 0 ;
}
if ( zend_parse_method_parameters ( ( getThis ( ) ) ? 0 : 1 TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
if ( argc < ( getThis ( ) ? 1 : 2 ) ) {
WRONG_PARAM_COUNT ;
}
if ( ( argc - start ) ! = mysql_stmt_field_count ( stmt - > stmt ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Number of bind variables doesn't match number of fields in prepared statement " ) ;
RETURN_FALSE ;
}
args = ( zval * * * ) safe_emalloc ( argc , sizeof ( zval * * ) , 0 ) ;
if ( zend_get_parameters_array_ex ( argc , args ) = = FAILURE ) {
efree ( args ) ;
WRONG_PARAM_COUNT ;
}
rc = mysqli_stmt_bind_result_do_bind ( stmt , args , argc , start TSRMLS_CC ) ;
efree ( args ) ;
RETURN_BOOL ( ! rc ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_change_user(object link, string user, string password, string database)
2003-05-04 11:15:02 +08:00
Change logged - in user of the active connection */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_change_user )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link = NULL ;
char * user , * password , * dbname ;
int user_len , password_len , dbname_len ;
2003-03-09 07:33:12 +08:00
ulong rc ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Osss " , & mysql_link , mysqli_link_class_entry , & user , & user_len , & password , & password_len , & dbname , & dbname_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
rc = mysql_change_user ( mysql - > mysql , user , password , dbname ) ;
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
2003-03-09 07:33:12 +08:00
if ( rc ) {
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_character_set_name(object link)
2003-05-04 11:15:02 +08:00
Returns the name of the character set used for this connection */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_character_set_name )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-03-09 07:33:12 +08:00
2007-10-06 05:23:56 +08:00
RETURN_STRING ( ( char * ) mysql_character_set_name ( mysql - > mysql ) , 1 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-02-18 08:00:51 +08:00
2009-10-15 23:49:40 +08:00
/* {{{ php_mysqli_close */
void php_mysqli_close ( MY_MYSQL * mysql , int close_type TSRMLS_DC )
{
2007-10-06 05:23:56 +08:00
if ( ! mysql - > persistent ) {
2009-10-15 23:49:40 +08:00
mysqli_close ( mysql - > mysql , close_type ) ;
2007-10-06 05:23:56 +08:00
} else {
zend_rsrc_list_entry * le ;
if ( zend_hash_find ( & EG ( persistent_list ) , mysql - > hash_key , strlen ( mysql - > hash_key ) + 1 , ( void * * ) & le ) = = SUCCESS ) {
if ( Z_TYPE_P ( le ) = = php_le_pmysqli ( ) ) {
mysqli_plist_entry * plist = ( mysqli_plist_entry * ) le - > ptr ;
2007-11-09 18:56:28 +08:00
zend_ptr_stack_push ( & plist - > free_links , mysql - > mysql ) ;
2007-10-06 05:23:56 +08:00
MyG ( num_links ) - - ;
MyG ( num_active_persistent ) - - ;
MyG ( num_inactive_persistent ) + + ;
}
}
2009-10-15 23:49:40 +08:00
mysql - > persistent = FALSE ;
2007-10-06 05:23:56 +08:00
}
2009-10-15 23:49:40 +08:00
mysql - > mysql = NULL ;
2007-10-06 05:23:56 +08:00
2005-05-05 21:02:32 +08:00
php_clear_mysql ( mysql ) ;
2009-10-15 23:49:40 +08:00
}
/* }}} */
/* {{{ proto bool mysqli_close(object link)
Close connection */
PHP_FUNCTION ( mysqli_close )
{
zval * mysql_link ;
MY_MYSQL * mysql ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_INITIALIZED ) ;
php_mysqli_close ( mysql , MYSQLI_CLOSE_EXPLICIT TSRMLS_CC ) ;
2007-10-06 05:23:56 +08:00
MYSQLI_CLEAR_RESOURCE ( & mysql_link ) ;
2005-05-05 21:02:32 +08:00
efree ( mysql ) ;
2003-02-12 08:45:53 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_commit(object link)
2003-05-04 11:15:02 +08:00
Commit outstanding actions and close transaction */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_commit )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2005-01-27 18:18:28 +08:00
if ( mysql_commit ( mysql - > mysql ) ) {
RETURN_FALSE ;
}
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2004-01-27 21:56:03 +08:00
/* {{{ proto bool mysqli_data_seek(object result, int offset)
2003-03-16 06:51:49 +08:00
Move internal result pointer */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_data_seek )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
2007-10-06 05:23:56 +08:00
zval * mysql_result ;
long offset ;
2003-02-12 08:45:53 +08:00
2003-07-15 22:00:19 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_result , mysqli_result_class_entry , & offset ) = = FAILURE ) {
2003-02-12 08:45:53 +08:00
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
if ( mysqli_result_is_unbuffered ( result ) ) {
2003-02-15 00:49:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Function cannot be used with MYSQL_USE_RESULT " ) ;
2004-01-27 21:56:03 +08:00
RETURN_FALSE ;
}
2007-10-06 05:23:56 +08:00
if ( offset < 0 | | offset > = mysql_num_rows ( result ) ) {
RETURN_FALSE ;
2003-02-12 08:45:53 +08:00
}
2003-02-15 00:49:09 +08:00
mysql_data_seek ( result , offset ) ;
2004-01-27 21:56:03 +08:00
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto void mysqli_debug(string debug) U
2003-02-12 08:45:53 +08:00
*/
PHP_FUNCTION ( mysqli_debug )
{
2007-10-06 05:23:56 +08:00
char * debug ;
int debug_len ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & debug , & debug_len ) = = FAILURE ) {
return ;
}
mysql_debug ( debug ) ;
2003-02-15 04:14:44 +08:00
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_dump_debug_info(object link)
2003-02-12 08:45:53 +08:00
*/
PHP_FUNCTION ( mysqli_dump_debug_info )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-03-09 07:33:12 +08:00
2007-10-06 05:23:56 +08:00
RETURN_BOOL ( ! mysql_dump_debug_info ( mysql - > mysql ) )
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_errno(object link)
2003-03-16 06:51:49 +08:00
Returns the numerical value of the error message from previous MySQL operation */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_errno )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
RETURN_LONG ( mysql_errno ( mysql - > mysql ) ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_error(object link)
2003-03-16 06:51:49 +08:00
Returns the text of the error message from previous MySQL operation */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_error )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
RETURN_STRING ( ( char * ) mysql_error ( mysql - > mysql ) , 1 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2008-03-20 22:03:30 +08:00
# ifndef MYSQLI_USE_MYSQLND
/* {{{ php_mysqli_stmt_copy_it */
static void
php_mysqli_stmt_copy_it ( zval * * * copies , zval * original , uint param_count , uint current )
{
if ( ! * copies ) {
* copies = ecalloc ( param_count , sizeof ( zval * ) ) ;
}
MAKE_STD_ZVAL ( ( * copies ) [ current ] ) ;
* ( * copies ) [ current ] = * original ;
Z_SET_REFCOUNT_P ( ( * copies ) [ current ] , 1 ) ;
zval_copy_ctor ( ( * copies ) [ current ] ) ;
}
/* }}} */
# endif
2004-03-09 20:01:23 +08:00
/* {{{ proto bool mysqli_stmt_execute(object stmt)
2003-05-04 11:15:02 +08:00
Execute a prepared statement */
2004-03-09 20:01:23 +08:00
PHP_FUNCTION ( mysqli_stmt_execute )
2003-02-12 08:45:53 +08:00
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2008-03-11 04:15:38 +08:00
# ifndef MYSQLI_USE_MYSQLND
2007-10-06 05:23:56 +08:00
unsigned int i ;
2008-03-20 22:03:30 +08:00
zval * * copies = NULL ;
2007-10-06 05:23:56 +08:00
# endif
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
2008-03-11 04:15:38 +08:00
# ifndef MYSQLI_USE_MYSQLND
2008-03-20 22:03:30 +08:00
if ( stmt - > param . var_cnt ) {
int j ;
for ( i = 0 ; i < stmt - > param . var_cnt ; i + + ) {
for ( j = i + 1 ; j < stmt - > param . var_cnt ; j + + ) {
/* Oops, someone binding the same variable - clone */
2009-09-18 22:33:08 +08:00
if ( stmt - > param . vars [ j ] = = stmt - > param . vars [ i ] & & stmt - > param . vars [ i ] ) {
2008-03-20 22:03:30 +08:00
php_mysqli_stmt_copy_it ( & copies , stmt - > param . vars [ i ] , stmt - > param . var_cnt , i ) ;
break ;
}
}
}
}
2007-10-06 05:23:56 +08:00
for ( i = 0 ; i < stmt - > param . var_cnt ; i + + ) {
2003-07-15 18:37:19 +08:00
if ( stmt - > param . vars [ i ] ) {
2004-12-21 00:39:14 +08:00
if ( ! ( stmt - > param . is_null [ i ] = ( stmt - > param . vars [ i ] - > type = = IS_NULL ) ) ) {
2008-03-20 22:03:30 +08:00
zval * the_var = copies & & copies [ i ] ? copies [ i ] : stmt - > param . vars [ i ] ;
2004-12-21 00:39:14 +08:00
switch ( stmt - > stmt - > params [ i ] . buffer_type ) {
case MYSQL_TYPE_VAR_STRING :
2008-03-20 22:03:30 +08:00
if ( the_var = = stmt - > param . vars [ i ] & & Z_TYPE_P ( stmt - > param . vars [ i ] ) ! = IS_STRING ) {
php_mysqli_stmt_copy_it ( & copies , stmt - > param . vars [ i ] , stmt - > param . var_cnt , i ) ;
the_var = copies [ i ] ;
}
convert_to_string_ex ( & the_var ) ;
stmt - > stmt - > params [ i ] . buffer = Z_STRVAL_P ( the_var ) ;
stmt - > stmt - > params [ i ] . buffer_length = Z_STRLEN_P ( the_var ) ;
2004-12-21 00:39:14 +08:00
break ;
case MYSQL_TYPE_DOUBLE :
2008-03-20 22:03:30 +08:00
if ( the_var = = stmt - > param . vars [ i ] & & Z_TYPE_P ( stmt - > param . vars [ i ] ) ! = IS_DOUBLE ) {
php_mysqli_stmt_copy_it ( & copies , stmt - > param . vars [ i ] , stmt - > param . var_cnt , i ) ;
the_var = copies [ i ] ;
}
convert_to_double_ex ( & the_var ) ;
stmt - > stmt - > params [ i ] . buffer = & Z_DVAL_P ( the_var ) ;
2004-12-21 00:39:14 +08:00
break ;
2007-10-29 17:51:08 +08:00
case MYSQL_TYPE_LONGLONG :
2004-12-21 00:39:14 +08:00
case MYSQL_TYPE_LONG :
2008-03-20 22:03:30 +08:00
if ( the_var = = stmt - > param . vars [ i ] & & Z_TYPE_P ( stmt - > param . vars [ i ] ) ! = IS_LONG ) {
php_mysqli_stmt_copy_it ( & copies , stmt - > param . vars [ i ] , stmt - > param . var_cnt , i ) ;
the_var = copies [ i ] ;
}
convert_to_long_ex ( & the_var ) ;
stmt - > stmt - > params [ i ] . buffer = & Z_LVAL_P ( the_var ) ;
2004-12-21 00:39:14 +08:00
break ;
default :
break ;
}
2007-10-06 05:23:56 +08:00
}
2003-02-12 08:45:53 +08:00
}
}
2007-10-06 05:23:56 +08:00
# endif
2004-03-09 20:01:23 +08:00
if ( mysql_stmt_execute ( stmt - > stmt ) ) {
2003-12-13 08:28:21 +08:00
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
2007-10-06 05:23:56 +08:00
RETVAL_FALSE ;
} else {
RETVAL_TRUE ;
2003-10-30 20:35:16 +08:00
}
2005-01-07 22:59:59 +08:00
2008-03-20 22:03:30 +08:00
# ifndef MYSQLI_USE_MYSQLND
if ( copies ) {
for ( i = 0 ; i < stmt - > param . var_cnt ; i + + ) {
if ( copies [ i ] ) {
zval_ptr_dtor ( & copies [ i ] ) ;
}
}
efree ( copies ) ;
}
# endif
2003-12-16 16:18:31 +08:00
if ( MyG ( report_mode ) & MYSQLI_REPORT_INDEX ) {
2007-10-06 05:23:56 +08:00
php_mysqli_report_index ( stmt - > query , mysqli_stmt_server_status ( stmt - > stmt ) TSRMLS_CC ) ;
2003-12-16 16:18:31 +08:00
}
2003-02-12 08:45:53 +08:00
}
/* }}} */
2008-03-11 04:15:38 +08:00
# ifndef MYSQLI_USE_MYSQLND
2007-10-06 05:23:56 +08:00
/* {{{ void mysqli_stmt_fetch_libmysql
2003-05-04 11:15:02 +08:00
Fetch results from a prepared statement into the bound variables */
2007-10-06 05:23:56 +08:00
void mysqli_stmt_fetch_libmysql ( INTERNAL_FUNCTION_PARAMETERS )
2003-02-12 08:45:53 +08:00
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
unsigned int i ;
ulong ret ;
unsigned int uval ;
2004-03-09 20:01:23 +08:00
my_ulonglong llval ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
/* reset buffers */
2003-07-15 18:37:19 +08:00
for ( i = 0 ; i < stmt - > result . var_cnt ; i + + ) {
if ( stmt - > result . buf [ i ] . type = = IS_STRING ) {
2004-03-09 20:01:23 +08:00
memset ( stmt - > result . buf [ i ] . val , 0 , stmt - > result . buf [ i ] . buflen ) ;
2003-02-15 00:49:09 +08:00
}
2003-02-12 08:45:53 +08:00
}
2005-04-20 20:50:13 +08:00
ret = mysql_stmt_fetch ( stmt - > stmt ) ;
# ifdef MYSQL_DATA_TRUNCATED
if ( ! ret | | ret = = MYSQL_DATA_TRUNCATED ) {
# else
2005-04-20 21:24:08 +08:00
if ( ! ret ) {
2005-04-20 20:50:13 +08:00
# endif
2003-07-15 18:37:19 +08:00
for ( i = 0 ; i < stmt - > result . var_cnt ; i + + ) {
2007-10-06 05:23:56 +08:00
/*
QQ : Isn ' t it quite better to call zval_dtor ( ) . What if the user has
assigned a resource , or an array to the bound variable ? We are going
to leak probably . zval_dtor ( ) will handle also Unicode / Non - unicode mode .
*/
2005-12-24 06:22:42 +08:00
/* Even if the string is of length zero there is one byte alloced so efree() in all cases */
if ( Z_TYPE_P ( stmt - > result . vars [ i ] ) = = IS_STRING ) {
2006-01-02 00:55:01 +08:00
efree ( stmt - > result . vars [ i ] - > value . str . val ) ;
2004-03-09 20:01:23 +08:00
}
2003-07-15 18:37:19 +08:00
if ( ! stmt - > result . is_null [ i ] ) {
switch ( stmt - > result . buf [ i ] . type ) {
2003-02-15 02:17:25 +08:00
case IS_LONG :
2006-03-14 23:53:16 +08:00
if ( ( stmt - > stmt - > fields [ i ] . type = = MYSQL_TYPE_LONG )
2007-10-06 05:23:56 +08:00
& & ( stmt - > stmt - > fields [ i ] . flags & UNSIGNED_FLAG ) )
2005-11-08 21:50:50 +08:00
{
/* unsigned int (11) */
2005-12-01 00:20:25 +08:00
uval = * ( unsigned int * ) stmt - > result . buf [ i ] . val ;
2007-10-06 05:23:56 +08:00
# if SIZEOF_LONG==4
2005-12-01 00:20:25 +08:00
if ( uval > INT_MAX ) {
char * tmp , * p ;
int j = 10 ;
tmp = emalloc ( 11 ) ;
p = & tmp [ 9 ] ;
do {
* p - - = ( uval % 10 ) + 48 ;
2007-10-06 05:23:56 +08:00
uval = uval / 10 ;
2005-12-01 00:20:25 +08:00
} while ( - - j > 0 ) ;
tmp [ 10 ] = ' \0 ' ;
2007-10-06 05:23:56 +08:00
/* unsigned int > INT_MAX is 10 digits - ALWAYS */
2005-12-01 00:20:25 +08:00
ZVAL_STRINGL ( stmt - > result . vars [ i ] , tmp , 10 , 0 ) ;
break ;
2005-11-08 21:50:50 +08:00
}
2007-10-06 05:23:56 +08:00
# endif
2005-11-08 21:50:50 +08:00
}
2006-03-14 23:53:16 +08:00
if ( stmt - > stmt - > fields [ i ] . flags & UNSIGNED_FLAG ) {
ZVAL_LONG ( stmt - > result . vars [ i ] , * ( unsigned int * ) stmt - > result . buf [ i ] . val ) ;
} else {
ZVAL_LONG ( stmt - > result . vars [ i ] , * ( int * ) stmt - > result . buf [ i ] . val ) ;
2006-05-08 23:06:51 +08:00
}
2003-02-15 02:17:25 +08:00
break ;
case IS_DOUBLE :
2006-03-27 05:08:41 +08:00
ZVAL_DOUBLE ( stmt - > result . vars [ i ] , * ( double * ) stmt - > result . buf [ i ] . val ) ;
2003-02-15 02:17:25 +08:00
break ;
case IS_STRING :
2009-09-22 21:59:29 +08:00
if ( stmt - > stmt - > bind [ i ] . buffer_type = = MYSQL_TYPE_LONGLONG
# if MYSQL_VERSION_ID > 50002
| | stmt - > stmt - > bind [ i ] . buffer_type = = MYSQL_TYPE_BIT
# endif
) {
2005-12-01 00:20:25 +08:00
my_bool uns = ( stmt - > stmt - > fields [ i ] . flags & UNSIGNED_FLAG ) ? 1 : 0 ;
2009-09-22 21:59:29 +08:00
# if MYSQL_VERSION_ID > 50002
if ( stmt - > stmt - > bind [ i ] . buffer_type = = MYSQL_TYPE_BIT ) {
switch ( stmt - > result . buf [ i ] . output_len ) {
case 8 : llval = ( my_ulonglong ) bit_uint8korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 7 : llval = ( my_ulonglong ) bit_uint7korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 6 : llval = ( my_ulonglong ) bit_uint6korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 5 : llval = ( my_ulonglong ) bit_uint5korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 4 : llval = ( my_ulonglong ) bit_uint4korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 3 : llval = ( my_ulonglong ) bit_uint3korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 2 : llval = ( my_ulonglong ) bit_uint2korr ( stmt - > result . buf [ i ] . val ) ; break ;
case 1 : llval = ( my_ulonglong ) uint1korr ( stmt - > result . buf [ i ] . val ) ; break ;
}
} else
# endif
{
llval = * ( my_ulonglong * ) stmt - > result . buf [ i ] . val ;
}
2007-10-06 05:23:56 +08:00
# if SIZEOF_LONG==8
2005-12-01 00:20:25 +08:00
if ( uns & & llval > 9223372036854775807L ) {
# elif SIZEOF_LONG==4
2005-12-01 22:12:56 +08:00
if ( ( uns & & llval > L64 ( 2147483647 ) ) | |
2007-10-06 05:23:56 +08:00
( ! uns & & ( ( L64 ( 2147483647 ) < ( my_longlong ) llval ) | |
( L64 ( - 2147483648 ) > ( my_longlong ) llval ) ) ) )
2005-12-01 00:20:25 +08:00
{
# endif
char tmp [ 22 ] ;
2003-02-17 01:59:30 +08:00
/* even though lval is declared as unsigned, the value
2006-04-05 20:17:08 +08:00
* may be negative . Therefor we cannot use MYSQLI_LLU_SPEC and must
* use MYSQLI_LL_SPEC .
2003-02-17 01:59:30 +08:00
*/
2007-02-24 10:17:47 +08:00
snprintf ( tmp , sizeof ( tmp ) , ( stmt - > stmt - > fields [ i ] . flags & UNSIGNED_FLAG ) ? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC , llval ) ;
2003-07-15 18:37:19 +08:00
ZVAL_STRING ( stmt - > result . vars [ i ] , tmp , 1 ) ;
2003-02-15 02:17:25 +08:00
} else {
2004-03-09 20:01:23 +08:00
ZVAL_LONG ( stmt - > result . vars [ i ] , llval ) ;
2003-02-15 02:17:25 +08:00
}
2009-09-22 21:59:29 +08:00
} else {
2007-03-09 06:49:53 +08:00
# if defined(MYSQL_DATA_TRUNCATED) && MYSQL_VERSION_ID > 50002
2007-10-06 05:23:56 +08:00
if ( ret = = MYSQL_DATA_TRUNCATED & & * ( stmt - > stmt - > bind [ i ] . error ) ! = 0 ) {
2007-03-09 06:49:53 +08:00
/* result was truncated */
2007-10-06 05:23:56 +08:00
ZVAL_STRINGL ( stmt - > result . vars [ i ] , stmt - > result . buf [ i ] . val ,
stmt - > stmt - > bind [ i ] . buffer_length , 1 ) ;
2007-03-09 06:49:53 +08:00
} else {
# else
{
# endif
2007-10-06 05:23:56 +08:00
ZVAL_STRINGL ( stmt - > result . vars [ i ] , stmt - > result . buf [ i ] . val ,
2009-09-11 20:16:56 +08:00
stmt - > result . buf [ i ] . output_len , 1 ) ;
2007-03-09 06:49:53 +08:00
}
2003-02-15 00:49:09 +08:00
}
2003-02-15 02:17:25 +08:00
break ;
default :
2007-10-06 05:23:56 +08:00
break ;
2003-02-15 02:17:25 +08:00
}
} else {
2005-12-24 06:22:42 +08:00
ZVAL_NULL ( stmt - > result . vars [ i ] ) ;
2003-02-12 08:45:53 +08:00
}
2003-02-15 00:49:09 +08:00
}
2003-12-13 08:28:21 +08:00
} else {
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
2003-02-12 08:45:53 +08:00
}
2004-01-25 20:01:36 +08:00
switch ( ret ) {
case 0 :
2005-12-29 17:49:19 +08:00
# ifdef MYSQL_DATA_TRUNCATED
/* according to SQL standard truncation (e.g. loss of precision is
not an error ) - for detecting possible truncation you have to
check mysqli_stmt_warning
*/
case MYSQL_DATA_TRUNCATED :
# endif
2004-01-25 20:01:36 +08:00
RETURN_TRUE ;
break ;
case 1 :
RETURN_FALSE ;
break ;
default :
2004-02-18 21:26:57 +08:00
RETURN_NULL ( ) ;
2004-01-25 20:01:36 +08:00
break ;
}
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
# else
/* {{{ mixed mysqli_stmt_fetch_mysqlnd */
void mysqli_stmt_fetch_mysqlnd ( INTERNAL_FUNCTION_PARAMETERS )
{
MY_STMT * stmt ;
zval * mysql_stmt ;
zend_bool fetched_anything ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
if ( FAIL = = mysqlnd_stmt_fetch ( stmt - > stmt , & fetched_anything ) ) {
RETURN_BOOL ( FALSE ) ;
} else if ( fetched_anything = = TRUE ) {
RETURN_BOOL ( TRUE ) ;
} else {
RETURN_NULL ( ) ;
}
}
# endif
/* }}} */
/* {{{ proto mixed mysqli_stmt_fetch(object stmt) U
Fetch results from a prepared statement into the bound variables */
PHP_FUNCTION ( mysqli_stmt_fetch )
{
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
mysqli_stmt_fetch_libmysql ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
# else
mysqli_stmt_fetch_mysqlnd ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
# endif
}
/* }}} */
/* {{{ php_add_field_properties */
2008-04-16 20:57:38 +08:00
static void php_add_field_properties ( zval * value , const MYSQL_FIELD * field TSRMLS_DC )
2007-10-06 05:23:56 +08:00
{
add_property_string ( value , " name " , ( field - > name ? field - > name : " " ) , 1 ) ;
add_property_string ( value , " orgname " , ( field - > org_name ? field - > org_name : " " ) , 1 ) ;
add_property_string ( value , " table " , ( field - > table ? field - > table : " " ) , 1 ) ;
add_property_string ( value , " orgtable " , ( field - > org_table ? field - > org_table : " " ) , 1 ) ;
add_property_string ( value , " def " , ( field - > def ? field - > def : " " ) , 1 ) ;
add_property_long ( value , " max_length " , field - > max_length ) ;
add_property_long ( value , " length " , field - > length ) ;
add_property_long ( value , " charsetnr " , field - > charsetnr ) ;
add_property_long ( value , " flags " , field - > flags ) ;
add_property_long ( value , " type " , field - > type ) ;
add_property_long ( value , " decimals " , field - > decimals ) ;
}
/* }}} */
2003-02-12 08:45:53 +08:00
2004-01-26 15:39:57 +08:00
/* {{{ proto mixed mysqli_fetch_field (object result)
2003-03-16 06:51:49 +08:00
Get column information from a result and return as an object */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_fetch_field )
{
2007-10-06 05:23:56 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * field ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
if ( ! ( field = mysql_fetch_field ( result ) ) ) {
RETURN_FALSE ;
}
2003-02-15 00:49:09 +08:00
object_init ( return_value ) ;
2007-10-06 05:23:56 +08:00
php_add_field_properties ( return_value , field TSRMLS_CC ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2004-01-26 15:39:57 +08:00
/* {{{ proto mixed mysqli_fetch_fields (object result)
2003-05-04 11:15:02 +08:00
Return array of objects containing field meta - data */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_fetch_fields )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
2007-10-06 05:23:56 +08:00
zval * mysql_result ;
zval * obj ;
2003-02-12 08:45:53 +08:00
2003-02-15 00:49:09 +08:00
unsigned int i ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2003-02-15 00:49:09 +08:00
array_init ( return_value ) ;
2003-02-12 08:45:53 +08:00
2003-02-15 00:49:09 +08:00
for ( i = 0 ; i < mysql_num_fields ( result ) ; i + + ) {
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * field = mysql_fetch_field_direct ( result , i ) ;
2003-02-12 08:45:53 +08:00
MAKE_STD_ZVAL ( obj ) ;
2003-02-15 00:49:09 +08:00
object_init ( obj ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
php_add_field_properties ( obj , field TSRMLS_CC ) ;
2003-02-12 08:45:53 +08:00
add_index_zval ( return_value , i , obj ) ;
}
}
/* }}} */
2004-01-26 15:39:57 +08:00
/* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset)
2003-05-04 11:15:02 +08:00
Fetch meta - data for a single field */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_fetch_field_direct )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * field ;
2007-10-06 05:23:56 +08:00
long offset ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_result , mysqli_result_class_entry , & offset ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2005-01-27 09:14:43 +08:00
2009-05-20 16:30:12 +08:00
if ( offset < 0 | | offset > = ( long ) mysql_num_fields ( result ) ) {
2005-01-27 09:14:43 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Field offset is invalid for resultset " ) ;
RETURN_FALSE ;
}
2003-02-12 08:45:53 +08:00
if ( ! ( field = mysql_fetch_field_direct ( result , offset ) ) ) {
RETURN_FALSE ;
}
2003-02-15 00:49:09 +08:00
object_init ( return_value ) ;
2007-10-06 05:23:56 +08:00
php_add_field_properties ( return_value , field TSRMLS_CC ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2004-01-26 15:39:57 +08:00
/* {{{ proto mixed mysqli_fetch_lengths (object result)
2003-03-16 06:51:49 +08:00
Get the length of each output in a result */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_fetch_lengths )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
unsigned int i ;
unsigned long * ret ;
2007-10-06 05:23:56 +08:00
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2003-02-15 00:49:09 +08:00
if ( ! ( ret = mysql_fetch_lengths ( result ) ) ) {
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
2003-02-15 00:49:09 +08:00
array_init ( return_value ) ;
2003-02-12 08:45:53 +08:00
2003-02-15 00:49:09 +08:00
for ( i = 0 ; i < mysql_num_fields ( result ) ; i + + ) {
2007-10-06 05:23:56 +08:00
add_index_long ( return_value , i , ret [ i ] ) ;
2003-02-12 08:45:53 +08:00
}
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto array mysqli_fetch_row (object result)
2003-03-16 06:51:49 +08:00
Get a result row as an enumerated array */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_fetch_row )
{
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2003-09-07 03:34:48 +08:00
php_mysqli_fetch_into_hash ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQLI_NUM , 0 ) ;
2007-10-06 05:23:56 +08:00
# else
MYSQL_RES * result ;
zval * mysql_result ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
mysqlnd_fetch_into ( result , MYSQLND_FETCH_NUM , return_value , MYSQLND_MYSQLI ) ;
# endif
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_field_count(object link)
2003-05-04 11:15:02 +08:00
Fetch the number of fields returned by the last query for the given link
2003-02-12 08:45:53 +08:00
*/
2007-10-06 05:23:56 +08:00
PHP_FUNCTION ( mysqli_field_count )
2003-02-12 08:45:53 +08:00
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
RETURN_LONG ( mysql_field_count ( mysql - > mysql ) ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2004-01-25 20:01:36 +08:00
/* {{{ proto int mysqli_field_seek(object result, int fieldnr)
2003-05-04 11:15:02 +08:00
Set result pointer to a specified field offset
*/
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_field_seek )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2005-04-19 20:59:16 +08:00
unsigned long fieldnr ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_result , mysqli_result_class_entry , & fieldnr ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
if ( fieldnr < 0 | | fieldnr > = mysql_num_fields ( result ) ) {
2006-09-29 16:40:10 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid field offset " ) ;
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
2007-10-06 05:23:56 +08:00
2003-02-12 08:45:53 +08:00
mysql_field_seek ( result , fieldnr ) ;
RETURN_TRUE ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_field_tell(object result)
2003-03-16 06:51:49 +08:00
Get current field offset of result pointer */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_field_tell )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
2003-02-12 08:45:53 +08:00
RETURN_LONG ( mysql_field_tell ( result ) ) ;
}
/* }}} */
2004-01-29 06:51:54 +08:00
/* {{{ proto void mysqli_free_result(object result)
2003-05-04 11:15:02 +08:00
Free query result memory for the given result handle */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_free_result )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
mysqli_free_result ( result , FALSE ) ;
MYSQLI_CLEAR_RESOURCE ( & mysql_result ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto string mysqli_get_client_info(void)
2003-03-16 06:51:49 +08:00
Get MySQL client info */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_get_client_info )
{
RETURN_STRING ( ( char * ) mysql_get_client_info ( ) , 1 ) ;
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto int mysqli_get_client_version(void)
2004-01-29 06:51:54 +08:00
Get MySQL client info */
PHP_FUNCTION ( mysqli_get_client_version )
{
RETURN_LONG ( ( long ) mysql_get_client_version ( ) ) ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_get_host_info (object link)
2003-03-16 06:51:49 +08:00
Get MySQL host info */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_get_host_info )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link = NULL ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-07-19 15:19:50 +08:00
RETURN_STRING ( ( mysql - > mysql - > host_info ) ? mysql - > mysql - > host_info : " " , 1 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
/* {{{ proto int mysqli_get_proto_info(object link)
2003-05-04 11:15:02 +08:00
Get MySQL protocol information */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_get_proto_info )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link = NULL ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
RETURN_LONG ( mysql_get_proto_info ( mysql - > mysql ) ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto string mysqli_get_server_info(object link)
2003-03-16 06:51:49 +08:00
Get MySQL server info */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_get_server_info )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link = NULL ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
RETURN_STRING ( ( char * ) mysql_get_server_info ( mysql - > mysql ) , 1 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_get_server_version(object link)
2003-05-04 11:15:02 +08:00
Return the MySQL version for the server referenced by the given link */
2003-02-13 08:11:17 +08:00
PHP_FUNCTION ( mysqli_get_server_version )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link = NULL ;
2003-02-13 08:11:17 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-13 08:11:17 +08:00
2004-06-06 02:31:56 +08:00
RETURN_LONG ( mysql_get_server_version ( mysql - > mysql ) ) ;
2003-02-13 08:11:17 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_info(object link)
2003-03-16 06:51:49 +08:00
Get information about the most recent query */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_info )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link = NULL ;
const char * info ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
info = mysql_info ( mysql - > mysql ) ;
RETURN_STRING ( ( info ) ? ( char * ) info : " " , 1 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2010-01-25 21:23:32 +08:00
/* {{{ php_mysqli_init() */
void php_mysqli_init ( INTERNAL_FUNCTION_PARAMETERS )
2003-02-12 08:45:53 +08:00
{
2004-12-27 23:39:35 +08:00
MYSQLI_RESOURCE * mysqli_resource ;
2008-09-19 19:38:46 +08:00
MY_MYSQL * mysql ;
2009-01-09 22:30:00 +08:00
if ( getThis ( ) & & ( ( mysqli_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ) - > ptr ) {
2008-09-19 19:38:46 +08:00
return ;
}
mysql = ( MY_MYSQL * ) ecalloc ( 1 , sizeof ( MY_MYSQL ) ) ;
2004-06-06 02:31:56 +08:00
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
if ( ! ( mysql - > mysql = mysql_init ( NULL ) ) )
# else
2008-02-06 19:34:44 +08:00
/*
We create always persistent , as if the user want to connecto
to p : somehost , we can ' t convert the handle then
*/
if ( ! ( mysql - > mysql = mysql_init ( TRUE ) ) )
2007-10-06 05:23:56 +08:00
# endif
{
2004-06-06 02:31:56 +08:00
efree ( mysql ) ;
RETURN_FALSE ;
}
2004-12-27 19:48:57 +08:00
2004-12-27 23:39:35 +08:00
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
2004-06-06 02:31:56 +08:00
mysqli_resource - > ptr = ( void * ) mysql ;
2006-03-24 17:32:24 +08:00
mysqli_resource - > status = MYSQLI_STATUS_INITIALIZED ;
2005-06-18 00:32:43 +08:00
2005-10-10 20:57:55 +08:00
if ( ! getThis ( ) | | ! instanceof_function ( Z_OBJCE_P ( getThis ( ) ) , mysqli_link_class_entry TSRMLS_CC ) ) {
2005-06-18 00:32:43 +08:00
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_link_class_entry ) ;
} else {
( ( mysqli_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ) - > ptr = mysqli_resource ;
}
2003-02-12 08:45:53 +08:00
}
/* }}} */
2010-01-25 21:23:32 +08:00
/* {{{ proto resource mysqli_init(void)
Initialize mysqli and return a resource for use with mysql_real_connect */
PHP_FUNCTION ( mysqli_init )
{
php_mysqli_init ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto mixed mysqli_insert_id(object link)
2003-03-16 06:51:49 +08:00
Get the ID generated from the previous INSERT operation */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_insert_id )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
my_ulonglong rc ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
rc = mysql_insert_id ( mysql - > mysql ) ;
2003-02-16 23:56:57 +08:00
MYSQLI_RETURN_LONG_LONG ( rc )
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_kill(object link, int processid)
2003-03-16 06:51:49 +08:00
Kill a mysql process on the server */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_kill )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
long processid ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_link , mysqli_link_class_entry , & processid ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
if ( processid < = 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " processid should have positive value " ) ;
RETURN_FALSE ;
}
2004-06-06 02:31:56 +08:00
if ( mysql_kill ( mysql - > mysql , processid ) ) {
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2006-05-08 23:06:51 +08:00
/* {{{ proto void mysqli_set_local_infile_default(object link)
2004-06-06 02:31:56 +08:00
unsets user defined handler for load local infile command */
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2004-06-06 02:31:56 +08:00
PHP_FUNCTION ( mysqli_set_local_infile_default )
{
MY_MYSQL * mysql ;
zval * mysql_link ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
2004-08-25 21:57:35 +08:00
if ( mysql - > li_read ) {
2007-10-17 16:18:09 +08:00
zval_ptr_dtor ( & ( mysql - > li_read ) ) ;
2004-08-25 21:57:35 +08:00
mysql - > li_read = NULL ;
2004-06-06 02:31:56 +08:00
}
}
/* }}} */
2004-08-25 21:57:35 +08:00
/* {{{ proto bool mysqli_set_local_infile_handler(object link, callback read_func)
2004-06-06 02:31:56 +08:00
Set callback functions for LOAD DATA LOCAL INFILE */
PHP_FUNCTION ( mysqli_set_local_infile_handler )
{
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link ;
2004-06-06 02:31:56 +08:00
char * callback_name ;
2004-08-25 21:57:35 +08:00
zval * callback_func ;
2004-06-06 02:31:56 +08:00
2004-08-25 21:57:35 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Oz " , & mysql_link , mysqli_link_class_entry ,
& callback_func ) = = FAILURE ) {
2004-06-06 02:31:56 +08:00
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
2004-08-25 21:57:35 +08:00
/* check callback function */
2008-08-02 12:46:07 +08:00
if ( ! zend_is_callable ( callback_func , 0 , & callback_name TSRMLS_CC ) ) {
2004-08-25 21:57:35 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Not a valid callback function %s " , callback_name ) ;
2004-06-06 02:31:56 +08:00
efree ( callback_name ) ;
2007-10-06 05:23:56 +08:00
RETURN_FALSE ;
2004-06-06 02:31:56 +08:00
}
2008-07-17 17:53:42 +08:00
efree ( callback_name ) ;
2004-06-06 02:31:56 +08:00
2004-08-25 21:57:35 +08:00
/* save callback function */
2007-10-06 05:23:56 +08:00
if ( ! mysql - > li_read ) {
MAKE_STD_ZVAL ( mysql - > li_read ) ;
} else {
zval_dtor ( mysql - > li_read ) ;
}
2008-07-17 17:53:42 +08:00
ZVAL_ZVAL ( mysql - > li_read , callback_func , 1 , 0 ) ;
2006-05-08 23:06:51 +08:00
RETURN_TRUE ;
2004-06-06 02:31:56 +08:00
}
2007-10-06 05:23:56 +08:00
# endif
2004-06-06 02:31:56 +08:00
/* }}} */
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
/* {{{ proto bool mysqli_more_results(object link)
check if there any more query results from a multi query */
2005-04-19 20:59:16 +08:00
PHP_FUNCTION ( mysqli_more_results )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
2006-05-08 23:06:51 +08:00
RETURN_BOOL ( mysql_more_results ( mysql - > mysql ) ) ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
}
/* }}} */
/* {{{ proto bool mysqli_next_result(object link)
read next result from multi_query */
PHP_FUNCTION ( mysqli_next_result ) {
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
2007-10-06 05:23:56 +08:00
if ( ! mysql_more_results ( mysql - > mysql ) ) {
php_error_docref ( NULL TSRMLS_CC , E_STRICT , " There is no next result set. "
" Please, call mysqli_more_results()/mysqli::more_results() to check "
" whether to call this function/method " ) ;
}
2006-05-08 23:06:51 +08:00
RETURN_BOOL ( ! mysql_next_result ( mysql - > mysql ) ) ;
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
}
/* }}} */
2009-08-04 22:49:33 +08:00
# if defined(HAVE_STMT_NEXT_RESULT) && defined(MYSQLI_USE_MYSQLND)
2008-04-24 22:22:19 +08:00
/* {{{ proto bool mysqli_stmt_next_result(object link)
check if there any more query results from a multi query */
PHP_FUNCTION ( mysqli_stmt_more_results )
{
MY_STMT * stmt ;
zval * mysql_stmt ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2009-08-04 22:49:33 +08:00
RETURN_BOOL ( mysqlnd_stmt_more_results ( stmt - > stmt ) ) ;
2008-04-24 22:22:19 +08:00
}
/* }}} */
/* {{{ proto bool mysqli_stmt_next_result(object link)
read next result from multi_query */
PHP_FUNCTION ( mysqli_stmt_next_result ) {
MY_STMT * stmt ;
zval * mysql_stmt ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2009-08-04 22:49:33 +08:00
if ( ! mysqlnd_stmt_more_results ( stmt - > stmt ) ) {
2008-04-24 22:22:19 +08:00
php_error_docref ( NULL TSRMLS_CC , E_STRICT , " There is no next result set. "
" Please, call mysqli_stmt_more_results()/mysqli_stmt::more_results() to check "
" whether to call this function/method " ) ;
}
2009-08-02 09:07:38 +08:00
RETURN_BOOL ( ! mysql_stmt_next_result ( stmt - > stmt ) ) ;
2008-04-24 22:22:19 +08:00
}
/* }}} */
# endif
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_num_fields(object result)
2003-03-16 06:51:49 +08:00
Get number of fields in result */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_num_fields )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
RETURN_LONG ( mysql_num_fields ( result ) ) ;
}
/* }}} */
2003-12-31 03:19:13 +08:00
/* {{{ proto mixed mysqli_num_rows(object result)
2003-03-16 06:51:49 +08:00
Get number of rows in result */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_num_rows )
{
2003-03-09 07:33:12 +08:00
MYSQL_RES * result ;
zval * mysql_result ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_result , mysqli_result_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( result , MYSQL_RES * , & mysql_result , " mysqli_result " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2007-10-06 05:23:56 +08:00
if ( mysqli_result_is_unbuffered ( result ) ) {
2003-02-15 00:49:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Function cannot be used with MYSQL_USE_RESULT " ) ;
2003-02-12 08:45:53 +08:00
RETURN_LONG ( 0 ) ;
}
2003-12-31 03:19:13 +08:00
MYSQLI_RETURN_LONG_LONG ( mysql_num_rows ( result ) ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2009-11-03 22:56:04 +08:00
/* {{{ mysqli_options_get_option_zval_type */
static int mysqli_options_get_option_zval_type ( int option )
{
switch ( option ) {
# ifdef MYSQLI_USE_MYSQLND
# if PHP_MAJOR_VERSION >= 6
case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE :
# endif
case MYSQLND_OPT_NET_CMD_BUFFER_SIZE :
case MYSQLND_OPT_NET_READ_BUFFER_SIZE :
# ifdef MYSQLND_STRING_TO_INT_CONVERSION
case MYSQLND_OPT_INT_AND_FLOAT_NATIVE :
# endif
# endif /* MYSQLI_USE_MYSQLND */
case MYSQL_OPT_CONNECT_TIMEOUT :
2009-12-02 05:39:19 +08:00
# ifdef MYSQL_REPORT_DATA_TRUNCATION
2009-11-03 22:56:04 +08:00
case MYSQL_REPORT_DATA_TRUNCATION :
2009-12-02 05:39:19 +08:00
# endif
2009-11-03 22:56:04 +08:00
case MYSQL_OPT_LOCAL_INFILE :
case MYSQL_OPT_NAMED_PIPE :
# ifdef MYSQL_OPT_PROTOCOL
case MYSQL_OPT_PROTOCOL :
# endif /* MySQL 4.1.0 */
# ifdef MYSQL_OPT_READ_TIMEOUT
case MYSQL_OPT_READ_TIMEOUT :
case MYSQL_OPT_WRITE_TIMEOUT :
case MYSQL_OPT_GUESS_CONNECTION :
case MYSQL_OPT_USE_EMBEDDED_CONNECTION :
case MYSQL_OPT_USE_REMOTE_CONNECTION :
case MYSQL_SECURE_AUTH :
# endif /* MySQL 4.1.1 */
# ifdef MYSQL_OPT_RECONNECT
case MYSQL_OPT_RECONNECT :
# endif /* MySQL 5.0.13 */
# ifdef MYSQL_OPT_SSL_VERIFY_SERVER_CERT
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT :
# endif /* MySQL 5.0.23 */
# ifdef MYSQL_OPT_COMPRESS
case MYSQL_OPT_COMPRESS :
# endif /* mysqlnd @ PHP 5.3.2 */
return IS_LONG ;
# ifdef MYSQL_SHARED_MEMORY_BASE_NAME
case MYSQL_SHARED_MEMORY_BASE_NAME :
# endif /* MySQL 4.1.0 */
# ifdef MYSQL_SET_CLIENT_IP
case MYSQL_SET_CLIENT_IP :
# endif /* MySQL 4.1.1 */
case MYSQL_READ_DEFAULT_FILE :
case MYSQL_READ_DEFAULT_GROUP :
case MYSQL_INIT_COMMAND :
case MYSQL_SET_CHARSET_NAME :
case MYSQL_SET_CHARSET_DIR :
return IS_STRING ;
default :
return IS_NULL ;
}
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_options(object link, int flags, mixed values)
2003-03-16 06:51:49 +08:00
Set options */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_options )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link = NULL ;
2010-04-21 20:52:24 +08:00
zval * * mysql_value ;
2007-10-06 05:23:56 +08:00
long mysql_option ;
unsigned int l_value ;
long ret ;
2009-11-03 22:56:04 +08:00
int expected_type ;
2003-02-12 08:45:53 +08:00
2010-04-21 20:52:24 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " OlZ " , & mysql_link , mysqli_link_class_entry , & mysql_option , & mysql_value ) = = FAILURE ) {
2003-02-12 08:45:53 +08:00
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_INITIALIZED ) ;
2003-02-12 08:45:53 +08:00
2010-04-27 07:53:30 +08:00
# if PHP_API_VERSION < 20100412
2007-06-19 05:51:32 +08:00
if ( ( PG ( open_basedir ) & & PG ( open_basedir ) [ 0 ] ! = ' \0 ' ) | | PG ( safe_mode ) ) {
2010-04-27 07:53:30 +08:00
# else
if ( PG ( open_basedir ) & & PG ( open_basedir ) [ 0 ] ! = ' \0 ' ) {
# endif
2007-06-19 05:51:32 +08:00
if ( mysql_option = = MYSQL_OPT_LOCAL_INFILE ) {
RETURN_FALSE ;
}
}
2009-11-03 22:56:04 +08:00
expected_type = mysqli_options_get_option_zval_type ( mysql_option ) ;
2010-04-21 20:52:24 +08:00
if ( expected_type ! = Z_TYPE_PP ( mysql_value ) ) {
2009-11-03 22:56:04 +08:00
switch ( expected_type ) {
case IS_STRING :
2010-04-21 20:52:24 +08:00
convert_to_string_ex ( mysql_value ) ;
2009-11-03 22:56:04 +08:00
break ;
case IS_LONG :
2010-04-21 20:52:24 +08:00
convert_to_long_ex ( mysql_value ) ;
2009-11-03 22:56:04 +08:00
break ;
default :
break ;
}
}
switch ( expected_type ) {
2003-02-12 08:45:53 +08:00
case IS_STRING :
2010-04-21 20:52:24 +08:00
ret = mysql_options ( mysql - > mysql , mysql_option , Z_STRVAL_PP ( mysql_value ) ) ;
2003-02-15 00:49:09 +08:00
break ;
2009-11-03 22:56:04 +08:00
case IS_LONG :
2010-04-21 20:52:24 +08:00
l_value = Z_LVAL_PP ( mysql_value ) ;
2004-06-06 02:31:56 +08:00
ret = mysql_options ( mysql - > mysql , mysql_option , ( char * ) & l_value ) ;
2003-02-15 00:49:09 +08:00
break ;
2009-11-03 22:56:04 +08:00
default :
ret = 1 ;
break ;
2003-02-12 08:45:53 +08:00
}
2006-05-08 23:06:51 +08:00
RETURN_BOOL ( ! ret ) ;
2007-10-06 05:23:56 +08:00
}
2003-02-12 08:45:53 +08:00
/* }}} */
2004-02-26 20:24:21 +08:00
/* {{{ proto bool mysqli_ping(object link)
2003-03-16 06:51:49 +08:00
Ping a server connection or reconnect if there is no connection */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_ping )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-12-13 08:28:21 +08:00
long rc ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
rc = mysql_ping ( mysql - > mysql ) ;
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2006-05-08 23:06:51 +08:00
RETURN_BOOL ( ! rc ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2004-01-27 21:23:54 +08:00
/* {{{ proto mixed mysqli_prepare(object link, string query)
2003-03-16 06:51:49 +08:00
Prepare a SQL statement for execution */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_prepare )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
2003-03-09 07:33:12 +08:00
char * query = NULL ;
unsigned int query_len ;
zval * mysql_link ;
2007-10-06 05:23:56 +08:00
MYSQLI_RESOURCE * mysqli_resource ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Os " , & mysql_link , mysqli_link_class_entry , & query , & query_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2005-05-10 05:48:03 +08:00
if ( mysql - > mysql - > status = = MYSQL_STATUS_GET_RESULT ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " All data must be fetched before a new statement prepare takes place " ) ;
RETURN_FALSE ;
}
2007-10-06 05:23:56 +08:00
# endif
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
stmt = ( MY_STMT * ) ecalloc ( 1 , sizeof ( MY_STMT ) ) ;
2003-03-09 07:33:12 +08:00
2004-07-14 01:04:16 +08:00
if ( ( stmt - > stmt = mysql_stmt_init ( mysql - > mysql ) ) ) {
2004-03-09 20:01:23 +08:00
if ( mysql_stmt_prepare ( stmt - > stmt , query , query_len ) ) {
2007-10-06 05:23:56 +08:00
/* mysql_stmt_close() clears errors, so we have to store them temporarily */
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
char last_error [ MYSQL_ERRMSG_SIZE ] ;
char sqlstate [ SQLSTATE_LENGTH + 1 ] ;
2005-05-21 16:38:53 +08:00
unsigned int last_errno ;
last_errno = stmt - > stmt - > last_errno ;
memcpy ( last_error , stmt - > stmt - > last_error , MYSQL_ERRMSG_SIZE ) ;
memcpy ( sqlstate , mysql - > mysql - > net . sqlstate , SQLSTATE_LENGTH + 1 ) ;
2007-10-06 05:23:56 +08:00
# else
2009-12-23 19:58:45 +08:00
MYSQLND_ERROR_INFO error_info = mysql - > mysql - > error_info ;
2007-10-06 05:23:56 +08:00
# endif
mysqli_stmt_close ( stmt - > stmt , FALSE ) ;
2004-03-09 20:01:23 +08:00
stmt - > stmt = NULL ;
2005-05-21 16:38:53 +08:00
/* restore error messages */
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2005-05-21 16:38:53 +08:00
mysql - > mysql - > net . last_errno = last_errno ;
memcpy ( mysql - > mysql - > net . last_error , last_error , MYSQL_ERRMSG_SIZE ) ;
memcpy ( mysql - > mysql - > net . sqlstate , sqlstate , SQLSTATE_LENGTH + 1 ) ;
2007-10-06 05:23:56 +08:00
# else
mysql - > mysql - > error_info = error_info ;
# endif
2004-03-09 20:01:23 +08:00
}
2006-05-08 23:06:51 +08:00
}
2007-10-06 05:23:56 +08:00
/* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */
/* Get performance boost if reporting is switched off */
if ( stmt - > stmt & & query_len & & ( MyG ( report_mode ) & MYSQLI_REPORT_INDEX ) ) {
stmt - > query = ( char * ) emalloc ( query_len + 1 ) ;
memcpy ( stmt - > query , query , query_len ) ;
stmt - > query [ query_len ] = ' \0 ' ;
}
/* don't join to the previous if because it won't work if mysql_stmt_prepare_fails */
2003-02-12 08:45:53 +08:00
if ( ! stmt - > stmt ) {
2004-06-06 02:31:56 +08:00
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2003-02-12 08:45:53 +08:00
efree ( stmt ) ;
RETURN_FALSE ;
}
2003-03-09 07:33:12 +08:00
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
mysqli_resource - > ptr = ( void * ) stmt ;
2006-03-24 17:32:24 +08:00
/* change status */
mysqli_resource - > status = MYSQLI_STATUS_VALID ;
2003-03-09 07:33:12 +08:00
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_stmt_class_entry ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2008-02-06 19:34:44 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]])
2003-05-04 11:15:02 +08:00
Open a connection to a mysql server */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_real_connect )
{
2008-03-08 22:55:52 +08:00
mysqli_common_connect ( INTERNAL_FUNCTION_PARAM_PASSTHRU , TRUE , FALSE ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2008-02-06 19:34:44 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_real_query(object link, string query)
2003-05-04 11:15:02 +08:00
Binary - safe version of mysql_query ( ) */
2003-02-15 02:35:30 +08:00
PHP_FUNCTION ( mysqli_real_query )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2003-03-09 07:33:12 +08:00
zval * mysql_link ;
char * query = NULL ;
2007-10-06 05:23:56 +08:00
unsigned int query_len ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Os " , & mysql_link , mysqli_link_class_entry , & query , & query_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-12-13 08:28:21 +08:00
MYSQLI_DISABLE_MQ ; /* disable multi statements/queries */
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
if ( mysql_real_query ( mysql - > mysql , query , query_len ) ) {
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
2003-12-13 08:28:21 +08:00
}
2004-06-06 02:31:56 +08:00
if ( ! mysql_field_count ( mysql - > mysql ) ) {
2003-12-13 08:28:21 +08:00
if ( MyG ( report_mode ) & MYSQLI_REPORT_INDEX ) {
2007-10-06 05:23:56 +08:00
php_mysqli_report_index ( query , mysqli_server_status ( mysql - > mysql ) TSRMLS_CC ) ;
2003-12-13 08:28:21 +08:00
}
}
2003-02-12 08:45:53 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_real_escape_string(object link, string escapestr)
2003-03-16 06:51:49 +08:00
Escapes special characters in a string for use in a SQL statement , taking into account the current charset of the connection */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_real_escape_string ) {
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2003-03-09 07:33:12 +08:00
zval * mysql_link = NULL ;
char * escapestr , * newstr ;
int escapestr_len , newstr_len ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Os " , & mysql_link , mysqli_link_class_entry , & escapestr , & escapestr_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2003-08-12 08:58:52 +08:00
newstr = safe_emalloc ( 2 , escapestr_len , 1 ) ;
2004-06-06 02:31:56 +08:00
newstr_len = mysql_real_escape_string ( mysql - > mysql , newstr , escapestr , escapestr_len ) ;
2003-02-12 08:45:53 +08:00
newstr = erealloc ( newstr , newstr_len + 1 ) ;
2007-10-06 05:23:56 +08:00
2006-05-08 23:06:51 +08:00
RETURN_STRINGL ( newstr , newstr_len , 0 ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto bool mysqli_rollback(object link)
2003-03-16 06:51:49 +08:00
Undo actions from current transaction */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_rollback )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2005-01-27 18:18:28 +08:00
if ( mysql_rollback ( mysql - > mysql ) ) {
RETURN_FALSE ;
}
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2006-10-02 15:44:34 +08:00
/* {{{ proto bool mysqli_stmt_send_long_data(object stmt, int param_nr, string data)
2003-02-12 08:45:53 +08:00
*/
2004-03-09 20:01:23 +08:00
PHP_FUNCTION ( mysqli_stmt_send_long_data )
2003-02-12 08:45:53 +08:00
{
2004-06-06 02:31:56 +08:00
MY_STMT * stmt ;
2007-10-06 05:23:56 +08:00
zval * mysql_stmt ;
2004-06-06 02:31:56 +08:00
char * data ;
2005-04-19 20:59:16 +08:00
long param_nr ;
int data_len ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ols " , & mysql_stmt , mysqli_stmt_class_entry , & param_nr , & data , & data_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-01-26 15:39:57 +08:00
if ( param_nr < 0 ) {
2003-02-12 08:45:53 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Invalid parameter number " ) ;
RETURN_FALSE ;
}
2004-03-09 20:01:23 +08:00
if ( mysql_stmt_send_long_data ( stmt - > stmt , param_nr , data , data_len ) ) {
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2003-10-30 04:48:47 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
2003-05-04 11:15:02 +08:00
Return the number of rows affected in the last query for the given link */
2003-02-16 20:03:37 +08:00
PHP_FUNCTION ( mysqli_stmt_affected_rows )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2003-03-09 07:33:12 +08:00
my_ulonglong rc ;
2003-02-16 20:03:37 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-02-16 20:03:37 +08:00
rc = mysql_stmt_affected_rows ( stmt - > stmt ) ;
2005-01-29 01:35:37 +08:00
if ( rc = = ( my_ulonglong ) - 1 ) {
RETURN_LONG ( - 1 ) ;
}
2003-02-16 23:56:57 +08:00
MYSQLI_RETURN_LONG_LONG ( rc )
2003-02-16 20:03:37 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto bool mysqli_stmt_close(object stmt)
2003-03-16 06:51:49 +08:00
Close statement */
2003-02-16 20:03:37 +08:00
PHP_FUNCTION ( mysqli_stmt_close )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
mysqli_stmt_close ( stmt - > stmt , FALSE ) ;
2003-02-22 15:31:01 +08:00
stmt - > stmt = NULL ;
2007-10-06 05:23:56 +08:00
php_clear_stmt_bind ( stmt TSRMLS_CC ) ;
2003-02-12 08:45:53 +08:00
MYSQLI_CLEAR_RESOURCE ( & mysql_stmt ) ;
RETURN_TRUE ;
}
/* }}} */
2003-07-15 22:00:19 +08:00
/* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset)
2003-07-28 18:23:36 +08:00
Move internal result pointer */
2003-07-15 22:00:19 +08:00
PHP_FUNCTION ( mysqli_stmt_data_seek )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
long offset ;
2003-07-15 22:00:19 +08:00
2003-07-28 18:23:36 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_stmt , mysqli_stmt_class_entry , & offset ) = = FAILURE ) {
return ;
}
2005-04-19 21:28:41 +08:00
if ( offset < 0 ) {
2005-05-10 06:29:54 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Offset must be positive " ) ;
RETURN_FALSE ;
2005-04-19 21:28:41 +08:00
}
2003-07-15 22:00:19 +08:00
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-07-15 22:00:19 +08:00
2003-08-31 19:03:05 +08:00
mysql_stmt_data_seek ( stmt - > stmt , offset ) ;
2003-07-15 22:00:19 +08:00
}
/* }}} */
2004-07-07 16:02:27 +08:00
/* {{{ proto int mysqli_stmt_field_count(object stmt) {
Return the number of result columns for the given statement */
PHP_FUNCTION ( mysqli_stmt_field_count )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
2004-07-07 16:02:27 +08:00
zval * mysql_stmt ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-07-07 16:02:27 +08:00
RETURN_LONG ( mysql_stmt_field_count ( stmt - > stmt ) ) ;
}
/* }}} */
2004-03-10 17:50:05 +08:00
/* {{{ proto void mysqli_stmt_free_result(object stmt)
Free stored result memory for the given statement handle */
PHP_FUNCTION ( mysqli_stmt_free_result )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2004-03-10 17:50:05 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-03-10 17:50:05 +08:00
mysql_stmt_free_result ( stmt - > stmt ) ;
}
/* }}} */
2004-03-17 05:43:25 +08:00
2004-06-06 02:31:56 +08:00
/* {{{ proto mixed mysqli_stmt_insert_id(object stmt)
Get the ID generated from the previous INSERT operation */
PHP_FUNCTION ( mysqli_stmt_insert_id )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
my_ulonglong rc ;
zval * mysql_stmt ;
2004-06-06 02:31:56 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
rc = mysql_stmt_insert_id ( stmt - > stmt ) ;
MYSQLI_RETURN_LONG_LONG ( rc )
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto int mysqli_stmt_param_count(object stmt)
2004-07-07 16:02:27 +08:00
Return the number of parameter for the given statement */
PHP_FUNCTION ( mysqli_stmt_param_count )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
2004-07-07 16:02:27 +08:00
zval * mysql_stmt ;
2007-10-06 05:23:56 +08:00
2004-07-07 16:02:27 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-07-07 16:02:27 +08:00
RETURN_LONG ( mysql_stmt_param_count ( stmt - > stmt ) ) ;
}
/* }}} */
2004-07-14 00:12:28 +08:00
/* {{{ proto bool mysqli_stmt_reset(object stmt)
2004-03-17 05:43:25 +08:00
reset a prepared statement */
2007-10-06 05:23:56 +08:00
PHP_FUNCTION ( mysqli_stmt_reset )
2004-03-17 05:43:25 +08:00
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2004-03-17 05:43:25 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-03-17 05:43:25 +08:00
2004-07-14 00:12:28 +08:00
if ( mysql_stmt_reset ( stmt - > stmt ) ) {
RETURN_FALSE ;
}
RETURN_TRUE ;
2004-03-17 05:43:25 +08:00
}
/* }}} */
2004-03-10 17:50:05 +08:00
2003-06-22 16:46:39 +08:00
/* {{{ proto mixed mysqli_stmt_num_rows(object stmt)
Return the number of rows in statements result set */
PHP_FUNCTION ( mysqli_stmt_num_rows )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2003-06-22 16:46:39 +08:00
my_ulonglong rc ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2003-07-28 18:23:36 +08:00
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-06-22 16:46:39 +08:00
2003-08-31 19:03:05 +08:00
rc = mysql_stmt_num_rows ( stmt - > stmt ) ;
2003-06-22 16:46:39 +08:00
MYSQLI_RETURN_LONG_LONG ( rc )
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto bool mysqli_select_db(object link, string dbname)
2003-03-16 06:51:49 +08:00
Select a MySQL database */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_select_db )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link ;
char * dbname ;
int dbname_len ;
2003-06-29 05:27:08 +08:00
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Os " , & mysql_link , mysqli_link_class_entry , & dbname , & dbname_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
if ( mysql_select_db ( mysql - > mysql , dbname ) ) {
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
RETURN_FALSE ;
2003-02-12 08:45:53 +08:00
}
2007-10-06 05:23:56 +08:00
RETURN_TRUE ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_sqlstate(object link)
2003-06-21 21:35:26 +08:00
Returns the SQLSTATE error from previous MySQL operation */
PHP_FUNCTION ( mysqli_sqlstate )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-06-21 21:35:26 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-06-06 02:31:56 +08:00
RETURN_STRING ( ( char * ) mysql_sqlstate ( mysql - > mysql ) , 1 ) ;
2003-06-21 21:35:26 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
/* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher]) U
2003-02-12 08:45:53 +08:00
*/
PHP_FUNCTION ( mysqli_ssl_set )
{
2004-06-06 02:31:56 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
zval * mysql_link ;
char * ssl_parm [ 5 ] ;
2004-06-06 02:31:56 +08:00
int ssl_parm_len [ 5 ] , i ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Osssss " , & mysql_link , mysqli_link_class_entry , & ssl_parm [ 0 ] , & ssl_parm_len [ 0 ] , & ssl_parm [ 1 ] , & ssl_parm_len [ 1 ] , & ssl_parm [ 2 ] , & ssl_parm_len [ 2 ] , & ssl_parm [ 3 ] , & ssl_parm_len [ 3 ] , & ssl_parm [ 4 ] , & ssl_parm_len [ 4 ] ) = = FAILURE ) {
2003-02-12 08:45:53 +08:00
return ;
}
2010-04-08 17:01:21 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_INITIALIZED ) ;
2004-06-06 02:31:56 +08:00
2007-10-06 05:23:56 +08:00
for ( i = 0 ; i < 5 ; i + + ) {
2004-06-06 02:31:56 +08:00
if ( ! ssl_parm_len [ i ] ) {
ssl_parm [ i ] = NULL ;
}
}
mysql_ssl_set ( mysql - > mysql , ssl_parm [ 0 ] , ssl_parm [ 1 ] , ssl_parm [ 2 ] , ssl_parm [ 3 ] , ssl_parm [ 4 ] ) ;
2003-02-12 08:45:53 +08:00
RETURN_TRUE ;
}
/* }}} */
2004-01-26 21:38:13 +08:00
/* {{{ proto mixed mysqli_stat(object link)
2003-03-16 06:51:49 +08:00
Get current system status */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_stat )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2004-01-26 21:38:13 +08:00
char * stat ;
2008-03-11 04:15:38 +08:00
# if defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
uint stat_len ;
# endif
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
if ( ( stat = ( char * ) mysql_stat ( mysql - > mysql ) ) )
{
2004-01-26 21:38:13 +08:00
RETURN_STRING ( stat , 1 ) ;
2007-10-06 05:23:56 +08:00
# else
if ( mysqlnd_stat ( mysql - > mysql , & stat , & stat_len ) = = PASS )
{
RETURN_STRINGL ( stat , stat_len , 0 ) ;
# endif
} else {
RETURN_FALSE ;
2004-01-26 21:38:13 +08:00
}
2003-02-12 08:45:53 +08:00
}
/* }}} */
2009-01-23 05:01:58 +08:00
/* {{{ proto bool mysqli_refresh(object link, long options)
Flush tables or caches , or reset replication server information */
PHP_FUNCTION ( mysqli_refresh )
{
MY_MYSQL * mysql ;
zval * mysql_link = NULL ;
long options ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_link , mysqli_link_class_entry , & options ) = = FAILURE ) {
return ;
}
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_INITIALIZED ) ;
2009-05-23 10:58:15 +08:00
# ifdef MYSQLI_USE_MYSQLND
RETURN_BOOL ( ! mysql_refresh ( mysql - > mysql , ( uint8_t ) options ) ) ;
# else
2009-05-20 21:10:49 +08:00
RETURN_BOOL ( ! mysql_refresh ( mysql - > mysql , options ) ) ;
2009-05-23 10:58:15 +08:00
# endif
2009-01-23 05:01:58 +08:00
}
/* }}} */
2003-02-12 08:45:53 +08:00
2006-05-08 23:06:51 +08:00
/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode)
2004-07-07 16:02:27 +08:00
*/
PHP_FUNCTION ( mysqli_stmt_attr_set )
{
MY_STMT * stmt ;
2007-10-06 05:23:56 +08:00
zval * mysql_stmt ;
long mode_in ;
ulong mode ;
2004-07-07 16:02:27 +08:00
ulong attr ;
2007-10-06 05:23:56 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Oll " , & mysql_stmt , mysqli_stmt_class_entry , & attr , & mode_in ) = = FAILURE ) {
2004-07-07 16:02:27 +08:00
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-07-07 16:02:27 +08:00
2007-10-06 05:23:56 +08:00
if ( mode_in < 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " mode should be non-negative, %ld passed " , mode_in ) ;
RETURN_FALSE ;
}
mode = mode_in ;
2009-09-25 18:52:29 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2009-09-25 20:25:54 +08:00
if ( FALSE = = mysql_stmt_attr_set ( stmt - > stmt , attr , ( void * ) & mode ) ) {
2009-09-25 18:52:29 +08:00
# else
if ( FAIL = = mysql_stmt_attr_set ( stmt - > stmt , attr , ( void * ) & mode ) ) {
# endif
2004-07-07 16:02:27 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
/* {{{ proto int mysqli_stmt_attr_get(object stmt, long attr)
*/
PHP_FUNCTION ( mysqli_stmt_attr_get )
{
MY_STMT * stmt ;
2007-10-06 05:23:56 +08:00
zval * mysql_stmt ;
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND) && MYSQL_VERSION_ID > 50099
2006-05-08 23:06:51 +08:00
my_bool value ;
# else
2006-03-11 19:16:03 +08:00
ulong value = 0 ;
2006-05-08 23:06:51 +08:00
# endif
2004-07-07 16:02:27 +08:00
ulong attr ;
int rc ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Ol " , & mysql_stmt , mysqli_stmt_class_entry , & attr ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-07-07 16:02:27 +08:00
2004-07-17 18:48:28 +08:00
if ( ( rc = mysql_stmt_attr_get ( stmt - > stmt , attr , & value ) ) ) {
2004-07-07 16:02:27 +08:00
RETURN_FALSE ;
}
2006-05-08 23:06:51 +08:00
RETURN_LONG ( ( long ) value ) ;
2004-07-07 16:02:27 +08:00
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_stmt_errno(object stmt)
2003-02-12 08:45:53 +08:00
*/
PHP_FUNCTION ( mysqli_stmt_errno )
{
2004-06-06 02:31:56 +08:00
MY_STMT * stmt ;
2007-10-06 05:23:56 +08:00
zval * mysql_stmt ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-04-05 20:17:08 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_INITIALIZED ) ;
2003-02-12 08:45:53 +08:00
RETURN_LONG ( mysql_stmt_errno ( stmt - > stmt ) ) ;
}
/* }}} */
2003-06-22 14:16:47 +08:00
/* {{{ proto string mysqli_stmt_error(object stmt)
2003-02-12 08:45:53 +08:00
*/
PHP_FUNCTION ( mysqli_stmt_error )
{
2004-06-06 02:31:56 +08:00
MY_STMT * stmt ;
2003-03-09 07:33:12 +08:00
zval * mysql_stmt ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-04-05 20:17:08 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_INITIALIZED ) ;
2003-02-12 08:45:53 +08:00
RETURN_STRING ( ( char * ) mysql_stmt_error ( stmt - > stmt ) , 1 ) ;
}
/* }}} */
2004-07-14 01:04:16 +08:00
/* {{{ proto mixed mysqli_stmt_init(object link)
2004-03-09 20:01:23 +08:00
Initialize statement object
*/
PHP_FUNCTION ( mysqli_stmt_init )
{
2004-06-08 14:20:58 +08:00
MY_MYSQL * mysql ;
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
2004-03-09 20:01:23 +08:00
zval * mysql_link ;
2007-10-06 05:23:56 +08:00
MYSQLI_RESOURCE * mysqli_resource ;
2004-03-09 20:01:23 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2004-03-09 20:01:23 +08:00
2004-06-06 02:31:56 +08:00
stmt = ( MY_STMT * ) ecalloc ( 1 , sizeof ( MY_STMT ) ) ;
2004-03-18 21:04:55 +08:00
2004-06-08 14:20:58 +08:00
if ( ! ( stmt - > stmt = mysql_stmt_init ( mysql - > mysql ) ) ) {
2004-03-18 21:04:55 +08:00
efree ( stmt ) ;
2004-03-09 20:01:23 +08:00
RETURN_FALSE ;
}
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
2006-03-24 17:32:24 +08:00
mysqli_resource - > status = MYSQLI_STATUS_INITIALIZED ;
2004-03-09 20:01:23 +08:00
mysqli_resource - > ptr = ( void * ) stmt ;
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_stmt_class_entry ) ;
}
/* }}} */
2004-07-14 01:04:16 +08:00
/* {{{ proto bool mysqli_stmt_prepare(object stmt, string query)
2004-03-09 20:01:23 +08:00
prepare server side statement with query
*/
PHP_FUNCTION ( mysqli_stmt_prepare )
{
2004-06-06 02:31:56 +08:00
MY_STMT * stmt ;
2004-03-09 20:01:23 +08:00
zval * mysql_stmt ;
char * query ;
int query_len ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " Os " , & mysql_stmt , mysqli_stmt_class_entry , & query , & query_len ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_INITIALIZED ) ;
2004-03-09 20:01:23 +08:00
if ( mysql_stmt_prepare ( stmt - > stmt , query , query_len ) ) {
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
RETURN_FALSE ;
}
2006-03-24 17:32:24 +08:00
/* change status */
MYSQLI_SET_STATUS ( & mysql_stmt , MYSQLI_STATUS_VALID ) ;
2004-03-09 20:01:23 +08:00
RETURN_TRUE ;
}
/* }}} */
/* {{{ proto mixed mysqli_stmt_result_metadata(object stmt)
return result set from statement */
PHP_FUNCTION ( mysqli_stmt_result_metadata )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
2004-03-09 20:01:23 +08:00
MYSQL_RES * result ;
2007-10-06 05:23:56 +08:00
zval * mysql_stmt ;
2004-03-09 20:01:23 +08:00
MYSQLI_RESOURCE * mysqli_resource ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2004-03-09 20:01:23 +08:00
if ( ! ( result = mysql_stmt_result_metadata ( stmt - > stmt ) ) ) {
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
RETURN_FALSE ;
}
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
mysqli_resource - > ptr = ( void * ) result ;
2006-03-24 17:32:24 +08:00
mysqli_resource - > status = MYSQLI_STATUS_VALID ;
2007-10-06 05:23:56 +08:00
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_result_class_entry ) ;
2004-03-09 20:01:23 +08:00
}
/* }}} */
2004-01-26 21:38:13 +08:00
/* {{{ proto bool mysqli_stmt_store_result(stmt)
2003-02-18 16:49:00 +08:00
*/
PHP_FUNCTION ( mysqli_stmt_store_result )
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2003-02-18 16:49:00 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2003-02-18 16:49:00 +08:00
2008-03-11 04:15:38 +08:00
# if !defined(MYSQLI_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
{
/*
If the user wants to store the data and we have BLOBs / TEXTs we try to allocate
not the maximal length of the type ( which is 16 MB even for LONGBLOB ) but
the maximal length of the field in the result set . If he / she has quite big
BLOB / TEXT columns after calling store_result ( ) the memory usage of PHP will
double - but this is a known problem of the simple MySQL API ; )
*/
int i = 0 ;
for ( i = mysql_stmt_field_count ( stmt - > stmt ) - 1 ; i > = 0 ; - - i ) {
if ( stmt - > stmt - > fields & & ( stmt - > stmt - > fields [ i ] . type = = MYSQL_TYPE_BLOB | |
stmt - > stmt - > fields [ i ] . type = = MYSQL_TYPE_MEDIUM_BLOB | |
2009-09-11 21:38:47 +08:00
stmt - > stmt - > fields [ i ] . type = = MYSQL_TYPE_LONG_BLOB | |
stmt - > stmt - > fields [ i ] . type = = MYSQL_TYPE_GEOMETRY ) )
2007-10-06 05:23:56 +08:00
{
my_bool tmp = 1 ;
mysql_stmt_attr_set ( stmt - > stmt , STMT_ATTR_UPDATE_MAX_LENGTH , & tmp ) ;
break ;
}
2005-04-28 01:53:15 +08:00
}
}
2007-10-06 05:23:56 +08:00
# endif
2005-04-28 01:53:15 +08:00
2003-02-18 16:49:00 +08:00
if ( mysql_stmt_store_result ( stmt - > stmt ) ) {
2003-12-13 08:28:21 +08:00
MYSQLI_REPORT_STMT_ERROR ( stmt - > stmt ) ;
2003-02-18 16:49:00 +08:00
RETURN_FALSE ;
}
RETURN_TRUE ;
}
/* }}} */
2003-03-09 07:33:12 +08:00
2003-09-17 03:45:22 +08:00
/* {{{ proto string mysqli_stmt_sqlstate(object stmt)
2003-06-21 21:35:26 +08:00
*/
2007-10-06 05:23:56 +08:00
PHP_FUNCTION ( mysqli_stmt_sqlstate )
2003-06-21 21:35:26 +08:00
{
2007-10-06 05:23:56 +08:00
MY_STMT * stmt ;
zval * mysql_stmt ;
2003-06-21 21:35:26 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_stmt , mysqli_stmt_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( stmt , MY_STMT * , & mysql_stmt , " mysqli_stmt " , MYSQLI_STATUS_VALID ) ;
2007-10-06 05:23:56 +08:00
2003-06-21 21:35:26 +08:00
RETURN_STRING ( ( char * ) mysql_stmt_sqlstate ( stmt - > stmt ) , 1 ) ;
}
/* }}} */
2003-10-30 04:48:47 +08:00
/* {{{ proto object mysqli_store_result(object link)
2003-05-04 11:15:02 +08:00
Buffer result set on client */
2003-03-09 07:33:12 +08:00
PHP_FUNCTION ( mysqli_store_result )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
MYSQL_RES * result ;
zval * mysql_link ;
2003-03-09 07:33:12 +08:00
MYSQLI_RESOURCE * mysqli_resource ;
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-03-09 07:33:12 +08:00
2004-06-06 02:31:56 +08:00
if ( ! ( result = mysql_store_result ( mysql - > mysql ) ) ) {
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2003-03-09 07:33:12 +08:00
RETURN_FALSE ;
}
2003-12-13 08:28:21 +08:00
if ( MyG ( report_mode ) & MYSQLI_REPORT_INDEX ) {
2007-10-06 05:23:56 +08:00
php_mysqli_report_index ( " from previous query " , mysqli_server_status ( mysql - > mysql ) TSRMLS_CC ) ;
2003-12-13 08:28:21 +08:00
}
2006-03-24 17:32:24 +08:00
2003-03-09 07:33:12 +08:00
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
mysqli_resource - > ptr = ( void * ) result ;
2006-03-24 17:32:24 +08:00
mysqli_resource - > status = MYSQLI_STATUS_VALID ;
2007-10-06 05:23:56 +08:00
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_result_class_entry ) ;
2003-03-09 07:33:12 +08:00
}
/* }}} */
2007-10-06 05:23:56 +08:00
2003-06-22 14:16:47 +08:00
/* {{{ proto int mysqli_thread_id(object link)
2003-03-16 06:51:49 +08:00
Return the current thread ID */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_thread_id )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2009-05-20 16:30:12 +08:00
RETURN_LONG ( ( long ) mysql_thread_id ( mysql - > mysql ) ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
/* {{{ proto bool mysqli_thread_safe(void)
2003-03-16 06:51:49 +08:00
Return whether thread safety is given or not */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_thread_safe )
{
RETURN_BOOL ( mysql_thread_safe ( ) ) ;
}
/* }}} */
2004-01-26 21:38:13 +08:00
/* {{{ proto mixed mysqli_use_result(object link)
2003-05-04 11:15:02 +08:00
Directly retrieve query results - do not buffer results on client side */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_use_result )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
MYSQL_RES * result ;
zval * mysql_link ;
MYSQLI_RESOURCE * mysqli_resource ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
if ( ! ( result = mysql_use_result ( mysql - > mysql ) ) ) {
MYSQLI_REPORT_MYSQL_ERROR ( mysql - > mysql ) ;
2003-02-12 08:45:53 +08:00
RETURN_FALSE ;
}
2003-12-13 08:28:21 +08:00
if ( MyG ( report_mode ) & MYSQLI_REPORT_INDEX ) {
2007-10-06 05:23:56 +08:00
php_mysqli_report_index ( " from previous query " , mysqli_server_status ( mysql - > mysql ) TSRMLS_CC ) ;
2003-12-13 08:28:21 +08:00
}
2003-03-09 07:33:12 +08:00
mysqli_resource = ( MYSQLI_RESOURCE * ) ecalloc ( 1 , sizeof ( MYSQLI_RESOURCE ) ) ;
mysqli_resource - > ptr = ( void * ) result ;
2006-03-24 17:32:24 +08:00
mysqli_resource - > status = MYSQLI_STATUS_VALID ;
2007-10-06 05:23:56 +08:00
MYSQLI_RETURN_RESOURCE ( mysqli_resource , mysqli_result_class_entry ) ;
2003-02-12 08:45:53 +08:00
}
/* }}} */
2003-10-30 04:48:47 +08:00
/* {{{ proto int mysqli_warning_count (object link)
2003-05-04 11:15:02 +08:00
Return number of warnings from the last query for the given link */
2003-02-12 08:45:53 +08:00
PHP_FUNCTION ( mysqli_warning_count )
{
2007-10-06 05:23:56 +08:00
MY_MYSQL * mysql ;
zval * mysql_link ;
2003-02-12 08:45:53 +08:00
if ( zend_parse_method_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , getThis ( ) , " O " , & mysql_link , mysqli_link_class_entry ) = = FAILURE ) {
return ;
}
2006-03-24 17:32:24 +08:00
MYSQLI_FETCH_RESOURCE ( mysql , MY_MYSQL * , & mysql_link , " mysqli_link " , MYSQLI_STATUS_VALID ) ;
2003-02-12 08:45:53 +08:00
2004-06-06 02:31:56 +08:00
RETURN_LONG ( mysql_warning_count ( mysql - > mysql ) ) ;
2003-02-12 08:45:53 +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
*/