2001-02-01 17:36:52 +08:00
/*
1999-04-22 05:26:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 16:18:22 +08:00
| PHP Version 5 |
1999-04-22 05:26:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-01-03 11:08:10 +08:00
| Copyright ( c ) 1997 - 2014 The PHP Group |
1999-04-22 05:26:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 21:13:16 +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 |
1999-07-16 21:13:16 +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 . |
1999-04-22 05:26:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2002-08-08 06:02:11 +08:00
| Authors : Zeev Suraski < zeev @ zend . com > |
| Zak Greant < zak @ mysql . com > |
| Georg Richter < georg @ php . net > |
1999-04-22 05:26:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
1999-09-04 03:54:12 +08:00
*/
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
/* $Id$ */
/* TODO:
*
* ? Safe mode implementation
*/
2001-05-24 18:07:29 +08:00
# ifdef HAVE_CONFIG_H
2002-07-13 06:57:19 +08:00
# include "config.h"
2001-05-24 18:07:29 +08:00
# endif
1999-04-22 05:26:10 +08:00
# include "php.h"
# include "php_globals.h"
1999-12-29 02:45:10 +08:00
# include "ext/standard/info.h"
# include "ext/standard/php_string.h"
2007-10-06 05:23:56 +08:00
# include "ext/standard/basic_functions.h"
2005-09-04 12:51:23 +08:00
# ifdef ZEND_ENGINE_2
# include "zend_exceptions.h"
# else
/* PHP 4 compat */
# define OnUpdateLong OnUpdateInt
# define E_STRICT E_NOTICE
# endif
1999-04-22 05:26:10 +08:00
2002-04-19 00:48:03 +08:00
# if HAVE_MYSQL
2000-02-13 03:47:49 +08:00
# ifdef PHP_WIN32
2003-02-16 11:48:49 +08:00
# include <winsock2.h>
2002-07-13 06:57:19 +08:00
# define signal(a, b) NULL
2002-07-12 20:55:56 +08:00
# elif defined(NETWARE)
2002-07-13 06:57:19 +08:00
# include <sys / socket.h>
# define signal(a, b) NULL
1999-04-22 05:26:10 +08:00
# else
2002-07-13 06:57:19 +08:00
# if HAVE_SIGNAL_H
# include <signal.h>
# endif
# if HAVE_SYS_TYPES_H
# include <sys / types.h>
# endif
# include <netdb.h>
# include <netinet / in.h>
2005-04-08 06:23:15 +08:00
# if HAVE_ARPA_INET_H
# include <arpa / inet.h>
# endif
1999-04-22 05:26:10 +08:00
# endif
2002-07-13 06:57:19 +08:00
# include "php_ini.h"
2007-10-09 00:14:56 +08:00
# include "php_mysql_structs.h"
2001-12-23 22:37:24 +08:00
1999-04-23 19:12:41 +08:00
/* True globals, no need for thread safety */
2000-12-03 01:27:11 +08:00
static int le_result , le_link , le_plink ;
1999-04-23 19:12:41 +08:00
2001-11-02 15:08:48 +08:00
# ifdef HAVE_MYSQL_REAL_CONNECT
# ifdef HAVE_ERRMSG_H
# include <errmsg.h>
# endif
1999-04-22 05:26:10 +08:00
# endif
# define SAFE_STRING(s) ((s)?(s):"")
2008-03-11 04:15:38 +08:00
# if MYSQL_VERSION_ID > 32199 || defined(MYSQL_USE_MYSQLND)
2014-08-26 01:24:55 +08:00
# define mysql_row_length_type zend_ulong
2002-07-13 06:57:19 +08:00
# define HAVE_MYSQL_ERRNO
1999-04-22 05:26:10 +08:00
# else
2002-07-13 06:57:19 +08:00
# define mysql_row_length_type unsigned int
# ifdef mysql_errno
# define HAVE_MYSQL_ERRNO
# endif
1999-04-22 05:26:10 +08:00
# endif
2008-03-11 04:15:38 +08:00
# if MYSQL_VERSION_ID >= 32032 || defined(MYSQL_USE_MYSQLND)
2001-02-01 06:04:30 +08:00
# define HAVE_GETINFO_FUNCS
# endif
2001-01-12 16:03:24 +08:00
# if MYSQL_VERSION_ID > 32133 || defined(FIELD_TYPE_TINY)
# define MYSQL_HAS_TINY
# endif
2001-01-31 09:14:54 +08:00
# if MYSQL_VERSION_ID >= 32200
2001-01-31 08:55:28 +08:00
# define MYSQL_HAS_YEAR
# endif
1999-06-28 23:08:28 +08:00
# define MYSQL_ASSOC 1<<0
# define MYSQL_NUM 1<<1
# define MYSQL_BOTH (MYSQL_ASSOC|MYSQL_NUM)
1999-04-22 05:26:10 +08:00
2000-11-07 23:46:15 +08:00
# define MYSQL_USE_RESULT 0
# define MYSQL_STORE_RESULT 1
2002-08-29 09:17:24 +08:00
# if MYSQL_VERSION_ID < 32224
1999-09-06 13:21:45 +08:00
# define PHP_MYSQL_VALID_RESULT(mysql) \
( mysql_num_fields ( mysql ) > 0 )
1999-11-06 05:43:53 +08:00
# else
# define PHP_MYSQL_VALID_RESULT(mysql) \
( mysql_field_count ( mysql ) > 0 )
# endif
1999-09-06 13:21:45 +08:00
2006-06-16 02:33:09 +08:00
ZEND_DECLARE_MODULE_GLOBALS ( mysql )
static PHP_GINIT_FUNCTION ( mysql ) ;
2001-03-14 05:13:19 +08:00
typedef struct _php_mysql_conn {
2007-10-06 05:23:56 +08:00
MYSQL * conn ;
2014-03-23 11:30:09 +08:00
zend_resource * active_result_res ;
2007-10-06 05:23:56 +08:00
int multi_query ;
2001-03-14 05:13:19 +08:00
} php_mysql_conn ;
2007-10-06 05:23:56 +08:00
2008-10-27 20:09:36 +08:00
# if MYSQL_VERSION_ID >= 40101
2007-10-06 05:23:56 +08:00
# define MYSQL_DISABLE_MQ if (mysql->multi_query) { \
mysql_set_server_option ( mysql - > conn , MYSQL_OPTION_MULTI_STATEMENTS_OFF ) ; \
mysql - > multi_query = 0 ; \
2010-10-04 18:08:10 +08:00
}
2008-10-27 20:09:36 +08:00
# else
# define MYSQL_DISABLE_MQ
# endif
2007-10-06 05:23:56 +08:00
2010-05-21 01:28:16 +08:00
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_connect , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , hostname )
ZEND_ARG_INFO ( 0 , username )
ZEND_ARG_INFO ( 0 , password )
ZEND_ARG_INFO ( 0 , new )
ZEND_ARG_INFO ( 0 , flags )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_pconnect , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , hostname )
ZEND_ARG_INFO ( 0 , username )
ZEND_ARG_INFO ( 0 , password )
ZEND_ARG_INFO ( 0 , flags )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo__optional_mysql_link , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_select_db , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , database_name )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO ( arginfo__void_mysql_arg , 0 )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_set_charset , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , charset_name )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_query , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , query )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_db_query , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , database_name )
ZEND_ARG_INFO ( 0 , query )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_list_fields , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , database_name )
ZEND_ARG_INFO ( 0 , table_name )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_escape_string , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , string )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_real_escape_string , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , string )
ZEND_ARG_INFO ( 0 , link_identifier )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_result , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , row )
ZEND_ARG_INFO ( 0 , field )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo__result_mysql_arg , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , result )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_fetch_object , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , class_name )
ZEND_ARG_INFO ( 0 , ctor_params )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_fetch_array , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , result_type )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_data_seek , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , row_number )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_fetch_field , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , field_offset )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_field_seek , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , field_offset )
ZEND_END_ARG_INFO ( )
ZEND_BEGIN_ARG_INFO_EX ( arginfo_mysql_field_name , 0 , 0 , 2 )
ZEND_ARG_INFO ( 0 , result )
ZEND_ARG_INFO ( 0 , field_index )
ZEND_END_ARG_INFO ( )
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ mysql_functions[]
*/
2007-10-06 05:23:56 +08:00
static const zend_function_entry mysql_functions [ ] = {
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_connect , arginfo_mysql_connect )
PHP_FE ( mysql_pconnect , arginfo_mysql_pconnect )
PHP_FE ( mysql_close , arginfo__optional_mysql_link )
PHP_FE ( mysql_select_db , arginfo_mysql_select_db )
2002-07-15 19:14:18 +08:00
# ifndef NETWARE /* The below two functions not supported on NetWare */
2001-11-02 14:42:12 +08:00
# if MYSQL_VERSION_ID < 40000
2010-05-21 01:28:16 +08:00
PHP_DEP_FE ( mysql_create_db , arginfo_mysql_select_db )
PHP_DEP_FE ( mysql_drop_db , arginfo_mysql_select_db )
2001-11-02 14:42:12 +08:00
# endif
2002-07-15 19:14:18 +08:00
# endif /* NETWARE */
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_query , arginfo_mysql_query )
PHP_FE ( mysql_unbuffered_query , arginfo_mysql_query )
2010-08-18 01:40:31 +08:00
PHP_DEP_FE ( mysql_db_query , arginfo_mysql_db_query )
PHP_DEP_FE ( mysql_list_dbs , arginfo__optional_mysql_link )
2010-05-21 01:28:16 +08:00
PHP_DEP_FE ( mysql_list_tables , arginfo_mysql_select_db )
PHP_FE ( mysql_list_fields , arginfo_mysql_list_fields )
PHP_FE ( mysql_list_processes , arginfo__optional_mysql_link )
PHP_FE ( mysql_error , arginfo__optional_mysql_link )
1999-08-18 06:06:55 +08:00
# ifdef HAVE_MYSQL_ERRNO
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_errno , arginfo__optional_mysql_link )
1999-04-22 05:26:10 +08:00
# endif
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_affected_rows , arginfo__optional_mysql_link )
PHP_FE ( mysql_insert_id , arginfo__optional_mysql_link )
PHP_FE ( mysql_result , arginfo_mysql_result )
PHP_FE ( mysql_num_rows , arginfo__result_mysql_arg )
PHP_FE ( mysql_num_fields , arginfo__result_mysql_arg )
PHP_FE ( mysql_fetch_row , arginfo__result_mysql_arg )
PHP_FE ( mysql_fetch_array , arginfo_mysql_fetch_array )
PHP_FE ( mysql_fetch_assoc , arginfo__result_mysql_arg )
PHP_FE ( mysql_fetch_object , arginfo_mysql_fetch_object )
PHP_FE ( mysql_data_seek , arginfo_mysql_data_seek )
PHP_FE ( mysql_fetch_lengths , arginfo__result_mysql_arg )
PHP_FE ( mysql_fetch_field , arginfo_mysql_fetch_field )
PHP_FE ( mysql_field_seek , arginfo_mysql_field_seek )
PHP_FE ( mysql_free_result , arginfo__result_mysql_arg )
PHP_FE ( mysql_field_name , arginfo_mysql_field_name )
PHP_FE ( mysql_field_table , arginfo_mysql_field_seek )
PHP_FE ( mysql_field_len , arginfo_mysql_field_seek )
PHP_FE ( mysql_field_type , arginfo_mysql_field_seek )
PHP_FE ( mysql_field_flags , arginfo_mysql_field_seek )
PHP_FE ( mysql_escape_string , arginfo_mysql_escape_string )
PHP_FE ( mysql_real_escape_string , arginfo_mysql_real_escape_string )
PHP_FE ( mysql_stat , arginfo__optional_mysql_link )
PHP_FE ( mysql_thread_id , arginfo__optional_mysql_link )
PHP_FE ( mysql_client_encoding , arginfo__optional_mysql_link )
PHP_FE ( mysql_ping , arginfo__optional_mysql_link )
2001-02-01 06:04:30 +08:00
# ifdef HAVE_GETINFO_FUNCS
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_get_client_info , arginfo__void_mysql_arg )
PHP_FE ( mysql_get_host_info , arginfo__optional_mysql_link )
PHP_FE ( mysql_get_proto_info , arginfo__optional_mysql_link )
PHP_FE ( mysql_get_server_info , arginfo__optional_mysql_link )
2001-02-01 06:04:30 +08:00
# endif
2002-03-29 20:47:02 +08:00
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_info , arginfo__optional_mysql_link )
2008-08-07 03:25:03 +08:00
# ifdef MYSQL_HAS_SET_CHARSET
2010-05-21 01:28:16 +08:00
PHP_FE ( mysql_set_charset , arginfo_mysql_set_charset )
2010-10-04 18:08:10 +08:00
# endif
2013-07-13 20:15:21 +08:00
/* for downwards compatibility */
2012-10-23 18:02:58 +08:00
PHP_DEP_FALIAS ( mysql , mysql_db_query , arginfo_mysql_db_query )
PHP_DEP_FALIAS ( mysql_fieldname , mysql_field_name , arginfo_mysql_field_name )
PHP_DEP_FALIAS ( mysql_fieldtable , mysql_field_table , arginfo_mysql_field_seek )
PHP_DEP_FALIAS ( mysql_fieldlen , mysql_field_len , arginfo_mysql_field_seek )
PHP_DEP_FALIAS ( mysql_fieldtype , mysql_field_type , arginfo_mysql_field_seek )
PHP_DEP_FALIAS ( mysql_fieldflags , mysql_field_flags , arginfo_mysql_field_seek )
PHP_DEP_FALIAS ( mysql_selectdb , mysql_select_db , arginfo_mysql_select_db )
2002-07-15 19:14:18 +08:00
# ifndef NETWARE /* The below two functions not supported on NetWare */
2001-11-02 14:42:12 +08:00
# if MYSQL_VERSION_ID < 40000
2010-06-27 00:03:39 +08:00
PHP_DEP_FALIAS ( mysql_createdb , mysql_create_db , arginfo_mysql_select_db )
PHP_DEP_FALIAS ( mysql_dropdb , mysql_drop_db , arginfo_mysql_select_db )
2001-11-02 14:42:12 +08:00
# endif
2002-07-15 19:14:18 +08:00
# endif /* NETWARE */
2012-10-23 18:02:58 +08:00
PHP_DEP_FALIAS ( mysql_freeresult , mysql_free_result , arginfo__result_mysql_arg )
PHP_DEP_FALIAS ( mysql_numfields , mysql_num_fields , arginfo__result_mysql_arg )
PHP_DEP_FALIAS ( mysql_numrows , mysql_num_rows , arginfo__result_mysql_arg )
PHP_DEP_FALIAS ( mysql_listdbs , mysql_list_dbs , arginfo__optional_mysql_link )
2010-06-27 00:03:39 +08:00
PHP_DEP_FALIAS ( mysql_listtables , mysql_list_tables , arginfo_mysql_select_db )
2012-10-23 18:02:58 +08:00
PHP_DEP_FALIAS ( mysql_listfields , mysql_list_fields , arginfo_mysql_list_fields )
2010-06-27 00:03:39 +08:00
PHP_FALIAS ( mysql_db_name , mysql_result , arginfo_mysql_result )
2012-10-23 18:02:58 +08:00
PHP_DEP_FALIAS ( mysql_dbname , mysql_result , arginfo_mysql_result )
2010-06-27 00:03:39 +08:00
PHP_FALIAS ( mysql_tablename , mysql_result , arginfo_mysql_result )
PHP_FALIAS ( mysql_table_name , mysql_result , arginfo_mysql_result )
2011-07-25 19:35:02 +08:00
PHP_FE_END
1999-04-22 05:26:10 +08:00
} ;
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2007-10-06 05:23:56 +08:00
/* Dependancies */
static const zend_module_dep mysql_deps [ ] = {
2008-03-11 04:15:38 +08:00
# if defined(MYSQL_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
ZEND_MOD_REQUIRED ( " mysqlnd " )
# endif
2011-08-06 22:47:44 +08:00
ZEND_MOD_END
2007-10-06 05:23:56 +08:00
} ;
2001-06-05 21:12:10 +08:00
/* {{{ mysql_module_entry
*/
1999-09-04 03:54:12 +08:00
zend_module_entry mysql_module_entry = {
2007-10-06 05:23:56 +08:00
# if ZEND_MODULE_API_NO >= 20050922
STANDARD_MODULE_HEADER_EX , NULL ,
mysql_deps ,
# elif ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER ,
# endif
2001-10-12 07:33:59 +08:00
" mysql " ,
2002-03-25 01:19:19 +08:00
mysql_functions ,
ZEND_MODULE_STARTUP_N ( mysql ) ,
PHP_MSHUTDOWN ( mysql ) ,
PHP_RINIT ( mysql ) ,
PHP_RSHUTDOWN ( mysql ) ,
PHP_MINFO ( mysql ) ,
2005-09-05 01:10:56 +08:00
" 1.0 " ,
2006-06-16 02:33:09 +08:00
PHP_MODULE_GLOBALS ( mysql ) ,
PHP_GINIT ( mysql ) ,
NULL ,
NULL ,
STANDARD_MODULE_PROPERTIES_EX
1999-04-22 05:26:10 +08:00
} ;
2001-06-05 21:12:10 +08:00
/* }}} */
2000-04-02 00:23:39 +08:00
2000-05-23 17:33:51 +08:00
# ifdef COMPILE_DL_MYSQL
2000-05-02 08:30:36 +08:00
ZEND_GET_MODULE ( mysql )
1999-04-22 05:26:10 +08:00
# endif
2000-02-20 06:41:53 +08:00
void timeout ( int sig ) ;
1999-04-22 05:26:10 +08:00
2014-03-23 11:30:09 +08:00
# define CHECK_LINK(link) { if (link == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
1999-04-22 05:26:10 +08:00
2008-03-11 04:15:38 +08:00
# if defined(MYSQL_USE_MYSQLND)
2014-03-23 11:30:09 +08:00
# define PHPMY_UNBUFFERED_QUERY_CHECK() \
{ \
if ( mysql - > active_result_res ) { \
do { \
MYSQL_RES * _mysql_result ; \
_mysql_result = ( MYSQL_RES * ) mysql - > active_result_res - > ptr ; \
if ( _mysql_result & & \
mysql - > active_result_res - > type = = le_result ) { \
if ( mysql_result_is_unbuffered ( _mysql_result ) & & \
! mysql_eof ( _mysql_result ) ) { \
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , \
2014-06-18 16:59:56 +08:00
" Function called without first fetching all " \
2014-03-23 11:30:09 +08:00
" rows from a previous unbuffered query " ) ; \
} \
zend_list_close ( mysql - > active_result_res ) ; \
mysql - > active_result_res = NULL ; \
} \
} while ( 0 ) ; \
} \
2007-10-06 05:23:56 +08:00
}
# else
2014-03-23 11:30:09 +08:00
# define PHPMY_UNBUFFERED_QUERY_CHECK() \
{ \
if ( mysql - > active_result_res ) { \
do { \
MYSQL_RES * mysql_result ; \
mysql_result = ( MYSQL_RES * ) mysql - > active_result_res - > ptr ; \
if ( mysql_result & & \
mysql - > active_result_res - > type = = le_result ) { \
if ( ! mysql_eof ( mysql_result ) ) { \
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , \
" Function called without first fetching " \
" all rows from a previous unbuffered query " ) ; \
while ( mysql_fetch_row ( mysql_result ) ) ; \
} \
zend_list_close ( mysql - > active_result_res ) ; \
mysql - > active_result_res = NULL ; \
} \
} while ( 0 ) ; \
} \
2007-10-06 05:23:56 +08:00
}
# endif
2003-07-23 00:05:32 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _free_mysql_result
2000-04-02 00:23:39 +08:00
* This wrapper is required since mysql_free_result ( ) returns an integer , and
* thus , cannot be used directly
1999-04-22 05:26:10 +08:00
*/
2014-03-23 11:30:09 +08:00
static void _free_mysql_result ( zend_resource * rsrc TSRMLS_DC )
2000-04-02 00:23:39 +08:00
{
2000-10-21 02:25:16 +08:00
MYSQL_RES * mysql_result = ( MYSQL_RES * ) rsrc - > ptr ;
2001-03-14 06:52:53 +08:00
1999-04-22 05:26:10 +08:00
mysql_free_result ( mysql_result ) ;
2002-11-17 00:07:54 +08:00
MySG ( result_allocated ) - - ;
1999-04-22 05:26:10 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_set_default_link
*/
2014-03-23 11:30:09 +08:00
static void php_mysql_set_default_link ( zend_resource * link TSRMLS_DC )
1999-04-22 05:26:10 +08:00
{
2014-03-23 11:30:09 +08:00
if ( MySG ( default_link ) ! = NULL ) {
2014-05-08 06:48:31 +08:00
zend_list_delete ( MySG ( default_link ) ) ;
2004-06-04 21:49:31 +08:00
}
2014-04-02 18:34:44 +08:00
+ + GC_REFCOUNT ( link ) ;
2014-03-23 11:30:09 +08:00
MySG ( default_link ) = link ;
1999-04-22 05:26:10 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2003-07-23 00:05:32 +08:00
/* {{{ php_mysql_select_db
*/
static int php_mysql_select_db ( php_mysql_conn * mysql , char * db TSRMLS_DC )
{
2003-08-08 21:36:28 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2003-07-23 00:05:32 +08:00
2007-10-06 05:23:56 +08:00
if ( mysql_select_db ( mysql - > conn , db ) ! = 0 ) {
2003-08-08 21:36:28 +08:00
return 0 ;
} else {
return 1 ;
2003-07-23 00:05:32 +08:00
}
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ _close_mysql_link
*/
2014-03-23 11:30:09 +08:00
static void _close_mysql_link ( zend_resource * rsrc TSRMLS_DC )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * link = ( php_mysql_conn * ) rsrc - > ptr ;
2014-03-23 11:30:09 +08:00
void ( * handler ) ( int ) ;
1999-04-22 05:26:10 +08:00
2000-02-20 06:41:53 +08:00
handler = signal ( SIGPIPE , SIG_IGN ) ;
2007-10-06 05:23:56 +08:00
mysql_close ( link - > conn ) ;
2000-12-03 01:27:11 +08:00
signal ( SIGPIPE , handler ) ;
1999-04-22 05:26:10 +08:00
efree ( link ) ;
MySG ( num_links ) - - ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ _close_mysql_plink
*/
2014-03-23 11:30:09 +08:00
static void _close_mysql_plink ( zend_resource * rsrc TSRMLS_DC )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * link = ( php_mysql_conn * ) rsrc - > ptr ;
2000-02-20 06:41:53 +08:00
void ( * handler ) ( int ) ;
1999-04-22 05:26:10 +08:00
2000-02-20 06:41:53 +08:00
handler = signal ( SIGPIPE , SIG_IGN ) ;
2007-10-06 05:23:56 +08:00
mysql_close ( link - > conn ) ;
2000-12-03 01:27:11 +08:00
signal ( SIGPIPE , handler ) ;
1999-04-22 05:26:10 +08:00
free ( link ) ;
MySG ( num_persistent ) - - ;
MySG ( num_links ) - - ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_INI_MH
*/
1999-04-22 05:26:10 +08:00
static PHP_INI_MH ( OnMySQLPort )
{
2003-06-01 10:29:28 +08:00
if ( new_value ! = NULL ) { /* default port */
1999-04-22 05:26:10 +08:00
MySG ( default_port ) = atoi ( new_value ) ;
2003-06-01 10:29:28 +08:00
} else {
MySG ( default_port ) = - 1 ;
1999-04-22 05:26:10 +08:00
}
2003-06-01 10:29:28 +08:00
1999-04-22 05:26:10 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-06 00:06:31 +08:00
/* {{{ PHP_INI */
1999-04-22 05:26:10 +08:00
PHP_INI_BEGIN ( )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_BOOLEAN ( " mysql.allow_persistent " , " 1 " , PHP_INI_SYSTEM , OnUpdateLong , allow_persistent , zend_mysql_globals , mysql_globals )
STD_PHP_INI_ENTRY_EX ( " mysql.max_persistent " , " -1 " , PHP_INI_SYSTEM , OnUpdateLong , max_persistent , zend_mysql_globals , mysql_globals , display_link_numbers )
STD_PHP_INI_ENTRY_EX ( " mysql.max_links " , " -1 " , PHP_INI_SYSTEM , OnUpdateLong , max_links , zend_mysql_globals , mysql_globals , display_link_numbers )
2000-06-16 09:53:35 +08:00
STD_PHP_INI_ENTRY ( " mysql.default_host " , NULL , PHP_INI_ALL , OnUpdateString , default_host , zend_mysql_globals , mysql_globals )
STD_PHP_INI_ENTRY ( " mysql.default_user " , NULL , PHP_INI_ALL , OnUpdateString , default_user , zend_mysql_globals , mysql_globals )
STD_PHP_INI_ENTRY ( " mysql.default_password " , NULL , PHP_INI_ALL , OnUpdateString , default_password , zend_mysql_globals , mysql_globals )
PHP_INI_ENTRY ( " mysql.default_port " , NULL , PHP_INI_ALL , OnMySQLPort )
2008-07-21 20:58:51 +08:00
# ifdef MYSQL_UNIX_ADDR
STD_PHP_INI_ENTRY ( " mysql.default_socket " , MYSQL_UNIX_ADDR , PHP_INI_ALL , OnUpdateStringUnempty , default_socket , zend_mysql_globals , mysql_globals )
# else
2000-06-16 09:53:35 +08:00
STD_PHP_INI_ENTRY ( " mysql.default_socket " , NULL , PHP_INI_ALL , OnUpdateStringUnempty , default_socket , zend_mysql_globals , mysql_globals )
2008-07-21 20:58:51 +08:00
# endif
2003-06-18 23:19:16 +08:00
STD_PHP_INI_ENTRY ( " mysql.connect_timeout " , " 60 " , PHP_INI_ALL , OnUpdateLong , connect_timeout , zend_mysql_globals , mysql_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_BOOLEAN ( " mysql.trace_mode " , " 0 " , PHP_INI_ALL , OnUpdateLong , trace_mode , zend_mysql_globals , mysql_globals )
2007-10-06 05:23:56 +08:00
STD_PHP_INI_BOOLEAN ( " mysql.allow_local_infile " , " 1 " , PHP_INI_SYSTEM , OnUpdateLong , allow_local_infile , zend_mysql_globals , mysql_globals )
1999-04-22 05:26:10 +08:00
PHP_INI_END ( )
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2006-06-16 02:33:09 +08:00
/* {{{ PHP_GINIT_FUNCTION
2001-06-05 21:12:10 +08:00
*/
2006-06-16 02:33:09 +08:00
static PHP_GINIT_FUNCTION ( mysql )
1999-04-23 19:12:41 +08:00
{
2000-04-02 00:23:39 +08:00
mysql_globals - > num_persistent = 0 ;
2001-02-22 07:57:28 +08:00
mysql_globals - > default_socket = NULL ;
mysql_globals - > default_host = NULL ;
mysql_globals - > default_user = NULL ;
mysql_globals - > default_password = NULL ;
2001-05-04 09:14:26 +08:00
mysql_globals - > connect_errno = 0 ;
mysql_globals - > connect_error = NULL ;
2002-07-16 21:53:54 +08:00
mysql_globals - > connect_timeout = 0 ;
2002-11-11 20:54:06 +08:00
mysql_globals - > trace_mode = 0 ;
2007-10-06 05:23:56 +08:00
mysql_globals - > allow_local_infile = 1 ;
2002-11-11 20:54:06 +08:00
mysql_globals - > result_allocated = 0 ;
1999-04-23 19:12:41 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-23 19:12:41 +08:00
2011-09-01 04:30:08 +08:00
# ifdef MYSQL_USE_MYSQLND
2011-10-26 07:01:49 +08:00
# include "ext/mysqlnd/mysqlnd_reverse_api.h"
2014-03-23 11:30:09 +08:00
static MYSQLND * mysql_convert_zv_to_mysqlnd ( zval * zv TSRMLS_DC )
2011-09-01 04:30:08 +08:00
{
php_mysql_conn * mysql ;
if ( Z_TYPE_P ( zv ) ! = IS_RESOURCE ) {
/* Might be nicer to check resource type, too, but ext/mysql is the only one using resources so emitting an error is not to bad, while usually this hook should be silent */
return NULL ;
}
2014-03-23 11:30:09 +08:00
mysql = zend_fetch_resource ( zv TSRMLS_CC , - 1 , " MySQL-Link " , NULL , 2 , le_link , le_plink ) ;
2011-09-01 04:30:08 +08:00
if ( ! mysql ) {
return NULL ;
}
return mysql - > conn ;
}
2011-10-19 23:04:12 +08:00
static MYSQLND_REVERSE_API mysql_reverse_api = {
2011-09-01 04:30:08 +08:00
& mysql_module_entry ,
mysql_convert_zv_to_mysqlnd
} ;
# endif
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINIT_FUNCTION
*/
2001-08-12 00:39:07 +08:00
ZEND_MODULE_STARTUP_D ( mysql )
1999-04-22 05:26:10 +08:00
{
1999-04-23 19:12:41 +08:00
REGISTER_INI_ENTRIES ( ) ;
2000-10-26 01:44:02 +08:00
le_result = zend_register_list_destructors_ex ( _free_mysql_result , NULL , " mysql result " , module_number ) ;
le_link = zend_register_list_destructors_ex ( _close_mysql_link , NULL , " mysql link " , module_number ) ;
le_plink = zend_register_list_destructors_ex ( NULL , _close_mysql_plink , " mysql link persistent " , module_number ) ;
2014-04-02 18:34:44 +08:00
mysql_module_entry . type = type ;
2003-06-01 10:29:28 +08:00
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " MYSQL_ASSOC " , MYSQL_ASSOC , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " MYSQL_NUM " , MYSQL_NUM , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " MYSQL_BOTH " , MYSQL_BOTH , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " MYSQL_CLIENT_COMPRESS " , CLIENT_COMPRESS , CONST_CS | CONST_PERSISTENT ) ;
2010-10-04 18:08:10 +08:00
# if MYSQL_VERSION_ID >= 40000
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " MYSQL_CLIENT_SSL " , CLIENT_SSL , CONST_CS | CONST_PERSISTENT ) ;
2002-08-23 22:10:27 +08:00
# endif
2014-08-26 01:24:55 +08:00
REGISTER_LONG_CONSTANT ( " MYSQL_CLIENT_INTERACTIVE " , CLIENT_INTERACTIVE , CONST_CS | CONST_PERSISTENT ) ;
REGISTER_LONG_CONSTANT ( " MYSQL_CLIENT_IGNORE_SPACE " , CLIENT_IGNORE_SPACE , CONST_CS | CONST_PERSISTENT ) ;
2002-07-10 21:16:24 +08:00
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-09-10 00:08:17 +08:00
# if MYSQL_VERSION_ID >= 40000
2007-06-26 00:01:30 +08:00
if ( mysql_server_init ( 0 , NULL , NULL ) ) {
return FAILURE ;
}
2007-09-10 00:08:17 +08:00
# endif
2007-10-06 05:23:56 +08:00
# endif
2007-06-26 00:01:30 +08:00
2011-09-01 04:30:08 +08:00
# ifdef MYSQL_USE_MYSQLND
2011-10-19 23:04:12 +08:00
mysqlnd_reverse_api_register_api ( & mysql_reverse_api TSRMLS_CC ) ;
2011-09-01 04:30:08 +08:00
# endif
1999-04-22 05:26:10 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
1999-08-03 00:06:13 +08:00
PHP_MSHUTDOWN_FUNCTION ( mysql )
1999-04-22 05:26:10 +08:00
{
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-09-10 00:08:17 +08:00
# if MYSQL_VERSION_ID >= 40000
2007-06-26 00:01:30 +08:00
# ifdef PHP_WIN32
2007-09-10 00:08:17 +08:00
unsigned long client_ver = mysql_get_client_version ( ) ;
2007-10-06 05:23:56 +08:00
/*
2008-03-08 23:00:50 +08:00
Can ' t call mysql_server_end ( ) multiple times prior to 5.0 .46 on Windows .
2007-10-06 05:23:56 +08:00
PHP bug # 41350 MySQL bug # 25621
*/
2008-03-08 23:00:50 +08:00
if ( ( client_ver > = 50046 & & client_ver < 50100 ) | | client_ver > 50122 ) {
2007-06-26 00:01:30 +08:00
mysql_server_end ( ) ;
}
# else
mysql_server_end ( ) ;
2007-09-10 00:08:17 +08:00
# endif
2007-10-06 05:23:56 +08:00
# endif
2007-06-26 00:01:30 +08:00
# endif
1999-04-22 05:26:10 +08:00
UNREGISTER_INI_ENTRIES ( ) ;
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_RINIT_FUNCTION
*/
1999-08-03 00:06:13 +08:00
PHP_RINIT_FUNCTION ( mysql )
1999-04-22 05:26:10 +08:00
{
2008-03-11 04:15:38 +08:00
# if !defined(MYSQL_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
2007-06-26 00:01:30 +08:00
if ( mysql_thread_init ( ) ) {
return FAILURE ;
}
# endif
2014-03-23 11:30:09 +08:00
MySG ( default_link ) = NULL ;
1999-04-22 05:26:10 +08:00
MySG ( num_links ) = MySG ( num_persistent ) ;
2001-05-05 02:27:15 +08:00
/* Reset connect error/errno on every request */
2001-05-05 09:42:15 +08:00
MySG ( connect_error ) = NULL ;
2002-11-13 16:54:34 +08:00
MySG ( connect_errno ) = 0 ;
MySG ( result_allocated ) = 0 ;
2007-06-26 00:01:30 +08:00
2001-05-05 09:42:15 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-05-05 09:42:15 +08:00
2011-08-02 22:18:56 +08:00
# if defined(A0) && defined(MYSQL_USE_MYSQLND)
2014-08-13 16:44:22 +08:00
static int php_mysql_persistent_helper ( zval * el TSRMLS_DC )
2008-06-25 06:22:48 +08:00
{
2014-08-13 16:44:22 +08:00
zend_resource * le = ( zend_resource * ) Z_PTR_P ( el ) ;
2008-06-25 06:22:48 +08:00
if ( le - > type = = le_plink ) {
mysqlnd_end_psession ( ( ( php_mysql_conn * ) le - > ptr ) - > conn ) ;
}
return ZEND_HASH_APPLY_KEEP ;
} /* }}} */
# endif
2001-06-05 21:12:10 +08:00
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
2001-05-05 09:42:15 +08:00
PHP_RSHUTDOWN_FUNCTION ( mysql )
{
2008-03-11 04:15:38 +08:00
# if !defined(MYSQL_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
2007-06-26 00:01:30 +08:00
mysql_thread_end ( ) ;
# endif
2002-11-11 20:54:06 +08:00
if ( MySG ( trace_mode ) ) {
if ( MySG ( result_allocated ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( " function.mysql-free-result " TSRMLS_CC , E_WARNING , " %pu result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() " , MySG ( result_allocated ) ) ;
2002-11-11 20:54:06 +08:00
}
}
2001-05-05 02:27:15 +08:00
if ( MySG ( connect_error ) ! = NULL ) {
efree ( MySG ( connect_error ) ) ;
}
2008-06-25 06:22:48 +08:00
2011-08-02 22:18:56 +08:00
# if defined(A0) && defined(MYSQL_USE_MYSQLND)
2008-06-25 06:22:48 +08:00
zend_hash_apply ( & EG ( persistent_list ) , ( apply_func_t ) php_mysql_persistent_helper TSRMLS_CC ) ;
2007-10-06 05:23:56 +08:00
# endif
1999-04-22 05:26:10 +08:00
return SUCCESS ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ PHP_MINFO_FUNCTION
*/
1999-08-03 00:06:13 +08:00
PHP_MINFO_FUNCTION ( mysql )
1999-04-22 05:26:10 +08:00
{
1999-08-14 05:03:27 +08:00
char buf [ 32 ] ;
2000-04-06 04:18:58 +08:00
php_info_print_table_start ( ) ;
2000-04-07 05:07:44 +08:00
php_info_print_table_header ( 2 , " MySQL Support " , " enabled " ) ;
2014-08-26 02:22:49 +08:00
snprintf ( buf , sizeof ( buf ) , ZEND_LONG_FMT , MySG ( num_persistent ) ) ;
1999-08-14 05:03:27 +08:00
php_info_print_table_row ( 2 , " Active Persistent Links " , buf ) ;
2014-08-26 02:22:49 +08:00
snprintf ( buf , sizeof ( buf ) , ZEND_LONG_FMT , MySG ( num_links ) ) ;
1999-08-14 05:03:27 +08:00
php_info_print_table_row ( 2 , " Active Links " , buf ) ;
php_info_print_table_row ( 2 , " Client API version " , mysql_get_client_info ( ) ) ;
2008-03-11 04:15:38 +08:00
# if !defined (PHP_WIN32) && !defined (NETWARE) && !defined(MYSQL_USE_MYSQLND)
2001-05-02 08:21:25 +08:00
php_info_print_table_row ( 2 , " MYSQL_MODULE_TYPE " , PHP_MYSQL_TYPE ) ;
php_info_print_table_row ( 2 , " MYSQL_SOCKET " , MYSQL_UNIX_ADDR ) ;
1999-08-14 05:03:27 +08:00
php_info_print_table_row ( 2 , " MYSQL_INCLUDE " , PHP_MYSQL_INCLUDE ) ;
php_info_print_table_row ( 2 , " MYSQL_LIBS " , PHP_MYSQL_LIBS ) ;
1999-04-22 05:26:10 +08:00
# endif
2002-08-08 05:21:46 +08:00
2000-04-06 04:18:58 +08:00
php_info_print_table_end ( ) ;
2000-04-07 05:07:44 +08:00
DISPLAY_INI_ENTRIES ( ) ;
1999-04-22 05:26:10 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_do_connect
*/
2000-12-03 01:27:11 +08:00
# define MYSQL_DO_CONNECT_CLEANUP() \
if ( free_host ) { \
efree ( host ) ; \
}
# define MYSQL_DO_CONNECT_RETURN_FALSE() \
MYSQL_DO_CONNECT_CLEANUP ( ) ; \
RETURN_FALSE ;
2008-03-11 04:15:38 +08:00
# ifdef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
# define MYSQL_PORT 0
# endif
2000-12-03 01:27:11 +08:00
static void php_mysql_do_connect ( INTERNAL_FUNCTION_PARAMETERS , int persistent )
1999-04-22 05:26:10 +08:00
{
2014-03-23 11:30:09 +08:00
char * user = NULL , * passwd = NULL ;
char * host_and_port = NULL , * socket = NULL ;
char * tmp = NULL , * host = NULL ;
2014-08-27 21:31:48 +08:00
size_t user_len = 0 , passwd_len = 0 , host_len = 0 ;
2014-03-23 11:30:09 +08:00
int port = MYSQL_PORT ;
2014-08-26 01:24:55 +08:00
zend_long client_flags = 0 ;
2014-03-23 11:30:09 +08:00
php_mysql_conn * mysql = NULL ;
2002-11-12 16:11:23 +08:00
# if MYSQL_VERSION_ID <= 32230
2000-02-20 06:41:53 +08:00
void ( * handler ) ( int ) ;
2002-11-12 16:11:23 +08:00
# endif
2014-08-26 01:24:55 +08:00
zend_long connect_timeout ;
2014-03-23 11:30:09 +08:00
zend_string * hashed_details = NULL ;
zend_bool free_host = 0 , new_link = 0 ;
2002-08-08 05:21:46 +08:00
2012-12-10 22:12:09 +08:00
php_error_docref ( NULL TSRMLS_CC ,
E_DEPRECATED ,
" The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead " ) ;
2008-10-27 20:09:36 +08:00
# if !defined(MYSQL_USE_MYSQLND)
if ( ( MYSQL_VERSION_ID / 100 ) ! = ( mysql_get_client_version ( ) / 100 ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING ,
2008-10-28 07:27:21 +08:00
" Headers and client library minor version mismatch. Headers:%d Library:%ld " ,
2008-10-27 20:09:36 +08:00
MYSQL_VERSION_ID , mysql_get_client_version ( ) ) ;
}
# endif
1999-04-22 05:26:10 +08:00
2002-07-16 21:53:54 +08:00
connect_timeout = MySG ( connect_timeout ) ;
2002-08-08 05:21:46 +08:00
2000-06-16 09:53:35 +08:00
socket = MySG ( default_socket ) ;
2003-06-01 10:29:28 +08:00
if ( MySG ( default_port ) < 0 ) {
# if !defined(PHP_WIN32) && !defined(NETWARE)
struct servent * serv_ptr ;
char * env ;
2010-10-04 18:08:10 +08:00
2003-06-01 10:29:28 +08:00
MySG ( default_port ) = MYSQL_PORT ;
if ( ( serv_ptr = getservbyname ( " mysql " , " tcp " ) ) ) {
2014-03-23 11:30:09 +08:00
MySG ( default_port ) = ( uint ) ntohs ( ( ushort ) serv_ptr - > s_port ) ;
2003-06-01 10:29:28 +08:00
}
if ( ( env = getenv ( " MYSQL_TCP_PORT " ) ) ) {
2014-03-23 11:30:09 +08:00
MySG ( default_port ) = ( uint ) atoi ( env ) ;
2003-06-01 10:29:28 +08:00
}
# else
MySG ( default_port ) = MYSQL_PORT ;
# endif
}
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
if ( PG ( sql_safe_mode ) ) {
2000-06-06 03:47:54 +08:00
if ( ZEND_NUM_ARGS ( ) > 0 ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_NOTICE , " SQL safe mode in effect - ignoring host/user/password information " ) ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
user = php_get_current_user ( TSRMLS_C ) ;
2014-08-26 01:24:55 +08:00
hashed_details = zend_string_alloc ( sizeof ( " mysql___ " ) + strlen ( user ) - 1 , 0 ) ;
2014-03-23 11:30:09 +08:00
snprintf ( hashed_details - > val , hashed_details - > len + 1 , " mysql__%s_ " , user ) ;
2002-07-10 21:16:24 +08:00
client_flags = CLIENT_INTERACTIVE ;
1999-04-22 05:26:10 +08:00
} else {
2008-02-13 04:43:42 +08:00
/* mysql_pconnect does not support new_link parameter */
if ( persistent ) {
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s!s!s!l " , & host_and_port , & host_len ,
2008-02-13 04:43:42 +08:00
& user , & user_len , & passwd , & passwd_len ,
& client_flags ) = = FAILURE ) {
return ;
}
} else {
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s!s!s!bl " , & host_and_port , & host_len ,
2010-10-04 18:08:10 +08:00
& user , & user_len , & passwd , & passwd_len ,
2008-02-13 04:43:42 +08:00
& new_link , & client_flags ) = = FAILURE ) {
return ;
}
1999-04-22 05:26:10 +08:00
}
2007-10-06 05:23:56 +08:00
2007-12-20 08:26:21 +08:00
if ( ! host_and_port ) {
host_and_port = MySG ( default_host ) ;
}
if ( ! user ) {
user = MySG ( default_user ) ;
}
if ( ! passwd ) {
passwd = MySG ( default_password ) ;
2011-01-15 04:02:49 +08:00
passwd_len = passwd ? strlen ( passwd ) : 0 ;
2007-12-20 08:26:21 +08:00
}
2007-10-06 05:23:56 +08:00
/* disable local infile option for open_basedir */
2010-04-27 07:53:30 +08:00
# if PHP_API_VERSION < 20100412
2007-10-06 05:23:56 +08:00
if ( ( ( PG ( open_basedir ) & & PG ( open_basedir ) [ 0 ] ! = ' \0 ' ) | | PG ( safe_mode ) ) & & ( client_flags & CLIENT_LOCAL_FILES ) ) {
2010-04-27 07:53:30 +08:00
# else
if ( ( PG ( open_basedir ) & & PG ( open_basedir ) [ 0 ] ! = ' \0 ' ) & & ( client_flags & CLIENT_LOCAL_FILES ) ) {
# endif
2007-10-06 05:23:56 +08:00
client_flags ^ = CLIENT_LOCAL_FILES ;
2000-12-03 01:27:11 +08:00
}
2010-02-08 21:09:34 +08:00
# ifdef CLIENT_MULTI_RESULTS
client_flags | = CLIENT_MULTI_RESULTS ; /* compatibility with 5.2, see bug#50416 */
# endif
2008-10-27 20:09:36 +08:00
# ifdef CLIENT_MULTI_STATEMENTS
2008-07-15 21:11:09 +08:00
client_flags & = ~ CLIENT_MULTI_STATEMENTS ; /* don't allow multi_queries via connect parameter */
2008-10-27 20:09:36 +08:00
# endif
2014-08-26 01:24:55 +08:00
hashed_details = zend_string_alloc ( sizeof ( " mysql____ " ) + ( host_and_port ? strlen ( host_and_port ) : 0 )
+ ( user ? strlen ( user ) : 0 ) + ( passwd ? strlen ( passwd ) : 0 ) + MAX_LENGTH_OF_LONG - 1 , 0 ) ;
2014-08-26 02:22:49 +08:00
hashed_details - > len = snprintf ( hashed_details - > val , hashed_details - > len + 1 , " mysql_%s_%s_%s_ " ZEND_LONG_FMT , SAFE_STRING ( host_and_port ) , SAFE_STRING ( user ) , SAFE_STRING ( passwd ) , client_flags ) ;
1999-04-22 05:26:10 +08:00
}
/* We cannot use mysql_port anymore in windows, need to use
* mysql_real_connect ( ) to set the port .
*/
2014-03-23 11:30:09 +08:00
if ( host_and_port & & ( tmp = strchr ( host_and_port , ' : ' ) ) ) {
2000-12-03 01:27:11 +08:00
host = estrndup ( host_and_port , tmp - host_and_port ) ;
free_host = 1 ;
1999-04-22 05:26:10 +08:00
tmp + + ;
1999-12-03 03:09:01 +08:00
if ( tmp [ 0 ] ! = ' / ' ) {
port = atoi ( tmp ) ;
2000-03-26 10:01:11 +08:00
if ( ( tmp = strchr ( tmp , ' : ' ) ) ) {
2000-03-20 15:40:56 +08:00
tmp + + ;
socket = tmp ;
2002-03-24 18:57:40 +08:00
}
1999-12-03 03:09:01 +08:00
} else {
socket = tmp ;
}
1999-04-22 05:26:10 +08:00
} else {
2000-12-03 01:27:11 +08:00
host = host_and_port ;
1999-04-22 05:26:10 +08:00
port = MySG ( default_port ) ;
}
# if MYSQL_VERSION_ID < 32200
mysql_port = port ;
# endif
if ( ! MySG ( allow_persistent ) ) {
2014-03-23 11:30:09 +08:00
persistent = 0 ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
1999-04-22 05:26:10 +08:00
if ( persistent ) {
2014-03-23 11:30:09 +08:00
zend_resource * le ;
zend_string * phashed ;
2002-03-24 18:57:40 +08:00
1999-04-22 05:26:10 +08:00
/* try to find if we already have this link in our persistent list */
2014-03-23 11:30:09 +08:00
if ( ( le = zend_hash_find_ptr ( & EG ( persistent_list ) , hashed_details ) ) = = NULL ) { /* we don't */
2014-04-11 18:47:53 +08:00
zval new_le ;
1999-04-22 05:26:10 +08:00
2007-10-06 05:23:56 +08:00
if ( MySG ( max_links ) ! = - 1 & & MySG ( num_links ) > = MySG ( max_links ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Too many open links (%pd) " , MySG ( num_links ) ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
2007-10-06 05:23:56 +08:00
if ( MySG ( max_persistent ) ! = - 1 & & MySG ( num_persistent ) > = MySG ( max_persistent ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Too many open persistent links (%pd) " , MySG ( num_persistent ) ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
/* create the link */
2014-03-23 11:30:09 +08:00
mysql = ( php_mysql_conn * ) malloc ( sizeof ( php_mysql_conn ) ) ;
2011-05-18 19:49:49 +08:00
if ( ! mysql ) {
2014-03-23 11:30:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_ERROR ,
" Out of memory while allocating memory for a persistent link " ) ;
2011-05-18 19:49:49 +08:00
}
2014-03-23 11:30:09 +08:00
mysql - > active_result_res = NULL ;
2008-10-27 20:09:36 +08:00
# ifdef CLIENT_MULTI_STATEMENTS
2008-07-15 21:11:09 +08:00
mysql - > multi_query = client_flags & CLIENT_MULTI_STATEMENTS ? 1 : 0 ;
2008-10-27 20:09:36 +08:00
# else
mysql - > multi_query = 0 ;
# endif
2010-10-04 18:08:10 +08:00
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
mysql - > conn = mysql_init ( NULL ) ;
# else
2014-04-10 21:44:54 +08:00
mysql - > conn = mysqlnd_init ( MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA , persistent ) ;
2007-10-06 05:23:56 +08:00
# endif
2002-07-16 21:53:54 +08:00
2008-06-25 06:22:48 +08:00
if ( connect_timeout ! = - 1 ) {
2007-10-06 05:23:56 +08:00
mysql_options ( mysql - > conn , MYSQL_OPT_CONNECT_TIMEOUT , ( const char * ) & connect_timeout ) ;
2008-06-25 06:22:48 +08:00
}
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
if ( mysql_real_connect ( mysql - > conn , host , user , passwd , NULL , port , socket , client_flags ) = = NULL )
1999-04-22 05:26:10 +08:00
# else
2014-04-10 21:44:54 +08:00
if ( mysqlnd_connect ( mysql - > conn , host , user , passwd , passwd_len , NULL , 0 , port , socket , client_flags , MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC ) = = NULL )
1999-04-22 05:26:10 +08:00
# endif
2007-10-06 05:23:56 +08:00
{
2001-05-04 09:14:26 +08:00
/* Populate connect error globals so that the error functions can read them */
2007-10-06 05:23:56 +08:00
if ( MySG ( connect_error ) ! = NULL ) {
efree ( MySG ( connect_error ) ) ;
}
2014-03-23 11:30:09 +08:00
2007-10-06 05:23:56 +08:00
MySG ( connect_error ) = estrdup ( mysql_error ( mysql - > conn ) ) ;
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s " , MySG ( connect_error ) ) ;
2001-05-04 09:14:26 +08:00
# if defined(HAVE_MYSQL_ERRNO)
2007-10-06 05:23:56 +08:00
MySG ( connect_errno ) = mysql_errno ( mysql - > conn ) ;
2002-03-24 18:57:40 +08:00
# endif
1999-04-22 05:26:10 +08:00
free ( mysql ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2007-10-06 05:23:56 +08:00
mysql_options ( mysql - > conn , MYSQL_OPT_LOCAL_INFILE , ( char * ) & MySG ( allow_local_infile ) ) ;
2002-03-24 18:57:40 +08:00
1999-04-22 05:26:10 +08:00
/* hash it up */
2014-04-11 18:47:53 +08:00
ZVAL_NEW_PERSISTENT_RES ( & new_le , - 1 , mysql , le_plink ) ;
2014-03-23 11:30:09 +08:00
/* avoid bogus memleak report */
2014-08-26 01:24:55 +08:00
phashed = zend_string_init ( hashed_details - > val , hashed_details - > len , 1 ) ;
2014-04-11 18:47:53 +08:00
if ( zend_hash_update ( & EG ( persistent_list ) , phashed , & new_le ) = = NULL ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( phashed ) ;
1999-04-22 05:26:10 +08:00
free ( mysql ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2014-08-26 01:24:55 +08:00
zend_string_release ( phashed ) ;
1999-04-22 05:26:10 +08:00
MySG ( num_persistent ) + + ;
MySG ( num_links ) + + ;
2002-11-12 09:41:16 +08:00
} else { /* The link is in our list of persistent connections */
2014-03-23 11:30:09 +08:00
if ( le - > type ! = le_plink ) {
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
mysql = ( php_mysql_conn * ) le - > ptr ;
mysql - > active_result_res = NULL ;
2008-10-27 20:09:36 +08:00
# ifdef CLIENT_MULTI_STATEMENTS
2008-07-15 21:11:09 +08:00
mysql - > multi_query = client_flags & CLIENT_MULTI_STATEMENTS ? 1 : 0 ;
2008-10-27 20:09:36 +08:00
# else
mysql - > multi_query = 0 ;
# endif
1999-04-22 05:26:10 +08:00
/* ensure that the link did not die */
2010-10-04 21:36:23 +08:00
# if defined(A0) && MYSQL_USE_MYSQLND
2008-07-23 07:44:23 +08:00
mysqlnd_end_psession ( mysql - > conn ) ;
2010-10-04 18:08:10 +08:00
# endif
2007-10-06 05:23:56 +08:00
if ( mysql_ping ( mysql - > conn ) ) {
if ( mysql_errno ( mysql - > conn ) = = 2006 ) {
2008-06-25 06:22:48 +08:00
# ifndef MYSQL_USE_MYSQLND
if ( mysql_real_connect ( mysql - > conn , host , user , passwd , NULL , port , socket , client_flags ) = = NULL )
# else
2014-04-10 21:44:54 +08:00
if ( mysqlnd_connect ( mysql - > conn , host , user , passwd , passwd_len , NULL , 0 , port , socket , client_flags , MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC ) = = NULL )
1999-04-22 05:26:10 +08:00
# endif
2007-10-06 05:23:56 +08:00
{
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Link to server lost, unable to reconnect " ) ;
2014-03-23 11:30:09 +08:00
zend_hash_del ( & EG ( persistent_list ) , hashed_details ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2007-10-06 05:23:56 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
}
mysql_options ( mysql - > conn , MYSQL_OPT_LOCAL_INFILE , ( char * ) & MySG ( allow_local_infile ) ) ;
1999-04-22 05:26:10 +08:00
}
2007-10-06 05:23:56 +08:00
} else {
2008-03-11 04:15:38 +08:00
# ifdef MYSQL_USE_MYSQLND
2009-12-10 04:21:05 +08:00
mysqlnd_restart_psession ( mysql - > conn ) ;
2003-01-08 19:00:06 +08:00
# endif
2007-10-06 05:23:56 +08:00
}
1999-04-22 05:26:10 +08:00
}
1999-09-04 03:54:12 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql , le_plink ) ;
1999-04-22 05:26:10 +08:00
} else { /* non persistent */
2014-04-11 18:47:53 +08:00
zend_resource * index_ptr ;
zval new_index_ptr ;
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
/* first we check the hash for the hashed_details key. if it exists,
* it should point us to the right offset where the actual mysql link sits .
* if it doesn ' t , open a new mysql link , add it to the resource list ,
* and add a pointer to it with hashed_details as the key .
*/
2014-03-23 11:30:09 +08:00
if ( ! new_link & & ( index_ptr = zend_hash_find_ptr ( & EG ( regular_list ) , hashed_details ) ) ) {
zend_resource * link ;
1999-04-22 05:26:10 +08:00
2014-03-23 11:30:09 +08:00
if ( index_ptr - > type ! = le_index_ptr ) {
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
link = ( zend_resource * ) index_ptr - > ptr ;
if ( link & & ( link - > type = = le_link | | link - > type = = le_plink ) ) {
2014-04-02 18:34:44 +08:00
GC_REFCOUNT ( link ) + + ;
2014-03-23 11:30:09 +08:00
ZVAL_RES ( return_value , link ) ;
2001-07-30 14:18:13 +08:00
php_mysql_set_default_link ( link TSRMLS_CC ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_CLEANUP ( ) ;
1999-04-22 05:26:10 +08:00
return ;
} else {
2014-03-23 11:30:09 +08:00
zend_hash_del ( & EG ( regular_list ) , hashed_details ) ;
1999-04-22 05:26:10 +08:00
}
}
2014-03-23 11:30:09 +08:00
2007-10-06 05:23:56 +08:00
if ( MySG ( max_links ) ! = - 1 & & MySG ( num_links ) > = MySG ( max_links ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Too many open links (%pd) " , MySG ( num_links ) ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2001-03-14 05:13:19 +08:00
mysql = ( php_mysql_conn * ) emalloc ( sizeof ( php_mysql_conn ) ) ;
2014-03-23 11:30:09 +08:00
mysql - > active_result_res = NULL ;
2008-10-27 20:09:36 +08:00
# ifdef CLIENT_MULTI_STATEMENTS
2007-10-06 05:23:56 +08:00
mysql - > multi_query = 1 ;
2008-10-27 20:09:36 +08:00
# endif
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
mysql - > conn = mysql_init ( NULL ) ;
# else
2014-04-10 21:44:54 +08:00
mysql - > conn = mysqlnd_init ( MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA , persistent ) ;
2007-10-06 05:23:56 +08:00
# endif
2010-05-26 06:55:10 +08:00
if ( ! mysql - > conn ) {
MySG ( connect_error ) = estrdup ( " OOM " ) ;
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " OOM " ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2010-05-26 06:55:10 +08:00
efree ( mysql ) ;
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
}
2002-07-16 21:53:54 +08:00
2010-05-26 06:55:10 +08:00
if ( connect_timeout ! = - 1 ) {
mysql_options ( mysql - > conn , MYSQL_OPT_CONNECT_TIMEOUT , ( const char * ) & connect_timeout ) ;
}
2002-07-16 21:53:54 +08:00
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2010-10-04 18:08:10 +08:00
if ( mysql_real_connect ( mysql - > conn , host , user , passwd , NULL , port , socket , client_flags ) = = NULL )
1999-04-22 05:26:10 +08:00
# else
2014-04-10 21:44:54 +08:00
if ( mysqlnd_connect ( mysql - > conn , host , user , passwd , passwd_len , NULL , 0 , port , socket , client_flags , MYSQLND_CLIENT_KNOWS_RSET_COPY_DATA TSRMLS_CC ) = = NULL )
2001-05-04 09:14:26 +08:00
# endif
2007-10-06 05:23:56 +08:00
{
2001-05-04 09:14:26 +08:00
/* Populate connect error globals so that the error functions can read them */
2007-10-06 05:23:56 +08:00
if ( MySG ( connect_error ) ! = NULL ) {
efree ( MySG ( connect_error ) ) ;
}
MySG ( connect_error ) = estrdup ( mysql_error ( mysql - > conn ) ) ;
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s " , MySG ( connect_error ) ) ;
2001-05-04 09:14:26 +08:00
# if defined(HAVE_MYSQL_ERRNO)
2007-10-06 05:23:56 +08:00
MySG ( connect_errno ) = mysql_errno ( mysql - > conn ) ;
# endif
/* free mysql structure */
2008-03-11 04:15:38 +08:00
# ifdef MYSQL_USE_MYSQLND
2008-09-30 05:18:31 +08:00
mysqlnd_close ( mysql - > conn , MYSQLND_CLOSE_DISCONNECTED ) ;
1999-04-22 05:26:10 +08:00
# endif
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
1999-04-22 05:26:10 +08:00
efree ( mysql ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2007-10-06 05:23:56 +08:00
mysql_options ( mysql - > conn , MYSQL_OPT_LOCAL_INFILE , ( char * ) & MySG ( allow_local_infile ) ) ;
1999-04-22 05:26:10 +08:00
/* add it to the list */
1999-09-04 03:54:12 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql , le_link ) ;
1999-04-22 05:26:10 +08:00
/* add it to the hash */
2014-04-11 18:47:53 +08:00
ZVAL_NEW_RES ( & new_index_ptr , - 1 , Z_RES_P ( return_value ) , le_index_ptr ) ;
if ( zend_hash_update ( & EG ( regular_list ) , hashed_details , & new_index_ptr ) = = NULL ) {
2014-04-09 20:48:03 +08:00
zval_ptr_dtor ( return_value ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_RETURN_FALSE ( ) ;
1999-04-22 05:26:10 +08:00
}
2014-04-09 20:48:03 +08:00
Z_ADDREF_P ( return_value ) ;
1999-04-22 05:26:10 +08:00
MySG ( num_links ) + + ;
}
2014-08-26 01:24:55 +08:00
zend_string_release ( hashed_details ) ;
2014-03-23 11:30:09 +08:00
php_mysql_set_default_link ( Z_RES_P ( return_value ) TSRMLS_CC ) ;
2000-12-03 01:27:11 +08:00
MYSQL_DO_CONNECT_CLEANUP ( ) ;
1999-04-22 05:26:10 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_get_default_link
*/
2014-03-23 11:30:09 +08:00
static zend_resource * php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAMETERS )
1999-04-22 05:26:10 +08:00
{
2014-03-23 11:30:09 +08:00
if ( MySG ( default_link ) = = NULL ) { /* no link opened yet, implicitly open one */
ZEND_NUM_ARGS ( ) = 0 ;
1999-09-04 03:54:12 +08:00
php_mysql_do_connect ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-22 05:26:10 +08:00
}
return MySG ( default_link ) ;
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-06-04 18:45:54 +08:00
2002-07-17 03:26:23 +08:00
/* {{{ proto resource mysql_connect([string hostname[:port][:/path/to/socket] [, string username [, string password [, bool new [, int flags]]]]])
2001-11-09 06:05:56 +08:00
Opens a connection to a MySQL Server */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_connect )
1999-04-22 05:26:10 +08:00
{
1999-09-04 03:54:12 +08:00
php_mysql_do_connect ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2002-07-17 03:26:23 +08:00
/* {{{ proto resource mysql_pconnect([string hostname[:port][:/path/to/socket] [, string username [, string password [, int flags]]]])
2001-11-09 06:05:56 +08:00
Opens a persistent connection to a MySQL Server */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_pconnect )
1999-04-22 05:26:10 +08:00
{
1999-09-04 03:54:12 +08:00
php_mysql_do_connect ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto bool mysql_close([int link_identifier])
1999-04-22 05:26:10 +08:00
Close a MySQL connection */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_close )
1999-04-22 05:26:10 +08:00
{
2014-03-23 11:30:09 +08:00
zend_resource * res ;
zval * mysql_link = NULL ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
1999-04-22 05:26:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
if ( mysql_link ) {
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
} else {
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , NULL , MySG ( default_link ) ? MySG ( default_link ) - > handle : - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2000-11-03 09:56:47 +08:00
2014-03-23 11:30:09 +08:00
res = mysql_link ? Z_RES_P ( mysql_link ) : MySG ( default_link ) ;
2009-09-18 18:49:31 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2014-03-23 11:30:09 +08:00
if ( res ) {
2008-07-23 01:41:15 +08:00
# ifdef MYSQL_USE_MYSQLND
2014-03-23 11:30:09 +08:00
if ( res - > type = = le_plink ) {
2008-07-23 01:41:15 +08:00
mysqlnd_end_psession ( mysql - > conn ) ;
}
# endif
2014-05-20 17:19:21 +08:00
if ( res = = MySG ( default_link ) ) {
zend_list_delete ( res ) ;
2014-03-23 11:30:09 +08:00
MySG ( default_link ) = NULL ;
2014-05-20 17:19:21 +08:00
}
if ( mysql_link ) {
/* we have at least 3 additional references to this resource ??? */
if ( GC_REFCOUNT ( res ) < = 3 ) {
zend_list_close ( res ) ;
}
2009-09-18 18:49:31 +08:00
}
2000-11-03 08:41:29 +08:00
}
2000-11-03 09:56:47 +08:00
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
}
/* }}} */
2002-07-22 05:36:10 +08:00
/* {{{ proto bool mysql_select_db(string database_name [, int link_identifier])
2001-11-09 06:05:56 +08:00
Selects a MySQL database */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_select_db )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db ;
2014-08-27 21:31:48 +08:00
size_t db_len ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & db , & db_len , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2002-04-28 14:38:12 +08:00
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2002-04-28 14:38:12 +08:00
2008-11-29 04:23:49 +08:00
if ( php_mysql_select_db ( mysql , db TSRMLS_CC ) ) {
2003-07-23 00:05:32 +08:00
RETURN_TRUE ;
1999-04-22 05:26:10 +08:00
} else {
2010-10-04 18:08:10 +08:00
RETURN_FALSE ;
2002-04-28 14:38:12 +08:00
}
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-02-01 06:04:30 +08:00
# ifdef HAVE_GETINFO_FUNCS
2001-03-12 23:14:38 +08:00
/* {{{ proto string mysql_get_client_info(void)
2001-02-01 06:04:30 +08:00
Returns a string that represents the client library version */
PHP_FUNCTION ( mysql_get_client_info )
{
2008-03-11 06:15:36 +08:00
if ( zend_parse_parameters_none ( ) = = FAILURE ) {
return ;
2001-02-01 06:04:30 +08:00
}
2014-03-23 11:30:09 +08:00
RETURN_STRING ( ( char * ) mysql_get_client_info ( ) ) ;
2001-02-01 06:04:30 +08:00
}
/* }}} */
/* {{{ proto string mysql_get_host_info([int link_identifier])
2001-02-01 07:35:37 +08:00
Returns a string describing the type of connection in use , including the server host name */
2001-02-01 06:04:30 +08:00
PHP_FUNCTION ( mysql_get_host_info )
{
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2001-02-01 06:04:30 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
2001-02-01 06:04:30 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2014-03-23 11:30:09 +08:00
RETURN_STRING ( ( char * ) mysql_get_host_info ( mysql - > conn ) ) ;
2001-02-01 06:04:30 +08:00
}
/* }}} */
/* {{{ proto int mysql_get_proto_info([int link_identifier])
Returns the protocol version used by current connection */
PHP_FUNCTION ( mysql_get_proto_info )
{
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2001-02-01 06:04:30 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2001-02-01 06:04:30 +08:00
}
2014-08-26 01:24:55 +08:00
RETURN_LONG ( mysql_get_proto_info ( mysql - > conn ) ) ;
2001-02-01 06:04:30 +08:00
}
/* }}} */
/* {{{ proto string mysql_get_server_info([int link_identifier])
Returns a string that represents the server version number */
PHP_FUNCTION ( mysql_get_server_info )
{
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2001-02-01 06:04:30 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
2001-02-01 06:04:30 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2014-03-23 11:30:09 +08:00
RETURN_STRING ( ( char * ) mysql_get_server_info ( mysql - > conn ) ) ;
2001-02-01 06:04:30 +08:00
}
/* }}} */
2002-03-29 20:47:02 +08:00
/* {{{ proto string mysql_info([int link_identifier])
Returns a string containing information about the most recent query */
PHP_FUNCTION ( mysql_info )
{
2002-03-29 20:56:25 +08:00
char * str ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-29 20:47:02 +08:00
php_mysql_conn * mysql ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-29 20:47:02 +08:00
}
2007-10-06 05:23:56 +08:00
if ( ( str = ( char * ) mysql_info ( mysql - > conn ) ) ) {
2014-03-23 11:30:09 +08:00
RETURN_STRING ( str ) ;
2002-03-29 20:47:02 +08:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2002-03-25 01:19:19 +08:00
/* {{{ proto int mysql_thread_id([int link_identifier])
Returns the thread id of current connection */
PHP_FUNCTION ( mysql_thread_id )
{
zval * mysql_link = NULL ;
php_mysql_conn * mysql ;
2002-03-25 09:19:59 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
2002-03-25 01:19:19 +08:00
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-25 09:19:59 +08:00
}
2002-03-25 01:19:19 +08:00
2014-08-26 17:23:25 +08:00
RETURN_LONG ( ( zend_long ) mysql_thread_id ( mysql - > conn ) ) ;
2002-03-25 01:19:19 +08:00
}
/* }}} */
2002-03-24 18:57:40 +08:00
/* {{{ proto string mysql_stat([int link_identifier])
2002-03-25 01:19:19 +08:00
Returns a string containing status information */
2002-03-24 18:57:40 +08:00
PHP_FUNCTION ( mysql_stat )
{
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2014-08-13 15:51:43 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
char * stat ;
2014-08-13 15:51:43 +08:00
# else
zend_string * stat ;
2007-10-06 05:23:56 +08:00
# endif
2002-03-24 18:57:40 +08:00
2014-08-13 15:51:43 +08:00
2002-03-25 09:19:59 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
2002-03-24 18:57:40 +08:00
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-25 09:19:59 +08:00
}
2002-03-25 01:19:19 +08:00
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
if ( ( stat = ( char * ) mysql_stat ( mysql - > conn ) ) ) {
2014-03-23 11:30:09 +08:00
RETURN_STRING ( stat ) ;
2007-10-06 05:23:56 +08:00
# else
2014-08-13 15:51:43 +08:00
if ( mysqlnd_stat ( mysql - > conn , & stat ) = = PASS ) {
RETURN_STR ( stat ) ;
2007-10-06 05:23:56 +08:00
# endif
} else {
RETURN_FALSE ;
}
2002-03-25 01:19:19 +08:00
}
/* }}} */
2002-03-24 18:57:40 +08:00
2002-08-25 05:41:25 +08:00
/* {{{ proto string mysql_client_encoding([int link_identifier])
2002-03-25 01:19:19 +08:00
Returns the default character set for the current connection */
2002-08-25 05:41:25 +08:00
PHP_FUNCTION ( mysql_client_encoding )
2002-03-25 01:19:19 +08:00
{
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-24 18:57:40 +08:00
2002-03-25 09:14:30 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-24 18:57:40 +08:00
}
2014-03-23 11:30:09 +08:00
RETURN_STRING ( ( char * ) mysql_character_set_name ( mysql - > conn ) ) ;
2007-05-15 01:10:47 +08:00
}
/* }}} */
# endif
2008-08-07 03:25:03 +08:00
# ifdef MYSQL_HAS_SET_CHARSET
/* {{{ proto bool mysql_set_charset(string csname [, int link_identifier])
sets client character set */
PHP_FUNCTION ( mysql_set_charset )
{
char * csname ;
2014-08-28 14:31:13 +08:00
size_t csname_len ;
2008-08-07 03:25:03 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2008-08-07 03:25:03 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & csname , & csname_len , & mysql_link ) = = FAILURE ) {
return ;
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-08-07 03:25:03 +08:00
}
if ( ! mysql_set_character_set ( mysql - > conn , csname ) ) {
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
# endif
2002-07-15 19:14:18 +08:00
# ifndef NETWARE /* The below two functions not supported on NetWare */
2001-11-02 14:42:12 +08:00
# if MYSQL_VERSION_ID < 40000
2001-11-09 04:23:33 +08:00
/* {{{ proto bool mysql_create_db(string database_name [, int link_identifier])
1999-04-22 05:26:10 +08:00
Create a MySQL database */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_create_db )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db ;
2014-08-27 21:31:48 +08:00
size_t db_len ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & db , & db_len , & mysql_link ) = = FAILURE ) {
return ;
}
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2002-08-08 06:02:11 +08:00
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2008-11-29 04:23:49 +08:00
if ( mysql_create_db ( mysql - > conn , db ) = = 0 ) {
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto bool mysql_drop_db(string database_name [, int link_identifier])
2001-11-09 06:05:56 +08:00
Drops ( delete ) a MySQL database */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_drop_db )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db ;
2014-08-27 21:31:48 +08:00
size_t db_len ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & db , & db_len , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2002-08-08 06:02:11 +08:00
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2002-07-13 07:25:30 +08:00
2008-11-29 04:23:49 +08:00
if ( mysql_drop_db ( mysql - > conn , db ) = = 0 ) {
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
} else {
RETURN_FALSE ;
}
}
/* }}} */
2001-11-02 14:42:12 +08:00
# endif
2002-07-15 19:14:18 +08:00
# endif /* NETWARE */
1999-04-22 05:26:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_do_query_general
*/
2014-03-23 11:30:09 +08:00
static void php_mysql_do_query_general ( php_mysql_conn * mysql , char * query , int query_len , char * db , int use_store , zval * return_value TSRMLS_DC )
2001-03-14 05:42:43 +08:00
{
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2001-03-14 05:42:43 +08:00
if ( db ) {
2008-11-29 04:23:49 +08:00
if ( ! php_mysql_select_db ( mysql , db TSRMLS_CC ) ) {
2001-03-14 05:42:43 +08:00
RETURN_FALSE ;
}
}
2001-03-14 06:52:53 +08:00
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2001-03-14 06:52:53 +08:00
2007-10-06 05:23:56 +08:00
MYSQL_DISABLE_MQ ;
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2002-11-11 20:54:06 +08:00
/* check explain */
if ( MySG ( trace_mode ) ) {
2008-11-29 04:23:49 +08:00
if ( ! strncasecmp ( " select " , query , 6 ) ) {
2002-11-11 20:54:06 +08:00
MYSQL_ROW row ;
2010-10-04 18:08:10 +08:00
2007-02-24 10:17:47 +08:00
char * newquery ;
2014-03-23 11:30:09 +08:00
int newql = spprintf ( & newquery , 0 , " EXPLAIN %s " , query ) ;
2007-10-06 05:23:56 +08:00
mysql_real_query ( mysql - > conn , newquery , newql ) ;
2002-11-11 20:54:06 +08:00
efree ( newquery ) ;
2007-10-06 05:23:56 +08:00
if ( mysql_errno ( mysql - > conn ) ) {
php_error_docref ( " http://www.mysql.com/doc " TSRMLS_CC , E_WARNING , " %s " , mysql_error ( mysql - > conn ) ) ;
2002-11-11 20:54:06 +08:00
RETURN_FALSE ;
}
else {
2007-10-06 05:23:56 +08:00
mysql_result = mysql_use_result ( mysql - > conn ) ;
2002-11-12 00:54:26 +08:00
while ( ( row = mysql_fetch_row ( mysql_result ) ) ) {
2002-11-11 20:54:06 +08:00
if ( ! strcmp ( " ALL " , row [ 1 ] ) ) {
2003-04-10 12:35:39 +08:00
php_error_docref ( " http://www.mysql.com/doc " TSRMLS_CC , E_WARNING , " Your query requires a full tablescan (table %s, %s rows affected). Use EXPLAIN to optimize your query. " , row [ 0 ] , row [ 6 ] ) ;
} else if ( ! strcmp ( " INDEX " , row [ 1 ] ) ) {
php_error_docref ( " http://www.mysql.com/doc " TSRMLS_CC , E_WARNING , " Your query requires a full indexscan (table %s, %s rows affected). Use EXPLAIN to optimize your query. " , row [ 0 ] , row [ 6 ] ) ;
2002-11-11 20:54:06 +08:00
}
}
mysql_free_result ( mysql_result ) ;
}
2010-10-04 18:08:10 +08:00
}
2002-11-11 20:54:06 +08:00
} /* end explain */
2007-10-06 05:23:56 +08:00
# endif
2002-11-11 20:54:06 +08:00
2001-03-14 05:42:43 +08:00
/* mysql_query is binary unsafe, use mysql_real_query */
2002-03-24 18:57:40 +08:00
# if MYSQL_VERSION_ID > 32199
2008-11-29 04:23:49 +08:00
if ( mysql_real_query ( mysql - > conn , query , query_len ) ! = 0 ) {
2002-11-11 20:54:06 +08:00
/* check possible error */
if ( MySG ( trace_mode ) ) {
2007-10-06 05:23:56 +08:00
if ( mysql_errno ( mysql - > conn ) ) {
2010-10-04 18:08:10 +08:00
php_error_docref ( " http://www.mysql.com/doc " TSRMLS_CC , E_WARNING , " %s " , mysql_error ( mysql - > conn ) ) ;
2002-11-11 20:54:06 +08:00
}
}
2001-03-14 05:42:43 +08:00
RETURN_FALSE ;
}
# else
2008-11-29 04:23:49 +08:00
if ( mysql_query ( mysql - > conn , query ) ! = 0 ) {
2002-11-11 20:54:06 +08:00
/* check possible error */
if ( MySG ( trace_mode ) ) {
2007-10-06 05:23:56 +08:00
if ( mysql_errno ( mysql - > conn ) ) {
2010-10-04 18:08:10 +08:00
php_error_docref ( " http://www.mysql.com/doc " TSRMLS_CC , E_WARNING , " %s " , mysql_error ( mysql - > conn ) ) ;
2002-11-11 20:54:06 +08:00
}
}
2001-03-14 05:42:43 +08:00
RETURN_FALSE ;
}
# endif
if ( use_store = = MYSQL_USE_RESULT ) {
2014-03-23 11:30:09 +08:00
mysql_result = mysql_use_result ( mysql - > conn ) ;
2001-03-14 05:42:43 +08:00
} else {
2014-03-23 11:30:09 +08:00
mysql_result = mysql_store_result ( mysql - > conn ) ;
2001-03-14 05:42:43 +08:00
}
if ( ! mysql_result ) {
2007-10-06 05:23:56 +08:00
if ( PHP_MYSQL_VALID_RESULT ( mysql - > conn ) ) { /* query should have returned rows */
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to save result set " ) ;
2001-03-14 05:42:43 +08:00
RETURN_FALSE ;
} else {
RETURN_TRUE ;
}
}
2002-11-11 20:54:06 +08:00
MySG ( result_allocated ) + + ;
2001-03-14 05:42:43 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql_result , le_result ) ;
2001-03-14 06:52:53 +08:00
if ( use_store = = MYSQL_USE_RESULT ) {
2014-03-23 11:30:09 +08:00
mysql - > active_result_res = Z_RES_P ( return_value ) ;
2014-04-09 21:02:13 +08:00
Z_ADDREF_P ( return_value ) ;
2001-03-14 06:52:53 +08:00
}
2001-03-14 05:42:43 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-03-14 05:42:43 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_do_query
*/
2001-03-14 06:52:53 +08:00
static void php_mysql_do_query ( INTERNAL_FUNCTION_PARAMETERS , int use_store )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * query ;
2014-08-27 23:31:24 +08:00
size_t query_len ;
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
2014-03-23 11:30:09 +08:00
php_mysql_conn * mysql ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & query , & query_len , & mysql_link ) = = FAILURE ) {
return ;
}
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2008-11-29 04:23:49 +08:00
2014-03-23 11:30:09 +08:00
php_mysql_do_query_general ( mysql , query , query_len , NULL , use_store , return_value TSRMLS_CC ) ;
2001-03-14 06:52:53 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
2001-03-14 06:52:53 +08:00
2003-04-11 17:53:01 +08:00
/* {{{ proto resource mysql_query(string query [, int link_identifier])
2001-11-09 06:05:56 +08:00
Sends an SQL query to MySQL */
2001-03-14 06:52:53 +08:00
PHP_FUNCTION ( mysql_query )
{
php_mysql_do_query ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQL_STORE_RESULT ) ;
}
/* }}} */
2003-04-11 17:53:01 +08:00
/* {{{ proto resource mysql_unbuffered_query(string query [, int link_identifier])
2001-11-09 06:05:56 +08:00
Sends an SQL query to MySQL , without fetching and buffering the result rows */
2001-03-14 06:52:53 +08:00
PHP_FUNCTION ( mysql_unbuffered_query )
{
php_mysql_do_query ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQL_USE_RESULT ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto resource mysql_db_query(string database_name, string query [, int link_identifier])
2001-11-09 06:05:56 +08:00
Sends an SQL query to MySQL */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_db_query )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db , * query ;
2014-08-27 23:31:24 +08:00
size_t db_len , query_len ;
2014-03-23 11:30:09 +08:00
php_mysql_conn * mysql ;
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss|r " , & db , & db_len , & query , & query_len , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2009-03-25 18:27:38 +08:00
php_error_docref ( NULL TSRMLS_CC , E_DEPRECATED , " This function is deprecated; use mysql_query() instead " ) ;
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
php_mysql_do_query_general ( mysql , query , query_len , db , MYSQL_STORE_RESULT , return_value TSRMLS_CC ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto resource mysql_list_dbs([int link_identifier])
1999-04-22 05:26:10 +08:00
List databases available on a MySQL server */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_list_dbs )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
2014-03-23 11:30:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_DEPRECATED , " This function is deprecated; use mysql_query() with SHOW DATABASES instead " ) ;
1999-09-04 03:13:37 +08:00
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2014-03-23 11:30:09 +08:00
if ( ( mysql_result = mysql_list_dbs ( mysql - > conn , NULL ) ) = = NULL ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to save MySQL query result " ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2014-03-23 11:30:09 +08:00
2011-08-31 19:11:08 +08:00
MySG ( result_allocated ) + + ;
1999-09-04 03:54:12 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql_result , le_result ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto resource mysql_list_tables(string database_name [, int link_identifier])
1999-04-22 05:26:10 +08:00
List tables in a MySQL database */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_list_tables )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db ;
2014-08-27 21:31:48 +08:00
size_t db_len ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & db , & db_len , & mysql_link ) = = FAILURE ) {
return ;
}
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( ! php_mysql_select_db ( mysql , db TSRMLS_CC ) ) {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2014-03-23 11:30:09 +08:00
if ( ( mysql_result = mysql_list_tables ( mysql - > conn , NULL ) ) = = NULL ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to save MySQL query result " ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2011-08-31 19:11:08 +08:00
MySG ( result_allocated ) + + ;
1999-09-04 03:54:12 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql_result , le_result ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-11-09 04:23:33 +08:00
/* {{{ proto resource mysql_list_fields(string database_name, string table_name [, int link_identifier])
1999-04-22 05:26:10 +08:00
List MySQL result fields */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_list_fields )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
char * db , * table ;
2014-08-27 21:31:48 +08:00
size_t db_len , table_len ;
2008-11-29 04:23:49 +08:00
zval * mysql_link = NULL ;
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " ss|r " , & db , & db_len , & table , & table_len , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2002-03-24 18:57:40 +08:00
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
if ( ! php_mysql_select_db ( mysql , db TSRMLS_CC ) ) {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2008-11-29 04:23:49 +08:00
if ( ( mysql_result = mysql_list_fields ( mysql - > conn , table , NULL ) ) = = NULL ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to save MySQL query result " ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2011-08-31 19:11:08 +08:00
MySG ( result_allocated ) + + ;
1999-09-04 03:54:12 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql_result , le_result ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2002-03-24 18:57:40 +08:00
/* {{{ proto resource mysql_list_processes([int link_identifier])
2002-03-25 01:19:19 +08:00
Returns a result set describing the current server threads */
2002-03-24 18:57:40 +08:00
PHP_FUNCTION ( mysql_list_processes )
{
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-24 18:57:40 +08:00
MYSQL_RES * mysql_result ;
2002-03-25 09:14:30 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-24 18:57:40 +08:00
}
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2007-10-06 05:23:56 +08:00
mysql_result = mysql_list_processes ( mysql - > conn ) ;
2002-03-25 09:14:30 +08:00
if ( mysql_result = = NULL ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to save MySQL query result " ) ;
2002-03-24 18:57:40 +08:00
RETURN_FALSE ;
}
2002-03-25 09:14:30 +08:00
2011-08-31 19:11:08 +08:00
MySG ( result_allocated ) + + ;
2002-03-24 18:57:40 +08:00
ZEND_REGISTER_RESOURCE ( return_value , mysql_result , le_result ) ;
}
/* }}} */
1999-04-22 05:26:10 +08:00
/* {{{ proto string mysql_error([int link_identifier])
Returns the text of the error message from previous MySQL operation */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_error )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
if ( MySG ( default_link ) = = NULL ) {
if ( MySG ( connect_error ) ! = NULL ) {
RETURN_STRING ( MySG ( connect_error ) ) ;
2008-11-29 04:23:49 +08:00
} else {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
}
2014-03-23 11:30:09 +08:00
mysql = ( php_mysql_conn * ) MySG ( default_link ) - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
RETURN_STRING ( ( char * ) mysql_error ( mysql - > conn ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
/* {{{ proto int mysql_errno([int link_identifier])
Returns the number of the error message from previous MySQL operation */
1999-08-18 06:06:55 +08:00
# ifdef HAVE_MYSQL_ERRNO
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_errno )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
}
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
if ( MySG ( default_link ) = = NULL ) {
if ( MySG ( connect_error ) ! = NULL ) {
2014-08-26 01:24:55 +08:00
RETURN_LONG ( MySG ( connect_errno ) ) ;
2008-11-29 04:23:49 +08:00
} else {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
}
2014-03-23 11:30:09 +08:00
mysql = ( php_mysql_conn * ) MySG ( default_link ) - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( mysql_errno ( mysql - > conn ) ) ;
1999-04-22 05:26:10 +08:00
}
# endif
/* }}} */
/* {{{ proto int mysql_affected_rows([int link_identifier])
2001-11-09 06:05:56 +08:00
Gets number of affected rows in previous MySQL operation */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_affected_rows )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
1999-04-22 05:26:10 +08:00
/* conversion from int64 to long happing here */
2014-08-26 17:23:25 +08:00
RETURN_LONG ( ( zend_long ) mysql_affected_rows ( mysql - > conn ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-08-21 04:50:54 +08:00
/* {{{ proto string mysql_escape_string(string to_be_escaped)
2000-10-12 02:27:21 +08:00
Escape string for mysql query */
PHP_FUNCTION ( mysql_escape_string )
{
2008-11-29 04:23:49 +08:00
char * str ;
2014-08-27 21:31:48 +08:00
size_t str_len ;
2014-03-23 11:30:09 +08:00
zend_string * escaped_str ;
2007-10-06 05:23:56 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & str , & str_len ) = = FAILURE ) {
return ;
2000-10-12 02:27:21 +08:00
}
2008-11-29 04:23:49 +08:00
2000-10-12 02:27:21 +08:00
/* assume worst case situation, which is 2x of the original string.
* we don ' t realloc ( ) down to the real size since it ' d most probably not
* be worth it
*/
2014-08-26 01:24:55 +08:00
escaped_str = zend_string_alloc ( str_len * 2 , 0 ) ;
2014-03-23 11:30:09 +08:00
escaped_str - > len = mysql_escape_string ( escaped_str - > val , str , str_len ) ;
2002-08-08 06:02:11 +08:00
2011-01-25 20:51:29 +08:00
php_error_docref ( " function.mysql-real-escape-string " TSRMLS_CC , E_DEPRECATED , " This function is deprecated; use mysql_real_escape_string() instead. " ) ;
2014-03-23 11:30:09 +08:00
RETURN_STR ( escaped_str ) ;
2000-10-12 02:27:21 +08:00
}
/* }}} */
2002-03-25 02:19:31 +08:00
/* {{{ proto string mysql_real_escape_string(string to_be_escaped [, int link_identifier])
2002-03-25 02:01:41 +08:00
Escape special characters in a string for use in a SQL statement , taking into account the current charset of the connection */
2002-03-25 01:19:19 +08:00
PHP_FUNCTION ( mysql_real_escape_string )
{
char * str ;
2014-08-27 21:31:48 +08:00
size_t str_len ;
2014-03-23 11:30:09 +08:00
zend_string * new_str ;
2002-03-25 01:19:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-25 09:07:23 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|r " , & str , & str_len , & mysql_link ) = = FAILURE ) {
return ;
2002-03-25 01:19:19 +08:00
}
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2002-03-25 09:07:23 +08:00
}
2002-03-25 09:14:30 +08:00
2014-03-23 11:30:09 +08:00
/* assume worst case situation, which is 2x of the original string.
* we don ' t realloc ( ) down to the real size since it ' d most probably not
* be worth it
*/
2014-08-26 01:24:55 +08:00
new_str = zend_string_alloc ( str_len * 2 , 0 ) ;
2014-03-23 11:30:09 +08:00
new_str - > len = mysql_real_escape_string ( mysql - > conn , new_str - > val , str , str_len ) ;
2002-03-25 09:07:23 +08:00
2014-04-03 19:26:23 +08:00
RETURN_NEW_STR ( new_str ) ;
2002-03-25 01:19:19 +08:00
}
/* }}} */
2000-10-12 02:27:21 +08:00
1999-04-22 05:26:10 +08:00
/* {{{ proto int mysql_insert_id([int link_identifier])
2001-11-09 06:05:56 +08:00
Gets the ID generated from the previous INSERT operation */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_insert_id )
1999-04-22 05:26:10 +08:00
{
2001-03-14 05:13:19 +08:00
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! mysql_link ) {
2014-03-23 11:30:09 +08:00
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
2008-11-29 04:23:49 +08:00
}
1999-04-22 05:26:10 +08:00
/* conversion from int64 to long happing here */
2014-08-26 17:23:25 +08:00
RETURN_LONG ( ( zend_long ) mysql_insert_id ( mysql - > conn ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto mixed mysql_result(resource result, int row [, mixed field])
2001-11-09 06:05:56 +08:00
Gets result data */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_result )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result , * field = NULL ;
2014-08-26 01:24:55 +08:00
zend_long row ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
1999-04-22 05:26:10 +08:00
MYSQL_ROW sql_row ;
mysql_row_length_type * sql_row_lengths ;
2007-10-06 05:23:56 +08:00
# endif
1999-09-04 03:13:37 +08:00
int field_offset = 0 ;
1999-04-22 05:26:10 +08:00
2008-11-29 04:23:49 +08:00
/*
johannes TODO :
2013-07-24 07:55:43 +08:00
Do 2 zend_parse_parameters calls instead of type " z " and switch below
2008-11-29 04:23:49 +08:00
Q : String or long first ?
*/
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rl|z " , & result , & row , & field ) = = FAILURE ) {
2008-11-29 04:23:49 +08:00
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
if ( row < 0 | | row > = ( int ) mysql_num_rows ( mysql_result ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Unable to jump to row %pd on MySQL result index %pd " , row , Z_RES_P ( result ) - > handle ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
mysql_data_seek ( mysql_result , row ) ;
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
if ( field ) {
2014-03-23 11:30:09 +08:00
switch ( Z_TYPE_P ( field ) ) {
1999-04-22 05:26:10 +08:00
case IS_STRING : {
2014-03-23 11:30:09 +08:00
int i = 0 ;
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * tmp_field ;
1999-09-24 22:07:15 +08:00
char * table_name , * field_name , * tmp ;
1999-04-22 05:26:10 +08:00
2014-03-23 11:30:09 +08:00
if ( ( tmp = strchr ( Z_STRVAL_P ( field ) , ' . ' ) ) ) {
2008-11-29 04:23:49 +08:00
table_name = estrndup ( Z_STRVAL_P ( field ) , tmp - Z_STRVAL_P ( field ) ) ;
2014-03-23 11:30:09 +08:00
field_name = estrdup ( tmp + 1 ) ;
1999-04-22 05:26:10 +08:00
} else {
table_name = NULL ;
2014-08-26 01:24:55 +08:00
field_name = estrndup ( Z_STRVAL_P ( field ) , Z_STRLEN_P ( field ) ) ;
1999-04-22 05:26:10 +08:00
}
2000-12-03 01:27:11 +08:00
mysql_field_seek ( mysql_result , 0 ) ;
2014-03-23 11:30:09 +08:00
while ( ( tmp_field = mysql_fetch_field ( mysql_result ) ) ) {
2014-06-25 00:42:20 +08:00
if ( ( ! table_name | |
! strncasecmp ( tmp_field - > table , table_name , tmp_field - > table_length ) ) & &
! strncasecmp ( tmp_field - > name , field_name , tmp_field - > name_length ) ) {
1999-04-22 05:26:10 +08:00
field_offset = i ;
break ;
}
i + + ;
}
if ( ! tmp_field ) { /* no match found */
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " %s%s%s not found in MySQL result index %pd " ,
2014-04-09 21:08:52 +08:00
( table_name ? table_name : " " ) , ( table_name ? " . " : " " ) , field_name , Z_RES_P ( result ) - > handle ) ;
1999-04-22 05:26:10 +08:00
efree ( field_name ) ;
if ( table_name ) {
efree ( table_name ) ;
}
RETURN_FALSE ;
}
efree ( field_name ) ;
if ( table_name ) {
efree ( table_name ) ;
}
}
break ;
default :
2014-08-26 03:51:49 +08:00
convert_to_long_ex ( field ) ;
2014-08-26 01:24:55 +08:00
field_offset = Z_LVAL_P ( field ) ;
2014-03-23 11:30:09 +08:00
if ( field_offset < 0 | | field_offset > = ( int ) mysql_num_fields ( mysql_result ) ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad column offset specified " ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
break ;
}
}
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2014-03-23 11:30:09 +08:00
if ( ( sql_row = mysql_fetch_row ( mysql_result ) ) = = NULL
| | ( sql_row_lengths = mysql_fetch_lengths ( mysql_result ) ) = = NULL ) { /* shouldn't happen? */
2007-10-06 05:23:56 +08:00
RETURN_FALSE ;
}
1999-04-22 05:26:10 +08:00
if ( sql_row [ field_offset ] ) {
2012-10-23 18:02:58 +08:00
# if PHP_API_VERSION < 20100412
1999-04-22 05:26:10 +08:00
if ( PG ( magic_quotes_runtime ) ) {
2014-03-23 11:30:09 +08:00
RETVAL_STR ( php_addslashes ( sql_row [ field_offset ] , sql_row_lengths [ field_offset ] , 0 TSRMLS_CC ) ) ;
2010-10-04 18:08:10 +08:00
} else {
2012-10-23 18:02:58 +08:00
# endif
2014-03-23 11:30:09 +08:00
RETVAL_STRINGL ( sql_row [ field_offset ] , sql_row_lengths [ field_offset ] ) ;
2011-07-22 19:25:30 +08:00
# if PHP_API_VERSION < 20100412
1999-04-22 05:26:10 +08:00
}
2012-10-23 18:02:58 +08:00
# endif
1999-04-22 05:26:10 +08:00
} else {
2014-03-23 11:30:09 +08:00
RETURN_NULL ( ) ;
1999-04-22 05:26:10 +08:00
}
2007-10-06 05:23:56 +08:00
# else
mysqlnd_result_fetch_field_data ( mysql_result , field_offset , return_value ) ;
# endif
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto int mysql_num_rows(resource result)
2001-11-09 06:05:56 +08:00
Gets number of rows in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_num_rows )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r " , & result ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
/* conversion from int64 to long happing here */
2014-08-26 17:23:25 +08:00
RETURN_LONG ( ( zend_long ) mysql_num_rows ( mysql_result ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto int mysql_num_fields(resource result)
2001-11-09 06:05:56 +08:00
Gets number of fields in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_num_fields )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r " , & result ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
2010-10-04 18:08:10 +08:00
2014-08-26 01:24:55 +08:00
RETURN_LONG ( mysql_num_fields ( mysql_result ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_fetch_hash
*/
2014-08-26 01:24:55 +08:00
static void php_mysql_fetch_hash ( INTERNAL_FUNCTION_PARAMETERS , zend_long result_type , int expected_args , int into_object )
1999-04-22 05:26:10 +08:00
{
MYSQL_RES * mysql_result ;
2014-03-23 11:30:09 +08:00
zval * res , * ctor_params = NULL ;
2006-08-02 18:04:11 +08:00
zend_class_entry * ce = NULL ;
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
int i ;
MYSQL_FIELD * mysql_field ;
MYSQL_ROW mysql_row ;
mysql_row_length_type * mysql_row_lengths ;
# endif
1999-04-22 05:26:10 +08:00
2005-09-04 12:51:23 +08:00
# ifdef ZEND_ENGINE_2
2004-01-12 10:34:55 +08:00
if ( into_object ) {
2014-03-23 11:30:09 +08:00
zend_string * class_name = NULL ;
2001-04-26 16:22:12 +08:00
2014-03-23 11:30:09 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|Sz " , & res , & class_name , & ctor_params ) = = FAILURE ) {
2004-01-12 10:34:55 +08:00
return ;
}
2008-11-29 04:23:49 +08:00
2004-01-12 10:34:55 +08:00
if ( ZEND_NUM_ARGS ( ) < 2 ) {
ce = zend_standard_class_def ;
} else {
2014-03-23 11:30:09 +08:00
ce = zend_fetch_class ( class_name , ZEND_FETCH_CLASS_AUTO TSRMLS_CC ) ;
2004-01-12 10:34:55 +08:00
}
if ( ! ce ) {
2014-03-23 11:30:09 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Could not find class '%s' " , class_name - > val ) ;
2004-01-12 10:34:55 +08:00
return ;
}
result_type = MYSQL_ASSOC ;
2005-09-04 12:51:23 +08:00
} else
# endif
{
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r|l " , & res , & result_type ) = = FAILURE ) {
2008-11-29 04:23:49 +08:00
return ;
2004-01-12 10:34:55 +08:00
}
2008-11-29 04:23:49 +08:00
if ( ! result_type ) {
/* result_type might have been set outside, so only overwrite when not set */
result_type = MYSQL_BOTH ;
2004-01-12 10:34:55 +08:00
}
1999-04-22 05:26:10 +08:00
}
2003-05-17 03:09:19 +08:00
2009-09-30 22:39:33 +08:00
if ( result_type & ~ MYSQL_BOTH ) {
2007-10-06 05:23:56 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH " ) ;
2007-11-08 21:29:06 +08:00
result_type = MYSQL_BOTH ;
2003-05-17 03:09:19 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , res , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
2008-03-11 04:15:38 +08:00
# ifndef MYSQL_USE_MYSQLND
2007-10-06 05:23:56 +08:00
if ( ( mysql_row = mysql_fetch_row ( mysql_result ) ) = = NULL | |
( mysql_row_lengths = mysql_fetch_lengths ( mysql_result ) ) = = NULL ) {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2003-01-19 03:41:56 +08:00
array_init ( return_value ) ;
2010-10-04 18:08:10 +08:00
2000-12-03 01:27:11 +08:00
mysql_field_seek ( mysql_result , 0 ) ;
2007-10-06 05:23:56 +08:00
for ( mysql_field = mysql_fetch_field ( mysql_result ) , i = 0 ;
mysql_field ;
mysql_field = mysql_fetch_field ( mysql_result ) , i + + )
{
1999-04-22 05:26:10 +08:00
if ( mysql_row [ i ] ) {
2014-03-23 11:30:09 +08:00
zval data ;
1999-07-17 01:19:11 +08:00
2012-10-23 18:02:58 +08:00
# if PHP_API_VERSION < 20100412
1999-04-22 05:26:10 +08:00
if ( PG ( magic_quotes_runtime ) ) {
2014-03-23 11:30:09 +08:00
ZVAL_STR ( & data , php_addslashes ( mysql_row [ i ] , mysql_row_lengths [ i ] , 0 TSRMLS_CC ) ) ;
1999-04-22 05:26:10 +08:00
} else {
2012-10-23 18:02:58 +08:00
# endif
2014-03-23 11:30:09 +08:00
ZVAL_STRINGL ( & data , mysql_row [ i ] , mysql_row_lengths [ i ] ) ;
2012-10-23 18:02:58 +08:00
# if PHP_API_VERSION < 20100412
1999-06-28 23:08:28 +08:00
}
2012-10-23 18:02:58 +08:00
# endif
2003-11-08 01:20:49 +08:00
1999-06-28 23:08:28 +08:00
if ( result_type & MYSQL_NUM ) {
2014-03-23 11:30:09 +08:00
add_index_zval ( return_value , i , & data ) ;
1999-06-28 23:08:28 +08:00
}
if ( result_type & MYSQL_ASSOC ) {
2003-11-08 01:20:49 +08:00
if ( result_type & MYSQL_NUM ) {
2014-03-23 11:30:09 +08:00
Z_ADDREF_P ( & data ) ;
2003-11-08 01:20:49 +08:00
}
2014-03-23 11:30:09 +08:00
add_assoc_zval ( return_value , mysql_field - > name , & data ) ;
1999-04-22 05:26:10 +08:00
}
} else {
2000-05-15 21:46:37 +08:00
/* NULL value. */
2001-12-30 18:00:26 +08:00
if ( result_type & MYSQL_NUM ) {
2001-02-01 05:53:30 +08:00
add_index_null ( return_value , i ) ;
2002-03-29 20:56:25 +08:00
}
2001-12-30 18:00:26 +08:00
2002-03-29 20:56:25 +08:00
if ( result_type & MYSQL_ASSOC ) {
2001-02-01 05:53:30 +08:00
add_assoc_null ( return_value , mysql_field - > name ) ;
2002-03-29 20:56:25 +08:00
}
1999-04-22 05:26:10 +08:00
}
}
2007-10-06 05:23:56 +08:00
# else
2010-05-18 19:50:31 +08:00
mysqlnd_fetch_into ( mysql_result , ( ( result_type & MYSQL_NUM ) ? MYSQLND_FETCH_NUM : 0 ) | ( ( result_type & MYSQL_ASSOC ) ? MYSQLND_FETCH_ASSOC : 0 ) , return_value , MYSQLND_MYSQL ) ;
2007-10-06 05:23:56 +08:00
# endif
2004-01-12 10:34:55 +08:00
2005-09-04 12:51:23 +08:00
# ifdef ZEND_ENGINE_2
2007-10-06 05:23:56 +08:00
/* mysqlnd might return FALSE if no more rows */
2014-04-30 22:32:42 +08:00
if ( into_object & & Z_TYPE_P ( return_value ) ! = IS_FALSE ) {
2014-03-23 11:30:09 +08:00
zval dataset ;
2004-01-12 10:34:55 +08:00
zend_fcall_info fci ;
zend_fcall_info_cache fcc ;
2014-03-23 11:30:09 +08:00
zval retval ;
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZVAL_COPY_VALUE ( & dataset , return_value ) ;
2004-01-12 10:34:55 +08:00
object_and_properties_init ( return_value , ce , NULL ) ;
2014-06-04 06:11:26 +08:00
if ( ! ce - > default_properties_count & & ! ce - > __set ) {
ALLOC_HASHTABLE ( Z_OBJ_P ( return_value ) - > properties ) ;
* Z_OBJ_P ( return_value ) - > properties = * Z_ARRVAL ( dataset ) ;
efree ( Z_ARR ( dataset ) ) ;
} else {
zend_merge_properties ( return_value , Z_ARRVAL ( dataset ) TSRMLS_CC ) ;
zval_dtor ( & dataset ) ;
}
2010-10-04 18:08:10 +08:00
2004-01-12 10:34:55 +08:00
if ( ce - > constructor ) {
fci . size = sizeof ( fci ) ;
fci . function_table = & ce - > function_table ;
2014-03-23 11:30:09 +08:00
ZVAL_UNDEF ( & fci . function_name ) ;
2004-01-12 10:34:55 +08:00
fci . symbol_table = NULL ;
2014-03-28 06:11:22 +08:00
fci . object = Z_OBJ_P ( return_value ) ;
2014-03-23 11:30:09 +08:00
fci . retval = & retval ;
2014-04-08 02:46:45 +08:00
fci . params = NULL ;
fci . param_count = 0 ;
fci . no_separation = 1 ;
2004-01-12 10:34:55 +08:00
if ( ctor_params & & Z_TYPE_P ( ctor_params ) ! = IS_NULL ) {
2014-04-08 02:46:45 +08:00
if ( zend_fcall_info_args ( & fci , ctor_params TSRMLS_CC ) = = FAILURE ) {
2004-01-12 10:34:55 +08:00
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that ' s not an array could be
2010-10-04 18:08:10 +08:00
* by mistake and the other way round is possible , too . The
2004-01-12 10:34:55 +08:00
* single value is an array . Also we ' d have to make that one
* argument passed by reference .
*/
2006-05-10 08:00:13 +08:00
zend_throw_exception ( zend_exception_get_default ( TSRMLS_C ) , " Parameter ctor_params must be an array " , 0 TSRMLS_CC ) ;
2004-01-12 10:34:55 +08:00
return ;
}
}
fcc . initialized = 1 ;
fcc . function_handler = ce - > constructor ;
fcc . calling_scope = EG ( scope ) ;
2008-07-25 16:23:07 +08:00
fcc . called_scope = Z_OBJCE_P ( return_value ) ;
2014-03-28 06:11:22 +08:00
fcc . object = Z_OBJ_P ( return_value ) ;
2010-10-04 18:08:10 +08:00
2004-01-12 10:34:55 +08:00
if ( zend_call_function ( & fci , & fcc TSRMLS_CC ) = = FAILURE ) {
2014-03-23 11:30:09 +08:00
zend_throw_exception_ex ( zend_exception_get_default ( TSRMLS_C ) , 0 TSRMLS_CC , " Could not execute %s::%s() " , ce - > name - > val , ce - > constructor - > common . function_name - > val ) ;
2004-01-12 10:34:55 +08:00
} else {
2014-05-03 16:06:27 +08:00
if ( ! Z_ISUNDEF ( retval ) ) {
2014-03-23 11:30:09 +08:00
zval_ptr_dtor ( & retval ) ;
2004-01-12 10:34:55 +08:00
}
}
if ( fci . params ) {
efree ( fci . params ) ;
}
} else if ( ctor_params ) {
2014-03-23 11:30:09 +08:00
zend_throw_exception_ex ( zend_exception_get_default ( TSRMLS_C ) , 0 TSRMLS_CC , " Class %s does not have a constructor hence you cannot use ctor_params " , ce - > name - > val ) ;
2004-01-12 10:34:55 +08:00
}
}
2005-09-04 12:51:23 +08:00
# endif
1999-04-22 05:26:10 +08:00
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-06-04 18:45:54 +08:00
2003-06-10 22:06:20 +08:00
/* {{{ proto array mysql_fetch_row(resource result)
2001-11-09 06:05:56 +08:00
Gets a result row as an enumerated array */
1999-06-28 23:08:28 +08:00
PHP_FUNCTION ( mysql_fetch_row )
{
2004-01-12 10:34:55 +08:00
php_mysql_fetch_hash ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQL_NUM , 1 , 0 ) ;
1999-06-28 23:08:28 +08:00
}
/* }}} */
2004-01-12 10:34:55 +08:00
/* {{{ proto object mysql_fetch_object(resource result [, string class_name [, NULL|array ctor_params]])
1999-04-22 05:26:10 +08:00
Fetch a result row as an object */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_fetch_object )
1999-04-22 05:26:10 +08:00
{
2004-01-12 10:34:55 +08:00
php_mysql_fetch_hash ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQL_ASSOC , 2 , 1 ) ;
2001-07-29 03:02:53 +08:00
if ( Z_TYPE_P ( return_value ) = = IS_ARRAY ) {
2002-03-13 04:18:01 +08:00
object_and_properties_init ( return_value , ZEND_STANDARD_CLASS_DEF_PTR , Z_ARRVAL_P ( return_value ) ) ;
1999-04-22 05:26:10 +08:00
}
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto array mysql_fetch_array(resource result [, int result_type])
2001-11-09 06:05:56 +08:00
Fetch a result row as an array ( associative , numeric or both ) */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_fetch_array )
1999-04-22 05:26:10 +08:00
{
2004-01-12 10:34:55 +08:00
php_mysql_fetch_hash ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 , 2 , 0 ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto array mysql_fetch_assoc(resource result)
2000-09-21 05:43:57 +08:00
Fetch a result row as an associative array */
PHP_FUNCTION ( mysql_fetch_assoc )
{
2004-01-12 10:34:55 +08:00
php_mysql_fetch_hash ( INTERNAL_FUNCTION_PARAM_PASSTHRU , MYSQL_ASSOC , 1 , 0 ) ;
2000-09-21 05:43:57 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto bool mysql_data_seek(resource result, int row_number)
1999-04-22 05:26:10 +08:00
Move internal result pointer */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_data_seek )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
2014-08-26 01:24:55 +08:00
zend_long offset ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rl " , & result , & offset ) ) {
2008-11-29 04:23:49 +08:00
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
2014-03-23 11:30:09 +08:00
if ( offset < 0 | | offset > = ( int ) mysql_num_rows ( mysql_result ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Offset %pd is invalid for MySQL result index %pd (or the query data is unbuffered) " , offset , Z_RES_P ( result ) - > handle ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
mysql_data_seek ( mysql_result , offset ) ;
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto array mysql_fetch_lengths(resource result)
2001-11-09 06:05:56 +08:00
Gets max data size of each column in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_fetch_lengths )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
mysql_row_length_type * lengths ;
int num_fields ;
int i ;
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r " , & result ) = = FAILURE ) {
2010-10-04 18:08:10 +08:00
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
1999-04-22 05:26:10 +08:00
if ( ( lengths = mysql_fetch_lengths ( mysql_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2003-01-19 03:41:56 +08:00
array_init ( return_value ) ;
1999-04-22 05:26:10 +08:00
num_fields = mysql_num_fields ( mysql_result ) ;
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
for ( i = 0 ; i < num_fields ; i + + ) {
2014-08-26 01:24:55 +08:00
add_index_long ( return_value , i , lengths [ i ] ) ;
1999-04-22 05:26:10 +08:00
}
}
/* }}} */
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_get_field_name
*/
1999-09-04 03:54:12 +08:00
static char * php_mysql_get_field_name ( int field_type )
1999-04-22 05:26:10 +08:00
{
switch ( field_type ) {
case FIELD_TYPE_STRING :
case FIELD_TYPE_VAR_STRING :
return " string " ;
break ;
2008-03-11 04:15:38 +08:00
# if MYSQL_VERSION_ID > 50002 || defined(MYSQL_USE_MYSQLND)
2007-10-06 05:23:56 +08:00
case MYSQL_TYPE_BIT :
# endif
2001-01-12 16:03:24 +08:00
# ifdef MYSQL_HAS_TINY
1999-04-22 05:26:10 +08:00
case FIELD_TYPE_TINY :
# endif
case FIELD_TYPE_SHORT :
case FIELD_TYPE_LONG :
case FIELD_TYPE_LONGLONG :
case FIELD_TYPE_INT24 :
return " int " ;
break ;
case FIELD_TYPE_FLOAT :
case FIELD_TYPE_DOUBLE :
case FIELD_TYPE_DECIMAL :
2005-12-05 21:16:48 +08:00
# ifdef FIELD_TYPE_NEWDECIMAL
case FIELD_TYPE_NEWDECIMAL :
# endif
1999-04-22 05:26:10 +08:00
return " real " ;
break ;
case FIELD_TYPE_TIMESTAMP :
return " timestamp " ;
break ;
2001-01-31 08:55:28 +08:00
# ifdef MYSQL_HAS_YEAR
case FIELD_TYPE_YEAR :
return " year " ;
break ;
# endif
1999-04-22 05:26:10 +08:00
case FIELD_TYPE_DATE :
2005-12-05 21:16:48 +08:00
# ifdef FIELD_TYPE_NEWDATE
case FIELD_TYPE_NEWDATE :
# endif
1999-04-22 05:26:10 +08:00
return " date " ;
break ;
case FIELD_TYPE_TIME :
return " time " ;
break ;
2005-12-05 21:16:48 +08:00
case FIELD_TYPE_SET :
return " set " ;
break ;
case FIELD_TYPE_ENUM :
return " enum " ;
break ;
# ifdef FIELD_TYPE_GEOMETRY
case FIELD_TYPE_GEOMETRY :
return " geometry " ;
break ;
# endif
1999-04-22 05:26:10 +08:00
case FIELD_TYPE_DATETIME :
return " datetime " ;
break ;
case FIELD_TYPE_TINY_BLOB :
case FIELD_TYPE_MEDIUM_BLOB :
case FIELD_TYPE_LONG_BLOB :
case FIELD_TYPE_BLOB :
return " blob " ;
break ;
case FIELD_TYPE_NULL :
return " null " ;
break ;
default :
return " unknown " ;
break ;
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-06-04 18:45:54 +08:00
2003-06-10 22:06:20 +08:00
/* {{{ proto object mysql_fetch_field(resource result [, int field_offset])
2001-11-09 06:05:56 +08:00
Gets column information from a result and return as an object */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_fetch_field )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
2014-08-26 01:24:55 +08:00
zend_long field = 0 ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * mysql_field ;
2010-10-04 18:08:10 +08:00
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r|l " , & result , & field ) = = FAILURE ) {
2008-11-29 04:23:49 +08:00
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
2009-02-19 00:34:47 +08:00
if ( ZEND_NUM_ARGS ( ) > 1 ) {
2014-03-23 11:30:09 +08:00
if ( field < 0 | | field > = ( int ) mysql_num_fields ( mysql_result ) ) {
2002-08-24 18:53:40 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Bad field offset " ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
mysql_field_seek ( mysql_result , field ) ;
1999-04-22 05:26:10 +08:00
}
2014-03-23 11:30:09 +08:00
if ( ( mysql_field = mysql_fetch_field ( mysql_result ) ) = = NULL ) {
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2003-01-30 10:33:16 +08:00
object_init ( return_value ) ;
1999-04-22 05:26:10 +08:00
2014-06-23 19:12:15 +08:00
# if MYSQL_USE_MYSQLND
2014-08-26 01:24:55 +08:00
add_property_str ( return_value , " name " , zend_string_copy ( mysql_field - > sname ) ) ;
2014-06-23 19:12:15 +08:00
# else
2014-06-25 00:42:20 +08:00
add_property_stringl ( return_value , " name " , ( mysql_field - > name ? mysql_field - > name : " " ) , mysql_field - > name_length ) ;
2014-06-23 19:12:15 +08:00
# endif
2014-06-25 00:42:20 +08:00
add_property_stringl ( return_value , " table " , ( mysql_field - > table ? mysql_field - > table : " " ) , mysql_field - > table_length ) ;
add_property_stringl ( return_value , " def " , ( mysql_field - > def ? mysql_field - > def : " " ) , mysql_field - > def_length ) ;
2014-08-26 01:24:55 +08:00
add_property_long ( return_value , " max_length " , mysql_field - > max_length ) ;
add_property_long ( return_value , " not_null " , IS_NOT_NULL ( mysql_field - > flags ) ? 1 : 0 ) ;
add_property_long ( return_value , " primary_key " , IS_PRI_KEY ( mysql_field - > flags ) ? 1 : 0 ) ;
add_property_long ( return_value , " multiple_key " , ( mysql_field - > flags & MULTIPLE_KEY_FLAG ? 1 : 0 ) ) ;
add_property_long ( return_value , " unique_key " , ( mysql_field - > flags & UNIQUE_KEY_FLAG ? 1 : 0 ) ) ;
add_property_long ( return_value , " numeric " , IS_NUM ( mysql_field - > type ) ? 1 : 0 ) ;
add_property_long ( return_value , " blob " , IS_BLOB ( mysql_field - > flags ) ? 1 : 0 ) ;
2014-04-15 19:40:40 +08:00
add_property_string ( return_value , " type " , php_mysql_get_field_name ( mysql_field - > type ) ) ;
2014-08-26 01:24:55 +08:00
add_property_long ( return_value , " unsigned " , ( mysql_field - > flags & UNSIGNED_FLAG ? 1 : 0 ) ) ;
add_property_long ( return_value , " zerofill " , ( mysql_field - > flags & ZEROFILL_FLAG ? 1 : 0 ) ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto bool mysql_field_seek(resource result, int field_offset)
2001-11-09 06:05:56 +08:00
Sets result pointer to a specific field offset */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_seek )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
2014-08-26 01:24:55 +08:00
zend_long offset ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2010-10-04 18:08:10 +08:00
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rl " , & result , & offset ) = = FAILURE ) {
2008-11-29 04:23:49 +08:00
return ;
2010-10-04 18:08:10 +08:00
}
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
2014-03-23 11:30:09 +08:00
if ( offset < 0 | | offset > = ( int ) mysql_num_fields ( mysql_result ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Field %pd is invalid for MySQL result index %pd " , offset , Z_RES_P ( result ) - > handle ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
mysql_field_seek ( mysql_result , offset ) ;
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
}
/* }}} */
2000-02-26 11:20:55 +08:00
# define PHP_MYSQL_FIELD_NAME 1
# define PHP_MYSQL_FIELD_TABLE 2
# define PHP_MYSQL_FIELD_LEN 3
# define PHP_MYSQL_FIELD_TYPE 4
# define PHP_MYSQL_FIELD_FLAGS 5
2010-10-04 18:08:10 +08:00
2001-06-05 21:12:10 +08:00
/* {{{ php_mysql_field_info
*/
1999-09-04 03:54:12 +08:00
static void php_mysql_field_info ( INTERNAL_FUNCTION_PARAMETERS , int entry_type )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
2014-08-26 01:24:55 +08:00
zend_long field ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2008-04-16 20:57:38 +08:00
const MYSQL_FIELD * mysql_field = { 0 } ;
1999-04-22 05:26:10 +08:00
char buf [ 512 ] ;
int len ;
2014-08-26 01:24:55 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " rl " , & result , & field ) = = FAILURE ) {
2008-11-29 04:23:49 +08:00
return ;
1999-04-22 05:26:10 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
if ( field < 0 | | field > = ( int ) mysql_num_fields ( mysql_result ) ) {
2014-08-24 08:35:34 +08:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Field %pd is invalid for MySQL result index %pd " , field , Z_RES_P ( result ) - > handle ) ;
1999-04-22 05:26:10 +08:00
RETURN_FALSE ;
}
2008-11-29 04:23:49 +08:00
mysql_field_seek ( mysql_result , field ) ;
1999-04-22 05:26:10 +08:00
if ( ( mysql_field = mysql_fetch_field ( mysql_result ) ) = = NULL ) {
RETURN_FALSE ;
}
2010-10-04 18:08:10 +08:00
1999-04-22 05:26:10 +08:00
switch ( entry_type ) {
2000-02-26 11:20:55 +08:00
case PHP_MYSQL_FIELD_NAME :
2014-06-23 19:12:15 +08:00
# ifdef MYSQL_USE_MYSQLND
2014-08-26 01:24:55 +08:00
RETVAL_STR ( zend_string_copy ( mysql_field - > sname ) ) ;
2014-06-23 19:12:15 +08:00
# else
2014-03-23 11:30:09 +08:00
RETVAL_STRING ( mysql_field - > name ) ;
2014-06-23 19:12:15 +08:00
# endif
1999-04-22 05:26:10 +08:00
break ;
2000-02-26 11:20:55 +08:00
case PHP_MYSQL_FIELD_TABLE :
2014-03-23 11:30:09 +08:00
RETVAL_STRING ( mysql_field - > table ) ;
1999-04-22 05:26:10 +08:00
break ;
2000-02-26 11:20:55 +08:00
case PHP_MYSQL_FIELD_LEN :
2014-08-26 01:24:55 +08:00
RETVAL_LONG ( mysql_field - > length ) ;
1999-04-22 05:26:10 +08:00
break ;
2000-02-26 11:20:55 +08:00
case PHP_MYSQL_FIELD_TYPE :
2014-04-02 18:34:44 +08:00
RETVAL_STRING ( php_mysql_get_field_name ( mysql_field - > type ) ) ;
1999-04-22 05:26:10 +08:00
break ;
2000-02-26 11:20:55 +08:00
case PHP_MYSQL_FIELD_FLAGS :
2002-10-09 21:05:42 +08:00
memcpy ( buf , " " , sizeof ( " " ) ) ;
1999-04-22 05:26:10 +08:00
# ifdef IS_NOT_NULL
if ( IS_NOT_NULL ( mysql_field - > flags ) ) {
strcat ( buf , " not_null " ) ;
}
# endif
# ifdef IS_PRI_KEY
if ( IS_PRI_KEY ( mysql_field - > flags ) ) {
strcat ( buf , " primary_key " ) ;
}
# endif
# ifdef UNIQUE_KEY_FLAG
if ( mysql_field - > flags & UNIQUE_KEY_FLAG ) {
strcat ( buf , " unique_key " ) ;
}
# endif
# ifdef MULTIPLE_KEY_FLAG
if ( mysql_field - > flags & MULTIPLE_KEY_FLAG ) {
strcat ( buf , " multiple_key " ) ;
}
# endif
# ifdef IS_BLOB
if ( IS_BLOB ( mysql_field - > flags ) ) {
strcat ( buf , " blob " ) ;
}
# endif
# ifdef UNSIGNED_FLAG
if ( mysql_field - > flags & UNSIGNED_FLAG ) {
strcat ( buf , " unsigned " ) ;
}
# endif
# ifdef ZEROFILL_FLAG
if ( mysql_field - > flags & ZEROFILL_FLAG ) {
strcat ( buf , " zerofill " ) ;
}
# endif
# ifdef BINARY_FLAG
if ( mysql_field - > flags & BINARY_FLAG ) {
strcat ( buf , " binary " ) ;
}
# endif
# ifdef ENUM_FLAG
if ( mysql_field - > flags & ENUM_FLAG ) {
strcat ( buf , " enum " ) ;
}
# endif
2001-10-08 14:28:16 +08:00
# ifdef SET_FLAG
if ( mysql_field - > flags & SET_FLAG ) {
strcat ( buf , " set " ) ;
}
# endif
1999-04-22 05:26:10 +08:00
# ifdef AUTO_INCREMENT_FLAG
if ( mysql_field - > flags & AUTO_INCREMENT_FLAG ) {
strcat ( buf , " auto_increment " ) ;
}
# endif
# ifdef TIMESTAMP_FLAG
if ( mysql_field - > flags & TIMESTAMP_FLAG ) {
strcat ( buf , " timestamp " ) ;
}
# endif
len = strlen ( buf ) ;
/* remove trailing space, if present */
if ( len & & buf [ len - 1 ] = = ' ' ) {
buf [ len - 1 ] = 0 ;
len - - ;
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
RETVAL_STRINGL ( buf , len ) ;
1999-04-22 05:26:10 +08:00
break ;
default :
RETURN_FALSE ;
}
}
2001-06-05 21:12:10 +08:00
/* }}} */
1999-06-04 18:45:54 +08:00
2003-06-10 22:06:20 +08:00
/* {{{ proto string mysql_field_name(resource result, int field_index)
2001-11-09 06:05:56 +08:00
Gets the name of the specified field in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_name )
1999-04-22 05:26:10 +08:00
{
2000-12-03 01:27:11 +08:00
php_mysql_field_info ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_MYSQL_FIELD_NAME ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto string mysql_field_table(resource result, int field_offset)
2001-11-09 06:05:56 +08:00
Gets name of the table the specified field is in */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_table )
1999-04-22 05:26:10 +08:00
{
2000-12-03 01:27:11 +08:00
php_mysql_field_info ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_MYSQL_FIELD_TABLE ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto int mysql_field_len(resource result, int field_offset)
1999-04-22 05:26:10 +08:00
Returns the length of the specified field */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_len )
1999-04-22 05:26:10 +08:00
{
2000-12-03 01:27:11 +08:00
php_mysql_field_info ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_MYSQL_FIELD_LEN ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto string mysql_field_type(resource result, int field_offset)
2001-11-09 06:05:56 +08:00
Gets the type of the specified field in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_type )
1999-04-22 05:26:10 +08:00
{
2000-12-03 01:27:11 +08:00
php_mysql_field_info ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_MYSQL_FIELD_TYPE ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto string mysql_field_flags(resource result, int field_offset)
2001-11-09 06:05:56 +08:00
Gets the flags associated with the specified field in a result */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_field_flags )
1999-04-22 05:26:10 +08:00
{
2000-12-03 01:27:11 +08:00
php_mysql_field_info ( INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_MYSQL_FIELD_FLAGS ) ;
1999-04-22 05:26:10 +08:00
}
/* }}} */
2003-06-10 22:06:20 +08:00
/* {{{ proto bool mysql_free_result(resource result)
1999-04-22 05:26:10 +08:00
Free result memory */
1999-05-21 18:06:25 +08:00
PHP_FUNCTION ( mysql_free_result )
1999-04-22 05:26:10 +08:00
{
2008-11-29 04:23:49 +08:00
zval * result ;
1999-04-22 05:26:10 +08:00
MYSQL_RES * mysql_result ;
2008-11-29 04:23:49 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " r " , & result ) = = FAILURE ) {
return ;
1999-04-22 05:26:10 +08:00
}
2002-03-24 18:57:40 +08:00
2014-03-23 11:30:09 +08:00
ZEND_FETCH_RESOURCE ( mysql_result , MYSQL_RES * , result , - 1 , " MySQL result " , le_result ) ;
1999-09-04 03:13:37 +08:00
2014-03-23 11:30:09 +08:00
zend_list_close ( Z_RES_P ( result ) ) ;
1999-04-22 05:26:10 +08:00
RETURN_TRUE ;
}
/* }}} */
2002-03-25 20:09:38 +08:00
/* {{{ proto bool mysql_ping([int link_identifier])
2002-03-25 01:34:20 +08:00
Ping a server connection . If no connection then reconnect . */
PHP_FUNCTION ( mysql_ping )
{
php_mysql_conn * mysql ;
2014-03-23 11:30:09 +08:00
zval * mysql_link = NULL ;
2002-03-25 01:34:20 +08:00
2014-03-23 11:30:09 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |r " , & mysql_link ) = = FAILURE ) {
2002-03-25 07:33:07 +08:00
return ;
2002-03-25 01:34:20 +08:00
}
2010-10-04 18:08:10 +08:00
2014-03-23 11:30:09 +08:00
if ( ! mysql_link ) {
zend_resource * res = php_mysql_get_default_link ( INTERNAL_FUNCTION_PARAM_PASSTHRU ) ;
CHECK_LINK ( res ) ;
mysql = ( php_mysql_conn * ) res - > ptr ;
} else {
ZEND_FETCH_RESOURCE2 ( mysql , php_mysql_conn * , mysql_link , - 1 , " MySQL-Link " , le_link , le_plink ) ;
}
2003-07-23 00:05:32 +08:00
PHPMY_UNBUFFERED_QUERY_CHECK ( ) ;
2014-03-23 11:30:09 +08:00
RETURN_BOOL ( ! mysql_ping ( mysql - > conn ) ) ;
2002-03-25 01:34:20 +08:00
}
/* }}} */
1999-04-22 05:26:10 +08:00
2002-04-19 00:48:03 +08:00
# endif
1999-04-22 05:26:10 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 21:29:31 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-22 05:26:10 +08:00
*/