2007-07-24 16:13:26 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2010-04-20 13:50:34 +00:00
| PHP Version 5 |
2007-07-24 16:13:26 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2012-01-01 13:15:04 +00:00
| Copyright ( c ) 2006 - 2012 The PHP Group |
2007-07-24 16:13:26 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| This source file is subject to version 3.01 of the PHP license , |
| that is bundled with this package in the file LICENSE , and is |
| available through the world - wide - web at the following url : |
| http : //www.php.net/license/3_01.txt |
| 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 . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2011-10-21 15:28:58 +00:00
| Authors : Andrey Hristov < andrey @ mysql . com > |
2007-07-24 16:13:26 +00:00
| Ulf Wendel < uwendel @ mysql . com > |
2011-10-21 15:28:58 +00:00
| Georg Richter < georg @ mysql . com > |
2007-07-24 16:13:26 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
# include "php.h"
# include "mysqlnd.h"
# include "mysqlnd_wireprotocol.h"
# include "mysqlnd_priv.h"
# include "mysqlnd_result.h"
# include "mysqlnd_statistics.h"
# include "mysqlnd_charset.h"
2007-10-02 10:45:27 +00:00
# include "mysqlnd_debug.h"
2007-07-24 16:13:26 +00:00
/*
TODO :
- Don ' t bind so tightly the metadata with the result set . This means
that the metadata reading should not expect a MYSQLND_RES pointer , it
does not need it , but return a pointer to the metadata ( MYSQLND_FIELD * ) .
For normal statements we will then just assign it to a member of
MYSQLND_RES . For PS statements , it will stay as part of the statement
( MYSQLND_STMT ) between prepare and execute . At execute the new metadata
will be sent by the server , so we will discard the old one and then
finally attach it to the result set . This will make the code more clean ,
as a prepared statement won ' t have anymore stmt - > result ! = NULL , as it
is now , just to have where to store the metadata .
- Change mysqlnd_simple_command to accept a heap dynamic array of MYSQLND_STRING
terminated by a string with ptr being NULL . Thus , multi - part messages can be
sent to the network like writev ( ) and this can save at least for
mysqlnd_stmt_send_long_data ( ) new malloc . This change will probably make the
code in few other places cleaner .
*/
extern MYSQLND_CHARSET * mysqlnd_charsets ;
2010-02-24 21:16:04 +00:00
PHPAPI const char * const mysqlnd_old_passwd = " mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. "
" Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will "
" store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords "
" flag from your my.cnf file " ;
2010-02-24 18:00:01 +00:00
2010-01-13 18:07:02 +00:00
PHPAPI const char * const mysqlnd_server_gone = " MySQL server has gone away " ;
PHPAPI const char * const mysqlnd_out_of_sync = " Commands out of sync; you can't run this command now " ;
2010-04-29 15:49:51 +00:00
PHPAPI const char * const mysqlnd_out_of_memory = " Out of memory " ;
2007-07-24 16:13:26 +00:00
2010-01-13 18:07:02 +00:00
PHPAPI MYSQLND_STATS * mysqlnd_global_stats = NULL ;
2007-07-24 16:13:26 +00:00
2011-10-31 11:46:24 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::free_options */
2009-08-27 13:16:39 +00:00
static void
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , free_options ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2009-08-27 13:16:39 +00:00
{
zend_bool pers = conn - > persistent ;
2011-10-25 23:01:49 +00:00
if ( conn - > options - > charset_name ) {
mnd_pefree ( conn - > options - > charset_name , pers ) ;
conn - > options - > charset_name = NULL ;
2009-08-27 13:16:39 +00:00
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > auth_protocol ) {
mnd_pefree ( conn - > options - > auth_protocol , pers ) ;
conn - > options - > auth_protocol = NULL ;
2011-01-12 21:40:05 +00:00
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > num_commands ) {
2009-08-27 13:16:39 +00:00
unsigned int i ;
2011-10-25 23:01:49 +00:00
for ( i = 0 ; i < conn - > options - > num_commands ; i + + ) {
2009-08-27 13:16:39 +00:00
/* allocated with pestrdup */
2011-10-25 23:01:49 +00:00
mnd_pefree ( conn - > options - > init_commands [ i ] , pers ) ;
2009-08-27 13:16:39 +00:00
}
2011-10-25 23:01:49 +00:00
mnd_pefree ( conn - > options - > init_commands , pers ) ;
conn - > options - > init_commands = NULL ;
2009-08-27 13:16:39 +00:00
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > cfg_file ) {
mnd_pefree ( conn - > options - > cfg_file , pers ) ;
conn - > options - > cfg_file = NULL ;
2009-08-27 13:16:39 +00:00
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > cfg_section ) {
mnd_pefree ( conn - > options - > cfg_section , pers ) ;
conn - > options - > cfg_section = NULL ;
2009-08-27 13:16:39 +00:00
}
}
2010-04-15 11:01:30 +00:00
/* }}} */
2009-08-27 13:16:39 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::free_contents */
2007-07-24 16:13:26 +00:00
static void
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , free_contents ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
zend_bool pers = conn - > persistent ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::free_contents " ) ;
2007-10-02 10:45:27 +00:00
mysqlnd_local_infile_default ( conn ) ;
2007-07-24 16:13:26 +00:00
if ( conn - > current_result ) {
2010-03-12 13:03:46 +00:00
conn - > current_result - > m . free_result ( conn - > current_result , TRUE TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
conn - > current_result = NULL ;
}
2010-05-26 13:47:43 +00:00
if ( conn - > net ) {
conn - > net - > m . free_contents ( conn - > net TSRMLS_CC ) ;
}
2009-12-15 13:13:51 +00:00
2007-10-02 10:45:27 +00:00
DBG_INF ( " Freeing memory of members " ) ;
2009-12-11 11:58:57 +00:00
2007-07-24 16:13:26 +00:00
if ( conn - > host ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > host , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > host = NULL ;
}
if ( conn - > user ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > user , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > user = NULL ;
}
if ( conn - > passwd ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > passwd , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > passwd = NULL ;
}
2009-10-22 17:07:55 +00:00
if ( conn - > connect_or_select_db ) {
mnd_pefree ( conn - > connect_or_select_db , pers ) ;
conn - > connect_or_select_db = NULL ;
}
2007-07-24 16:13:26 +00:00
if ( conn - > unix_socket ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > unix_socket , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > unix_socket = NULL ;
}
2011-07-05 20:31:53 +00:00
DBG_INF_FMT ( " scheme=%s " , conn - > scheme ) ;
2007-07-24 16:13:26 +00:00
if ( conn - > scheme ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > scheme , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > scheme = NULL ;
}
if ( conn - > server_version ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > server_version , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > server_version = NULL ;
}
if ( conn - > host_info ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > host_info , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > host_info = NULL ;
}
2011-01-14 20:04:17 +00:00
if ( conn - > auth_plugin_data ) {
mnd_pefree ( conn - > auth_plugin_data , pers ) ;
conn - > auth_plugin_data = NULL ;
2007-07-24 16:13:26 +00:00
}
if ( conn - > last_message ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > last_message , pers ) ;
2007-07-24 16:13:26 +00:00
conn - > last_message = NULL ;
}
2011-10-25 23:01:49 +00:00
if ( conn - > error_info - > error_list ) {
zend_llist_clean ( conn - > error_info - > error_list ) ;
mnd_pefree ( conn - > error_info - > error_list , pers ) ;
conn - > error_info - > error_list = NULL ;
2011-08-04 09:51:26 +00:00
}
2007-10-02 10:45:27 +00:00
conn - > charset = NULL ;
conn - > greet_charset = NULL ;
DBG_VOID_RETURN ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::dtor */
2007-07-24 16:13:26 +00:00
static void
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , dtor ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::dtor " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2007-07-24 16:13:26 +00:00
conn - > m - > free_contents ( conn TSRMLS_CC ) ;
2009-08-27 13:16:39 +00:00
conn - > m - > free_options ( conn TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
2009-12-11 11:58:57 +00:00
if ( conn - > net ) {
2011-10-25 23:01:49 +00:00
mysqlnd_net_free ( conn - > net , conn - > stats , conn - > error_info TSRMLS_CC ) ;
2009-12-11 11:58:57 +00:00
conn - > net = NULL ;
}
2010-01-07 19:44:59 +00:00
if ( conn - > protocol ) {
mysqlnd_protocol_free ( conn - > protocol TSRMLS_CC ) ;
conn - > protocol = NULL ;
}
2010-01-08 17:35:20 +00:00
if ( conn - > stats ) {
mysqlnd_stats_end ( conn - > stats ) ;
}
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn , conn - > persistent ) ;
DBG_VOID_RETURN ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::simple_command_handle_response */
2009-12-11 10:18:00 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , simple_command_handle_response ) ( MYSQLND_CONN_DATA * conn , enum mysqlnd_packet_type ok_packet ,
2010-04-15 12:55:04 +00:00
zend_bool silent , enum php_mysqlnd_server_command command ,
zend_bool ignore_upsert_status TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2010-05-25 23:18:13 +00:00
enum_func_status ret = FAIL ;
2007-10-02 10:45:27 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::simple_command_handle_response " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " silent=%u packet=%u command=%s " , silent , ok_packet , mysqlnd_command_to_text [ command ] ) ;
2007-10-02 10:45:27 +00:00
2007-07-24 16:13:26 +00:00
switch ( ok_packet ) {
case PROT_OK_PACKET : {
2010-01-11 20:10:10 +00:00
MYSQLND_PACKET_OK * ok_response = conn - > protocol - > m . get_ok_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
2010-05-25 23:18:13 +00:00
if ( ! ok_response ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-05-25 23:18:13 +00:00
break ;
}
2010-01-07 19:44:59 +00:00
if ( FAIL = = ( ret = PACKET_READ ( ok_response , conn ) ) ) {
2007-07-24 16:13:26 +00:00
if ( ! silent ) {
2007-10-02 10:45:27 +00:00
DBG_ERR_FMT ( " Error while reading %s's OK packet " , mysqlnd_command_to_text [ command ] ) ;
2010-06-21 15:32:26 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error while reading %s's OK packet. PID=%u " ,
2007-10-02 10:45:27 +00:00
mysqlnd_command_to_text [ command ] , getpid ( ) ) ;
2007-07-24 16:13:26 +00:00
}
} else {
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " OK from server " ) ;
2010-01-07 19:44:59 +00:00
if ( 0xFF = = ok_response - > field_count ) {
2007-07-24 16:13:26 +00:00
/* The server signalled error. Set the error */
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , ok_response - > error_no , ok_response - > sqlstate , ok_response - > error ) ;
2007-07-24 16:13:26 +00:00
ret = FAIL ;
/*
Cover a protocol design error : error packet does not
contain the server status . Therefore , the client has no way
to find out whether there are more result sets of
a multiple - result - set statement pending . Luckily , in 5.0 an
error always aborts execution of a statement , wherever it is
a multi - statement or a stored procedure , so it should be
safe to unconditionally turn off the flag here .
*/
2011-10-25 23:01:49 +00:00
conn - > upsert_status - > server_status & = ~ SERVER_MORE_RESULTS_EXISTS ;
2007-07-24 16:13:26 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
} else {
SET_NEW_MESSAGE ( conn - > last_message , conn - > last_message_len ,
2010-01-07 19:44:59 +00:00
ok_response - > message , ok_response - > message_len ,
2007-08-06 15:11:46 +00:00
conn - > persistent ) ;
2007-07-24 16:13:26 +00:00
2008-10-27 17:20:26 +00:00
if ( ! ignore_upsert_status ) {
2011-10-25 23:01:49 +00:00
conn - > upsert_status - > warning_count = ok_response - > warning_count ;
conn - > upsert_status - > server_status = ok_response - > server_status ;
conn - > upsert_status - > affected_rows = ok_response - > affected_rows ;
conn - > upsert_status - > last_insert_id = ok_response - > last_insert_id ;
2008-10-27 17:20:26 +00:00
}
2007-07-24 16:13:26 +00:00
}
}
2010-01-07 19:44:59 +00:00
PACKET_FREE ( ok_response ) ;
2007-07-24 16:13:26 +00:00
break ;
}
case PROT_EOF_PACKET : {
2010-01-11 20:10:10 +00:00
MYSQLND_PACKET_EOF * ok_response = conn - > protocol - > m . get_eof_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
2010-05-25 23:18:13 +00:00
if ( ! ok_response ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-09-23 16:03:22 +00:00
break ;
2010-05-25 23:18:13 +00:00
}
2010-01-07 19:44:59 +00:00
if ( FAIL = = ( ret = PACKET_READ ( ok_response , conn ) ) ) {
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_MALFORMED_PACKET , UNKNOWN_SQLSTATE ,
2007-07-24 16:13:26 +00:00
" Malformed packet " ) ;
if ( ! silent ) {
2007-10-02 10:45:27 +00:00
DBG_ERR_FMT ( " Error while reading %s's EOF packet " , mysqlnd_command_to_text [ command ] ) ;
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error while reading %s's EOF packet. PID=%d " ,
2010-04-15 12:55:04 +00:00
mysqlnd_command_to_text [ command ] , getpid ( ) ) ;
2007-07-24 16:13:26 +00:00
}
2010-01-07 19:44:59 +00:00
} else if ( 0xFF = = ok_response - > field_count ) {
2007-07-24 16:13:26 +00:00
/* The server signalled error. Set the error */
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , ok_response - > error_no , ok_response - > sqlstate , ok_response - > error ) ;
2007-07-24 16:13:26 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
2010-01-07 19:44:59 +00:00
} else if ( 0xFE ! = ok_response - > field_count ) {
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_MALFORMED_PACKET , UNKNOWN_SQLSTATE , " Malformed packet " ) ;
2007-07-24 16:13:26 +00:00
if ( ! silent ) {
2010-01-07 19:44:59 +00:00
DBG_ERR_FMT ( " EOF packet expected, field count wasn't 0xFE but 0x%2X " , ok_response - > field_count ) ;
2010-04-15 12:55:04 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " EOF packet expected, field count wasn't 0xFE but 0x%2X " ,
2010-01-07 19:44:59 +00:00
ok_response - > field_count ) ;
2007-07-24 16:13:26 +00:00
}
} else {
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " OK from server " ) ;
2007-07-24 16:13:26 +00:00
}
2010-01-07 19:44:59 +00:00
PACKET_FREE ( ok_response ) ;
2007-07-24 16:13:26 +00:00
break ;
}
default :
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_MALFORMED_PACKET , UNKNOWN_SQLSTATE , " Malformed packet " ) ;
2010-06-21 15:32:26 +00:00
php_error_docref ( NULL TSRMLS_CC , E_ERROR , " Wrong response packet %u passed to the function " , ok_packet ) ;
2007-07-24 16:13:26 +00:00
break ;
}
2007-10-02 10:45:27 +00:00
DBG_INF ( ret = = PASS ? " PASS " : " FAIL " ) ;
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::simple_command */
2009-12-11 10:18:00 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , simple_command ) ( MYSQLND_CONN_DATA * conn , enum php_mysqlnd_server_command command ,
2011-01-24 12:34:47 +00:00
const zend_uchar * const arg , size_t arg_len , enum mysqlnd_packet_type ok_packet , zend_bool silent ,
2009-12-11 10:18:00 +00:00
zend_bool ignore_upsert_status TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
enum_func_status ret = PASS ;
2010-01-11 20:10:10 +00:00
MYSQLND_PACKET_COMMAND * cmd_packet ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::simple_command " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " command=%s ok_packet=%u silent=%u " , mysqlnd_command_to_text [ command ] , ok_packet , silent ) ;
2007-10-02 10:45:27 +00:00
2008-01-28 18:27:49 +00:00
switch ( CONN_GET_STATE ( conn ) ) {
2007-07-24 16:13:26 +00:00
case CONN_READY :
break ;
case CONN_QUIT_SENT :
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_SERVER_GONE_ERROR , UNKNOWN_SQLSTATE , mysqlnd_server_gone ) ;
2007-10-02 10:45:27 +00:00
DBG_ERR ( " Server is gone " ) ;
DBG_RETURN ( FAIL ) ;
2007-07-24 16:13:26 +00:00
default :
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_COMMANDS_OUT_OF_SYNC , UNKNOWN_SQLSTATE , mysqlnd_out_of_sync ) ;
2010-06-21 15:32:26 +00:00
DBG_ERR_FMT ( " Command out of sync. State=%u " , CONN_GET_STATE ( conn ) ) ;
2007-10-02 10:45:27 +00:00
DBG_RETURN ( FAIL ) ;
2007-07-24 16:13:26 +00:00
}
/* clean UPSERT info */
2008-10-27 17:20:26 +00:00
if ( ! ignore_upsert_status ) {
2011-10-25 23:01:49 +00:00
memset ( conn - > upsert_status , 0 , sizeof ( * conn - > upsert_status ) ) ;
2008-10-27 17:20:26 +00:00
}
2007-07-24 16:13:26 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
2011-10-25 23:01:49 +00:00
SET_EMPTY_ERROR ( * conn - > error_info ) ;
2007-07-24 16:13:26 +00:00
2010-01-07 19:44:59 +00:00
cmd_packet = conn - > protocol - > m . get_command_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
2010-05-25 23:18:13 +00:00
if ( ! cmd_packet ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-05-25 23:18:13 +00:00
DBG_RETURN ( FAIL ) ;
}
2010-01-07 19:44:59 +00:00
cmd_packet - > command = command ;
2007-07-24 16:13:26 +00:00
if ( arg & & arg_len ) {
2010-01-07 19:44:59 +00:00
cmd_packet - > argument = arg ;
cmd_packet - > arg_len = arg_len ;
2007-07-24 16:13:26 +00:00
}
2010-01-08 17:35:20 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_COM_QUIT + command - 1 /* because of COM_SLEEP */ ) ;
2009-10-16 13:02:01 +00:00
2010-01-07 19:44:59 +00:00
if ( ! PACKET_WRITE ( cmd_packet , conn ) ) {
2007-07-24 16:13:26 +00:00
if ( ! silent ) {
2007-10-02 10:45:27 +00:00
DBG_ERR_FMT ( " Error while sending %s packet " , mysqlnd_command_to_text [ command ] ) ;
php_error ( E_WARNING , " Error while sending %s packet. PID=%d " , mysqlnd_command_to_text [ command ] , getpid ( ) ) ;
2007-07-24 16:13:26 +00:00
}
2011-10-10 20:49:28 +00:00
CONN_SET_STATE ( conn , CONN_QUIT_SENT ) ;
2007-10-02 10:45:27 +00:00
DBG_ERR ( " Server is gone " ) ;
2007-07-24 16:13:26 +00:00
ret = FAIL ;
} else if ( ok_packet ! = PROT_LAST ) {
2009-12-11 10:18:00 +00:00
ret = conn - > m - > simple_command_handle_response ( conn , ok_packet , silent , command , ignore_upsert_status TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
2010-01-07 19:44:59 +00:00
PACKET_FREE ( cmd_packet ) ;
2007-10-02 10:45:27 +00:00
DBG_INF ( ret = = PASS ? " PASS " : " FAIL " ) ;
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::set_server_option */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , set_server_option ) ( MYSQLND_CONN_DATA * const conn , enum_mysqlnd_server_option option TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , set_server_option ) ;
2011-01-24 12:34:47 +00:00
zend_uchar buffer [ 2 ] ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::set_server_option " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
int2store ( buffer , ( unsigned int ) option ) ;
ret = conn - > m - > simple_command ( conn , COM_SET_OPTION , buffer , sizeof ( buffer ) , PROT_EOF_PACKET , FALSE , TRUE TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::restart_psession */
2010-01-08 13:47:03 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , restart_psession ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2010-01-08 13:47:03 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::restart_psession " ) ;
2010-01-08 17:35:20 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_CONNECT_REUSED ) ;
2007-08-06 15:11:46 +00:00
/* Free here what should not be seen by the next script */
if ( conn - > last_message ) {
2007-10-02 10:45:27 +00:00
mnd_pefree ( conn - > last_message , conn - > persistent ) ;
2007-08-06 15:11:46 +00:00
conn - > last_message = NULL ;
}
2010-01-08 13:47:03 +00:00
DBG_RETURN ( PASS ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::end_psession */
2010-01-08 13:47:03 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , end_psession ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::end_psession " ) ;
2010-01-08 13:47:03 +00:00
DBG_RETURN ( PASS ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-01-11 13:02:57 +00:00
/* {{{ mysqlnd_switch_to_ssl_if_needed */
2011-01-12 21:40:05 +00:00
static enum_func_status
2011-01-11 13:02:57 +00:00
mysqlnd_switch_to_ssl_if_needed (
2011-10-31 11:46:24 +00:00
MYSQLND_CONN_DATA * conn ,
2011-01-11 13:02:57 +00:00
const MYSQLND_PACKET_GREET * const greet_packet ,
const MYSQLND_OPTIONS * const options ,
unsigned long mysql_flags
TSRMLS_DC
)
{
2011-01-12 21:40:05 +00:00
enum_func_status ret = FAIL ;
const MYSQLND_CHARSET * charset ;
MYSQLND_PACKET_AUTH * auth_packet ;
2011-01-11 13:02:57 +00:00
DBG_ENTER ( " mysqlnd_switch_to_ssl_if_needed " ) ;
2011-01-12 21:40:05 +00:00
auth_packet = conn - > protocol - > m . get_auth_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
2011-01-11 13:02:57 +00:00
if ( ! auth_packet ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-01-12 21:40:05 +00:00
goto end ;
2011-01-11 13:02:57 +00:00
}
auth_packet - > client_flags = mysql_flags ;
auth_packet - > max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE ;
if ( options - > charset_name & & ( charset = mysqlnd_find_charset_name ( options - > charset_name ) ) ) {
auth_packet - > charset_no = charset - > nr ;
} else {
# if MYSQLND_UNICODE
auth_packet - > charset_no = 200 ; /* utf8 - swedish collation, check mysqlnd_charset.c */
# else
auth_packet - > charset_no = greet_packet - > charset_no ;
# endif
}
# ifdef MYSQLND_SSL_SUPPORTED
if ( ( greet_packet - > server_capabilities & CLIENT_SSL ) & & ( mysql_flags & CLIENT_SSL ) ) {
zend_bool verify = mysql_flags & CLIENT_SSL_VERIFY_SERVER_CERT ? TRUE : FALSE ;
DBG_INF ( " Switching to SSL " ) ;
if ( ! PACKET_WRITE ( auth_packet , conn ) ) {
CONN_SET_STATE ( conn , CONN_QUIT_SENT ) ;
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_SERVER_GONE_ERROR , UNKNOWN_SQLSTATE , mysqlnd_server_gone ) ;
2011-01-12 21:40:05 +00:00
goto end ;
2011-01-11 13:02:57 +00:00
}
conn - > net - > m . set_client_option ( conn - > net , MYSQL_OPT_SSL_VERIFY_SERVER_CERT , ( const char * ) & verify TSRMLS_CC ) ;
if ( FAIL = = conn - > net - > m . enable_ssl ( conn - > net TSRMLS_CC ) ) {
2011-01-12 21:40:05 +00:00
goto end ;
2011-01-11 13:02:57 +00:00
}
}
# endif
2011-01-12 21:40:05 +00:00
ret = PASS ;
end :
2011-01-11 13:02:57 +00:00
PACKET_FREE ( auth_packet ) ;
2011-01-12 21:40:05 +00:00
DBG_RETURN ( ret ) ;
2011-01-11 13:02:57 +00:00
}
/* }}} */
2010-06-17 11:37:49 +00:00
/* {{{ mysqlnd_connect_run_authentication */
static enum_func_status
mysqlnd_connect_run_authentication (
2011-10-31 11:46:24 +00:00
MYSQLND_CONN_DATA * conn ,
2010-06-17 11:37:49 +00:00
const char * const user ,
const char * const passwd ,
const char * const db ,
size_t db_len ,
2011-01-14 13:00:42 +00:00
size_t passwd_len ,
2010-06-17 11:37:49 +00:00
const MYSQLND_PACKET_GREET * const greet_packet ,
const MYSQLND_OPTIONS * const options ,
unsigned long mysql_flags
TSRMLS_DC )
{
enum_func_status ret = FAIL ;
DBG_ENTER ( " mysqlnd_connect_run_authentication " ) ;
2011-01-12 21:40:05 +00:00
ret = mysqlnd_switch_to_ssl_if_needed ( conn , greet_packet , options , mysql_flags TSRMLS_CC ) ;
if ( PASS = = ret ) {
2011-01-24 12:34:47 +00:00
zend_bool first_call = TRUE ;
2011-01-12 21:40:05 +00:00
char * switch_to_auth_protocol = NULL ;
2011-01-24 12:34:47 +00:00
size_t switch_to_auth_protocol_len = 0 ;
2011-01-12 21:40:05 +00:00
char * requested_protocol = NULL ;
2011-01-24 12:34:47 +00:00
zend_uchar * plugin_data ;
size_t plugin_data_len ;
plugin_data_len = greet_packet - > auth_plugin_data_len ;
2011-05-04 10:35:04 +00:00
plugin_data = mnd_emalloc ( plugin_data_len + 1 ) ;
2011-01-24 12:34:47 +00:00
if ( ! plugin_data ) {
ret = FAIL ;
goto end ;
}
memcpy ( plugin_data , greet_packet - > auth_plugin_data , plugin_data_len ) ;
2011-05-04 10:35:04 +00:00
plugin_data [ plugin_data_len ] = ' \0 ' ;
2011-01-24 12:34:47 +00:00
requested_protocol = mnd_pestrdup ( greet_packet - > auth_protocol ? greet_packet - > auth_protocol : " mysql_native_password " , FALSE ) ;
if ( ! requested_protocol ) {
ret = FAIL ;
goto end ;
}
2011-01-12 21:40:05 +00:00
do {
struct st_mysqlnd_authentication_plugin * auth_plugin ;
2011-01-24 12:34:47 +00:00
{
char * plugin_name = NULL ;
2011-01-11 13:02:57 +00:00
2011-03-18 14:56:20 +00:00
mnd_sprintf ( & plugin_name , 0 , " auth_plugin_%s " , requested_protocol ) ;
2011-01-24 12:34:47 +00:00
DBG_INF_FMT ( " looking for %s auth plugin " , plugin_name ) ;
auth_plugin = mysqlnd_plugin_find ( plugin_name ) ;
2011-03-18 14:56:20 +00:00
mnd_sprintf_free ( plugin_name ) ;
2011-01-24 12:34:47 +00:00
if ( ! auth_plugin ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " The server requested authentication method unknown to the client [%s] " , requested_protocol ) ;
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_NOT_IMPLEMENTED , UNKNOWN_SQLSTATE , " The server requested authentication method umknown to the client " ) ;
2011-01-24 12:34:47 +00:00
break ;
}
}
2011-01-12 21:40:05 +00:00
DBG_INF ( " plugin found " ) ;
2011-01-11 13:02:57 +00:00
2011-01-24 12:34:47 +00:00
{
zend_uchar * switch_to_auth_protocol_data = NULL ;
size_t switch_to_auth_protocol_data_len = 0 ;
zend_uchar * scrambled_data = NULL ;
size_t scrambled_data_len = 0 ;
switch_to_auth_protocol = NULL ;
switch_to_auth_protocol_len = 0 ;
if ( conn - > auth_plugin_data ) {
mnd_pefree ( conn - > auth_plugin_data , conn - > persistent ) ;
conn - > auth_plugin_data = NULL ;
}
conn - > auth_plugin_data_len = plugin_data_len ;
conn - > auth_plugin_data = mnd_pemalloc ( conn - > auth_plugin_data_len , conn - > persistent ) ;
if ( ! conn - > auth_plugin_data ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-01-24 12:34:47 +00:00
goto end ;
}
memcpy ( conn - > auth_plugin_data , plugin_data , plugin_data_len ) ;
DBG_INF_FMT ( " salt=[%*s] " , plugin_data_len - 1 , plugin_data ) ;
/* The data should be allocated with malloc() */
scrambled_data =
auth_plugin - > methods . get_auth_data ( NULL , & scrambled_data_len , conn , user , passwd , passwd_len ,
plugin_data , plugin_data_len , options , mysql_flags TSRMLS_CC ) ;
2011-10-31 11:46:24 +00:00
ret = mysqlnd_auth_handshake ( conn , user , passwd , passwd_len , db , db_len , options , mysql_flags ,
greet_packet - > charset_no ,
2011-01-24 12:34:47 +00:00
first_call ,
requested_protocol ,
scrambled_data , scrambled_data_len ,
& switch_to_auth_protocol , & switch_to_auth_protocol_len ,
& switch_to_auth_protocol_data , & switch_to_auth_protocol_data_len
TSRMLS_CC ) ;
first_call = FALSE ;
free ( scrambled_data ) ;
DBG_INF_FMT ( " switch_to_auth_protocol=%s " , switch_to_auth_protocol ? switch_to_auth_protocol : " n/a " ) ;
2011-01-31 13:29:18 +00:00
if ( requested_protocol & & switch_to_auth_protocol ) {
2011-01-24 12:34:47 +00:00
mnd_efree ( requested_protocol ) ;
2011-01-31 13:29:18 +00:00
requested_protocol = switch_to_auth_protocol ;
2011-01-24 12:34:47 +00:00
}
2010-06-17 11:37:49 +00:00
2011-01-24 12:34:47 +00:00
if ( plugin_data ) {
mnd_efree ( plugin_data ) ;
}
plugin_data_len = switch_to_auth_protocol_data_len ;
plugin_data = switch_to_auth_protocol_data ;
}
2011-10-25 23:01:49 +00:00
DBG_INF_FMT ( " conn->error_info->error_no = %d " , conn - > error_info - > error_no ) ;
} while ( ret = = FAIL & & conn - > error_info - > error_no = = 0 & & switch_to_auth_protocol ! = NULL ) ;
2011-01-24 12:34:47 +00:00
if ( plugin_data ) {
mnd_efree ( plugin_data ) ;
}
2011-01-12 21:40:05 +00:00
if ( ret = = PASS ) {
2011-01-31 13:29:18 +00:00
DBG_INF_FMT ( " saving requested_protocol=%s " , requested_protocol ) ;
2011-01-12 21:40:05 +00:00
conn - > m - > set_client_option ( conn , MYSQLND_OPT_AUTH_PROTOCOL , requested_protocol TSRMLS_CC ) ;
}
2010-06-17 11:37:49 +00:00
2011-01-24 12:34:47 +00:00
if ( requested_protocol ) {
mnd_efree ( requested_protocol ) ;
2010-06-17 11:37:49 +00:00
}
}
2011-01-24 12:34:47 +00:00
end :
2010-08-12 11:38:08 +00:00
DBG_RETURN ( ret ) ;
2010-06-17 11:37:49 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::connect */
2009-11-20 08:12:14 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , connect ) ( MYSQLND_CONN_DATA * conn ,
2008-01-23 19:09:33 +00:00
const char * host , const char * user ,
const char * passwd , unsigned int passwd_len ,
const char * db , unsigned int db_len ,
2007-07-24 16:13:26 +00:00
unsigned int port ,
2010-10-05 16:27:49 +00:00
const char * socket_or_pipe ,
2009-12-09 20:21:05 +00:00
unsigned int mysql_flags
2007-07-24 16:13:26 +00:00
TSRMLS_DC )
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , connect ) ;
2011-10-10 20:49:28 +00:00
size_t host_len ;
2007-07-24 16:13:26 +00:00
zend_bool unix_socket = FALSE ;
2010-09-22 15:14:04 +00:00
zend_bool named_pipe = FALSE ;
2007-10-02 10:45:27 +00:00
zend_bool reconnect = FALSE ;
2009-11-20 08:12:14 +00:00
zend_bool saved_compression = FALSE ;
2011-10-25 19:04:36 +00:00
zend_bool local_tx_started = FALSE ;
2007-07-24 16:13:26 +00:00
2010-01-11 20:10:10 +00:00
MYSQLND_PACKET_GREET * greet_packet = NULL ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::connect " ) ;
2009-11-20 08:12:14 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS ! = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
goto err ;
}
local_tx_started = TRUE ;
2011-10-25 23:01:49 +00:00
SET_EMPTY_ERROR ( * conn - > error_info ) ;
2011-01-28 17:33:14 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " host=%s user=%s db=%s port=%u flags=%u persistent=%u state=%u " ,
2007-10-02 10:45:27 +00:00
host ? host : " " , user ? user : " " , db ? db : " " , port , mysql_flags ,
2008-01-28 18:27:49 +00:00
conn ? conn - > persistent : 0 , conn ? CONN_GET_STATE ( conn ) : - 1 ) ;
2007-10-02 10:45:27 +00:00
2011-01-12 21:40:05 +00:00
if ( CONN_GET_STATE ( conn ) > CONN_ALLOCED & & CONN_GET_STATE ( conn ) ) {
2007-10-02 10:45:27 +00:00
DBG_INF ( " Connecting on a connected handle. " ) ;
2008-01-28 18:27:49 +00:00
if ( CONN_GET_STATE ( conn ) < CONN_QUIT_SENT ) {
2010-01-08 17:35:20 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_CLOSE_IMPLICIT ) ;
2007-10-02 10:45:27 +00:00
reconnect = TRUE ;
2010-02-09 19:05:40 +00:00
conn - > m - > send_close ( conn TSRMLS_CC ) ;
2007-10-02 10:45:27 +00:00
}
conn - > m - > free_contents ( conn TSRMLS_CC ) ;
2010-01-08 17:35:20 +00:00
MYSQLND_DEC_CONN_STATISTIC ( conn - > stats , STAT_OPENED_CONNECTIONS ) ;
2007-10-02 10:45:27 +00:00
if ( conn - > persistent ) {
2010-01-08 17:35:20 +00:00
MYSQLND_DEC_CONN_STATISTIC ( conn - > stats , STAT_OPENED_PERSISTENT_CONNECTIONS ) ;
2007-10-02 10:45:27 +00:00
}
/* Now reconnect using the same handle */
2009-12-11 11:58:57 +00:00
if ( conn - > net - > compressed ) {
2009-11-20 08:12:14 +00:00
/*
2009-12-11 11:58:57 +00:00
we need to save the state . As we will re - connect , net - > compressed should be off , or
2009-11-20 08:12:14 +00:00
we will look for a compression header as part of the greet message , but there will
be none .
*/
saved_compression = TRUE ;
2009-12-11 11:58:57 +00:00
conn - > net - > compressed = FALSE ;
2009-11-20 08:12:14 +00:00
}
2011-01-12 21:40:05 +00:00
} else {
unsigned int max_allowed_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE ;
conn - > m - > set_client_option ( conn , MYSQLND_OPT_MAX_ALLOWED_PACKET , ( char * ) & max_allowed_size TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
if ( ! host | | ! host [ 0 ] ) {
host = " localhost " ;
}
2010-03-26 16:58:25 +00:00
if ( ! user ) {
DBG_INF_FMT ( " no user given, using empty string " ) ;
user = " " ;
2007-07-24 16:13:26 +00:00
}
if ( ! passwd ) {
2010-03-26 16:58:25 +00:00
DBG_INF_FMT ( " no password given, using empty string " ) ;
2007-07-24 16:13:26 +00:00
passwd = " " ;
passwd_len = 0 ;
}
if ( ! db ) {
2010-03-26 16:58:25 +00:00
DBG_INF_FMT ( " no db given, using empty string " ) ;
2007-07-24 16:13:26 +00:00
db = " " ;
db_len = 0 ;
}
2010-04-01 13:26:41 +00:00
2008-04-16 12:53:18 +00:00
host_len = strlen ( host ) ;
2010-03-29 17:04:16 +00:00
{
char * transport = NULL ;
int transport_len ;
2007-07-24 16:13:26 +00:00
# ifndef PHP_WIN32
2010-03-29 17:04:16 +00:00
if ( host_len = = sizeof ( " localhost " ) - 1 & & ! strncasecmp ( host , " localhost " , host_len ) ) {
2010-10-05 16:27:49 +00:00
DBG_INF_FMT ( " socket=%s " , socket_or_pipe ? socket_or_pipe : " n/a " ) ;
if ( ! socket_or_pipe ) {
socket_or_pipe = " /tmp/mysql.sock " ;
2010-03-29 17:04:16 +00:00
}
2011-03-18 14:56:20 +00:00
transport_len = mnd_sprintf ( & transport , 0 , " unix://%s " , socket_or_pipe ) ;
2010-03-29 17:04:16 +00:00
unix_socket = TRUE ;
2010-09-22 15:14:04 +00:00
# else
if ( host_len = = sizeof ( " . " ) - 1 & & host [ 0 ] = = ' . ' ) {
/* named pipe in socket */
2010-10-05 16:27:49 +00:00
if ( ! socket_or_pipe ) {
socket_or_pipe = " \\ \\ . \\ pipe \\ MySQL " ;
2010-09-22 15:14:04 +00:00
}
2011-03-18 14:56:20 +00:00
transport_len = mnd_sprintf ( & transport , 0 , " pipe://%s " , socket_or_pipe ) ;
2010-09-22 15:14:04 +00:00
named_pipe = TRUE ;
2007-07-24 16:13:26 +00:00
# endif
2010-09-22 15:14:04 +00:00
} else {
2010-03-29 17:04:16 +00:00
if ( ! port ) {
port = 3306 ;
}
2011-03-18 14:56:20 +00:00
transport_len = mnd_sprintf ( & transport , 0 , " tcp://%s:%u " , host , port ) ;
2010-03-29 17:04:16 +00:00
}
2010-04-29 15:49:51 +00:00
if ( ! transport ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-04-29 15:49:51 +00:00
goto err ; /* OOM */
}
2011-07-05 20:31:53 +00:00
DBG_INF_FMT ( " transport=%s conn->scheme=%s " , transport , conn - > scheme ) ;
2010-03-29 17:04:16 +00:00
conn - > scheme = mnd_pestrndup ( transport , transport_len , conn - > persistent ) ;
conn - > scheme_len = transport_len ;
2011-03-18 14:56:20 +00:00
mnd_sprintf_free ( transport ) ;
2010-03-29 17:04:16 +00:00
transport = NULL ;
2010-04-29 15:49:51 +00:00
if ( ! conn - > scheme ) {
goto err ; /* OOM */
}
2007-07-24 16:13:26 +00:00
}
2010-01-07 19:44:59 +00:00
greet_packet = conn - > protocol - > m . get_greet_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
2010-06-17 11:37:49 +00:00
if ( ! greet_packet ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-04-29 15:49:51 +00:00
goto err ; /* OOM */
}
2007-07-24 16:13:26 +00:00
2011-10-10 20:49:28 +00:00
if ( FAIL = = conn - > net - > m . connect_ex ( conn - > net , conn - > scheme , conn - > scheme_len , conn - > persistent ,
2011-10-25 23:01:49 +00:00
conn - > stats , conn - > error_info TSRMLS_CC ) )
2011-10-10 20:49:28 +00:00
{
2010-04-15 12:55:04 +00:00
goto err ;
2009-11-20 08:12:14 +00:00
}
2009-12-15 17:33:06 +00:00
DBG_INF_FMT ( " stream=%p " , conn - > net - > stream ) ;
2009-11-20 08:12:14 +00:00
2010-01-07 19:44:59 +00:00
if ( FAIL = = PACKET_READ ( greet_packet , conn ) ) {
2007-10-02 10:45:27 +00:00
DBG_ERR ( " Error while reading greeting packet " ) ;
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error while reading greeting packet. PID=%d " , getpid ( ) ) ;
2007-07-24 16:13:26 +00:00
goto err ;
2010-01-07 19:44:59 +00:00
} else if ( greet_packet - > error_no ) {
2010-06-21 15:32:26 +00:00
DBG_ERR_FMT ( " errorno=%u error=%s " , greet_packet - > error_no , greet_packet - > error ) ;
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , greet_packet - > error_no , greet_packet - > sqlstate , greet_packet - > error ) ;
2009-11-20 08:12:14 +00:00
goto err ;
2010-01-07 19:44:59 +00:00
} else if ( greet_packet - > pre41 ) {
DBG_ERR_FMT ( " Connecting to 3.22, 3.23 & 4.0 is not supported. Server is %-.32s " , greet_packet - > server_version ) ;
2007-07-24 16:13:26 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Connecting to 3.22, 3.23 & 4.0 "
2010-01-07 19:44:59 +00:00
" is not supported. Server is %-.32s " , greet_packet - > server_version ) ;
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_NOT_IMPLEMENTED , UNKNOWN_SQLSTATE ,
2007-07-24 16:13:26 +00:00
" Connecting to 3.22, 3.23 & 4.0 servers is not supported " ) ;
goto err ;
}
2010-01-07 19:44:59 +00:00
conn - > thread_id = greet_packet - > thread_id ;
conn - > protocol_version = greet_packet - > protocol_version ;
2010-03-29 17:04:16 +00:00
conn - > server_version = mnd_pestrdup ( greet_packet - > server_version , conn - > persistent ) ;
2007-07-24 16:13:26 +00:00
2010-01-07 19:44:59 +00:00
conn - > greet_charset = mysqlnd_find_charset_nr ( greet_packet - > charset_no ) ;
2007-07-24 16:13:26 +00:00
/* we allow load data local infile by default */
2010-06-17 11:37:49 +00:00
mysql_flags | = MYSQLND_CAPABILITIES ;
if ( db ) {
mysql_flags | = CLIENT_CONNECT_WITH_DB ;
}
if ( PG ( open_basedir ) & & strlen ( PG ( open_basedir ) ) ) {
mysql_flags ^ = CLIENT_LOCAL_FILES ;
}
2009-09-30 23:13:43 +00:00
# ifndef MYSQLND_COMPRESSION_ENABLED
if ( mysql_flags & CLIENT_COMPRESS ) {
mysql_flags & = ~ CLIENT_COMPRESS ;
}
2010-09-01 14:47:36 +00:00
# else
if ( conn - > net - > options . flags & MYSQLND_NET_FLAG_USE_COMPRESSION ) {
mysql_flags | = CLIENT_COMPRESS ;
}
2009-09-30 23:13:43 +00:00
# endif
2010-04-15 11:01:30 +00:00
# ifndef MYSQLND_SSL_SUPPORTED
if ( mysql_flags & CLIENT_SSL ) {
mysql_flags & = ~ CLIENT_SSL ;
}
# else
if ( conn - > net - > options . ssl_key | | conn - > net - > options . ssl_cert | |
conn - > net - > options . ssl_ca | | conn - > net - > options . ssl_capath | | conn - > net - > options . ssl_cipher )
{
mysql_flags | = CLIENT_SSL ;
}
# endif
2007-07-24 16:13:26 +00:00
2011-01-14 13:00:42 +00:00
if ( FAIL = = mysqlnd_connect_run_authentication ( conn , user , passwd , db , db_len , ( size_t ) passwd_len ,
2011-10-25 23:01:49 +00:00
greet_packet , conn - > options , mysql_flags TSRMLS_CC ) )
2011-01-14 13:00:42 +00:00
{
2009-11-20 08:12:14 +00:00
goto err ;
2007-10-02 10:45:27 +00:00
}
2007-07-24 16:13:26 +00:00
2010-06-17 11:37:49 +00:00
{
2008-01-28 18:27:49 +00:00
CONN_SET_STATE ( conn , CONN_READY ) ;
2010-04-01 13:26:41 +00:00
2010-06-17 11:37:49 +00:00
if ( saved_compression ) {
2009-12-11 11:58:57 +00:00
conn - > net - > compressed = TRUE ;
2009-11-20 08:12:14 +00:00
}
/*
If a connect on a existing handle is performed and mysql_flags is
passed which doesn ' t CLIENT_COMPRESS , then we need to overwrite the value
which we set based on saved_compression .
*/
2009-12-11 11:58:57 +00:00
conn - > net - > compressed = mysql_flags & CLIENT_COMPRESS ? TRUE : FALSE ;
2007-07-24 16:13:26 +00:00
2010-03-29 17:04:16 +00:00
conn - > user = mnd_pestrdup ( user , conn - > persistent ) ;
2009-10-22 17:07:55 +00:00
conn - > user_len = strlen ( conn - > user ) ;
2010-03-29 17:04:16 +00:00
conn - > passwd = mnd_pestrndup ( passwd , passwd_len , conn - > persistent ) ;
2009-10-22 17:07:55 +00:00
conn - > passwd_len = passwd_len ;
2007-07-24 16:13:26 +00:00
conn - > port = port ;
2010-03-29 17:04:16 +00:00
conn - > connect_or_select_db = mnd_pestrndup ( db , db_len , conn - > persistent ) ;
2009-10-22 17:07:55 +00:00
conn - > connect_or_select_db_len = db_len ;
2009-10-19 12:09:48 +00:00
2010-04-29 15:49:51 +00:00
if ( ! conn - > user | | ! conn - > passwd | | ! conn - > connect_or_select_db ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-04-29 15:49:51 +00:00
goto err ; /* OOM */
}
2007-07-24 16:13:26 +00:00
2010-09-22 15:14:04 +00:00
if ( ! unix_socket & & ! named_pipe ) {
2010-03-29 17:04:16 +00:00
conn - > host = mnd_pestrdup ( host , conn - > persistent ) ;
2010-04-29 15:49:51 +00:00
if ( ! conn - > host ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-04-29 15:49:51 +00:00
goto err ; /* OOM */
}
2009-10-22 17:07:55 +00:00
conn - > host_len = strlen ( conn - > host ) ;
2010-04-01 13:26:41 +00:00
{
char * p ;
2011-03-18 14:56:20 +00:00
mnd_sprintf ( & p , 0 , " %s via TCP/IP " , conn - > host ) ;
2010-04-29 15:49:51 +00:00
if ( ! p ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-08-12 11:38:08 +00:00
goto err ; /* OOM */
2010-04-29 15:49:51 +00:00
}
2010-04-01 13:26:41 +00:00
conn - > host_info = mnd_pestrdup ( p , conn - > persistent ) ;
2011-03-18 14:56:20 +00:00
mnd_sprintf_free ( p ) ;
2010-04-29 15:49:51 +00:00
if ( ! conn - > host_info ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-08-12 11:38:08 +00:00
goto err ; /* OOM */
2010-04-29 15:49:51 +00:00
}
2007-07-24 16:13:26 +00:00
}
} else {
2011-10-31 11:46:24 +00:00
conn - > unix_socket = mnd_pestrdup ( socket_or_pipe , conn - > persistent ) ;
2010-09-22 15:14:04 +00:00
if ( unix_socket ) {
2011-10-31 11:46:24 +00:00
conn - > host_info = mnd_pestrdup ( " Localhost via UNIX socket " , conn - > persistent ) ;
2010-09-22 15:14:04 +00:00
} else if ( named_pipe ) {
char * p ;
2011-03-18 14:56:20 +00:00
mnd_sprintf ( & p , 0 , " %s via named pipe " , conn - > unix_socket ) ;
2010-09-22 15:14:04 +00:00
if ( ! p ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-09-22 15:14:04 +00:00
goto err ; /* OOM */
}
conn - > host_info = mnd_pestrdup ( p , conn - > persistent ) ;
2011-03-18 14:56:20 +00:00
mnd_sprintf_free ( p ) ;
2010-09-22 15:14:04 +00:00
if ( ! conn - > host_info ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-09-22 15:14:04 +00:00
goto err ; /* OOM */
}
} else {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Impossible. Should be either socket or a pipe. Report a bug! " ) ;
}
2010-04-29 15:49:51 +00:00
if ( ! conn - > unix_socket | | ! conn - > host_info ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2010-08-12 11:38:08 +00:00
goto err ; /* OOM */
2010-04-29 15:49:51 +00:00
}
conn - > unix_socket_len = strlen ( conn - > unix_socket ) ;
2007-07-24 16:13:26 +00:00
}
2010-06-17 11:37:49 +00:00
conn - > client_flag = mysql_flags ;
2011-01-11 13:02:57 +00:00
conn - > max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE ;
2007-07-24 16:13:26 +00:00
/* todo: check if charset is available */
2010-01-07 19:44:59 +00:00
conn - > server_capabilities = greet_packet - > server_capabilities ;
2011-10-25 23:01:49 +00:00
conn - > upsert_status - > warning_count = 0 ;
conn - > upsert_status - > server_status = greet_packet - > server_status ;
conn - > upsert_status - > affected_rows = 0 ;
2007-07-24 16:13:26 +00:00
2011-10-25 23:01:49 +00:00
SET_EMPTY_ERROR ( * conn - > error_info ) ;
2007-07-24 16:13:26 +00:00
2008-03-20 13:25:49 +00:00
mysqlnd_local_infile_default ( conn ) ;
2007-07-24 16:13:26 +00:00
2010-08-12 12:02:02 +00:00
# if MYSQLND_UNICODE
2007-07-24 16:13:26 +00:00
{
2008-11-06 10:36:30 +00:00
unsigned int as_unicode = 1 ;
2010-04-15 12:55:04 +00:00
conn - > m - > set_client_option ( conn , MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE , ( char * ) & as_unicode TSRMLS_CC ) ;
2007-10-02 10:45:27 +00:00
DBG_INF ( " unicode set " ) ;
2007-07-24 16:13:26 +00:00
}
2007-10-02 10:45:27 +00:00
# endif
2011-10-25 23:01:49 +00:00
if ( conn - > options - > init_commands ) {
2010-04-15 15:28:00 +00:00
unsigned int current_command = 0 ;
2011-10-25 23:01:49 +00:00
for ( ; current_command < conn - > options - > num_commands ; + + current_command ) {
const char * const command = conn - > options - > init_commands [ current_command ] ;
2010-04-29 15:49:51 +00:00
if ( command ) {
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_INIT_COMMAND_EXECUTED_COUNT ) ;
if ( PASS ! = conn - > m - > query ( conn , command , strlen ( command ) TSRMLS_CC ) ) {
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_INIT_COMMAND_FAILED_COUNT ) ;
goto err ;
}
if ( conn - > last_query_type = = QUERY_SELECT ) {
MYSQLND_RES * result = conn - > m - > use_result ( conn TSRMLS_CC ) ;
2010-05-27 12:39:12 +00:00
if ( result ) {
result - > m . free_result ( result , TRUE TSRMLS_CC ) ;
}
2010-04-29 15:49:51 +00:00
}
2009-08-27 13:16:39 +00:00
}
}
}
2010-06-17 11:37:49 +00:00
MYSQLND_INC_CONN_STATISTIC_W_VALUE2 ( conn - > stats , STAT_CONNECT_SUCCESS , 1 , STAT_OPENED_CONNECTIONS , 1 ) ;
if ( reconnect ) {
MYSQLND_INC_GLOBAL_STATISTIC ( STAT_RECONNECT ) ;
}
if ( conn - > persistent ) {
MYSQLND_INC_CONN_STATISTIC_W_VALUE2 ( conn - > stats , STAT_PCONNECT_SUCCESS , 1 , STAT_OPENED_PERSISTENT_CONNECTIONS , 1 ) ;
}
DBG_INF_FMT ( " connection_id=%llu " , conn - > thread_id ) ;
2010-01-07 19:44:59 +00:00
PACKET_FREE ( greet_packet ) ;
2008-01-28 18:27:49 +00:00
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , PASS TSRMLS_CC ) ;
2009-11-20 08:12:14 +00:00
DBG_RETURN ( PASS ) ;
2007-07-24 16:13:26 +00:00
}
err :
2010-01-07 19:44:59 +00:00
PACKET_FREE ( greet_packet ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 23:01:49 +00:00
DBG_ERR_FMT ( " [%u] %.128s (trying to connect via %s) " , conn - > error_info - > error_no , conn - > error_info - > error , conn - > scheme ) ;
if ( ! conn - > error_info - > error_no ) {
SET_CLIENT_ERROR ( * conn - > error_info , CR_CONNECTION_ERROR , UNKNOWN_SQLSTATE , conn - > error_info - > error ? conn - > error_info - > error : " Unknown error " ) ;
2011-10-10 20:49:28 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " [%u] %.128s (trying to connect via %s) " ,
2011-10-25 23:01:49 +00:00
conn - > error_info - > error_no , conn - > error_info - > error , conn - > scheme ) ;
2007-07-24 16:13:26 +00:00
}
2011-10-10 20:49:28 +00:00
2011-07-05 20:31:53 +00:00
conn - > m - > free_contents ( conn TSRMLS_CC ) ;
2010-01-08 17:35:20 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_CONNECT_FAILURE ) ;
2011-10-25 19:04:36 +00:00
if ( TRUE = = local_tx_started ) {
conn - > m - > local_tx_end ( conn , this_func , FAIL TSRMLS_CC ) ;
}
2009-11-20 08:12:14 +00:00
DBG_RETURN ( FAIL ) ;
}
/* }}} */
2011-11-02 17:06:30 +00:00
/* {{{ mysqlnd_conn::connect */
static enum_func_status
MYSQLND_METHOD ( mysqlnd_conn , connect ) ( MYSQLND * conn_handle ,
const char * host , const char * user ,
const char * passwd , unsigned int passwd_len ,
const char * db , unsigned int db_len ,
unsigned int port ,
const char * socket_or_pipe ,
unsigned int mysql_flags
TSRMLS_DC )
{
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , connect ) ;
enum_func_status ret = FAIL ;
MYSQLND_CONN_DATA * conn = conn_handle - > data ;
DBG_ENTER ( " mysqlnd_conn::connect " ) ;
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > connect ( conn , host , user , passwd , passwd_len , db , db_len , port , socket_or_pipe , mysql_flags TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , FAIL TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
}
2009-11-20 08:12:14 +00:00
/* {{{ mysqlnd_connect */
2011-10-31 11:46:24 +00:00
PHPAPI MYSQLND * mysqlnd_connect ( MYSQLND * conn_handle ,
2011-10-25 19:04:36 +00:00
const char * host , const char * user ,
const char * passwd , unsigned int passwd_len ,
const char * db , unsigned int db_len ,
2009-11-20 08:12:14 +00:00
unsigned int port ,
2011-10-25 19:04:36 +00:00
const char * socket_or_pipe ,
2009-12-09 20:21:05 +00:00
unsigned int mysql_flags
2009-11-20 08:12:14 +00:00
TSRMLS_DC )
{
2010-04-01 13:26:41 +00:00
enum_func_status ret = FAIL ;
2009-11-20 08:12:14 +00:00
zend_bool self_alloced = FALSE ;
DBG_ENTER ( " mysqlnd_connect " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " host=%s user=%s db=%s port=%u flags=%u " , host ? host : " " , user ? user : " " , db ? db : " " , port , mysql_flags ) ;
2009-11-20 08:12:14 +00:00
2011-10-31 11:46:24 +00:00
if ( ! conn_handle ) {
2009-11-20 08:12:14 +00:00
self_alloced = TRUE ;
2011-10-31 11:46:24 +00:00
if ( ! ( conn_handle = mysqlnd_init ( FALSE ) ) ) {
2010-04-29 15:49:51 +00:00
/* OOM */
2010-04-29 13:13:41 +00:00
DBG_RETURN ( NULL ) ;
}
2007-07-24 16:13:26 +00:00
}
2009-11-20 08:12:14 +00:00
2011-11-02 17:06:30 +00:00
ret = conn_handle - > m - > connect ( conn_handle , host , user , passwd , passwd_len , db , db_len , port , socket_or_pipe , mysql_flags TSRMLS_CC ) ;
2009-11-20 08:12:14 +00:00
if ( ret = = FAIL ) {
if ( self_alloced ) {
/*
We have alloced , thus there are no references to this
object - we are free to kill it !
*/
2011-10-31 14:33:56 +00:00
conn_handle - > m - > dtor ( conn_handle TSRMLS_CC ) ;
2009-11-20 08:12:14 +00:00
}
DBG_RETURN ( NULL ) ;
}
2011-10-31 11:46:24 +00:00
DBG_RETURN ( conn_handle ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::query */
2009-11-20 08:12:14 +00:00
/*
2011-10-25 23:01:49 +00:00
If conn - > error_info - > error_no is not zero , then we had an error .
2007-07-24 16:13:26 +00:00
Still the result from the query is PASS
*/
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , query ) ( MYSQLND_CONN_DATA * conn , const char * query , unsigned int query_len TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , query ) ;
2011-05-31 20:42:44 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::query " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu query=%s " , conn - > thread_id , query ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
if ( PASS = = conn - > m - > send_query ( conn , query , query_len TSRMLS_CC ) & &
PASS = = conn - > m - > reap_query ( conn TSRMLS_CC ) )
{
ret = PASS ;
2011-10-25 23:01:49 +00:00
if ( conn - > last_query_type = = QUERY_UPSERT & & conn - > upsert_status - > affected_rows ) {
MYSQLND_INC_CONN_STATISTIC_W_VALUE ( conn - > stats , STAT_ROWS_AFFECTED_NORMAL , conn - > upsert_status - > affected_rows ) ;
2011-10-25 19:04:36 +00:00
}
2011-05-31 20:42:44 +00:00
}
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2009-10-22 14:30:51 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::send_query */
2008-11-18 16:54:38 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , send_query ) ( MYSQLND_CONN_DATA * conn , const char * query , unsigned int query_len TSRMLS_DC )
2008-11-18 16:54:38 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , send_query ) ;
2008-11-18 16:54:38 +00:00
enum_func_status ret ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::send_query " ) ;
2008-11-18 16:54:38 +00:00
DBG_INF_FMT ( " conn=%llu query=%s " , conn - > thread_id , query ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > simple_command ( conn , COM_QUERY , ( zend_uchar * ) query , query_len ,
2011-10-31 11:46:24 +00:00
PROT_LAST /* we will handle the OK packet*/ ,
FALSE , FALSE TSRMLS_CC ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = ret ) {
CONN_SET_STATE ( conn , CONN_QUERY_SENT ) ;
}
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2011-05-31 20:42:44 +00:00
}
2008-11-18 16:54:38 +00:00
DBG_RETURN ( ret ) ;
}
/* }}} */
2010-01-07 19:44:59 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::reap_query */
2008-11-18 16:54:38 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , reap_query ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2008-11-18 16:54:38 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , reap_query ) ;
2008-11-18 18:02:06 +00:00
enum_mysqlnd_connection_state state = CONN_GET_STATE ( conn ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::reap_query " ) ;
2008-11-18 16:54:38 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2008-11-18 18:02:06 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
if ( state < = CONN_READY | | state = = CONN_QUIT_SENT ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Connection not opened, clear or has been closed " ) ;
DBG_ERR_FMT ( " Connection not opened, clear or has been closed. State=%u " , state ) ;
DBG_RETURN ( ret ) ;
}
ret = conn - > m - > query_read_result_set_header ( conn , NULL TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2008-11-18 16:54:38 +00:00
}
2011-10-25 19:04:36 +00:00
DBG_RETURN ( ret ) ;
2008-11-18 16:54:38 +00:00
}
/* }}} */
# include "php_network.h"
MYSQLND * * mysqlnd_stream_array_check_for_readiness ( MYSQLND * * conn_array TSRMLS_DC )
{
int cnt = 0 ;
MYSQLND * * p = conn_array , * * p_p ;
MYSQLND * * ret = NULL ;
while ( * p ) {
2011-10-31 11:46:24 +00:00
if ( CONN_GET_STATE ( ( * p ) - > data ) < = CONN_READY | | CONN_GET_STATE ( ( * p ) - > data ) = = CONN_QUIT_SENT ) {
2008-11-18 16:54:38 +00:00
cnt + + ;
}
p + + ;
}
if ( cnt ) {
MYSQLND * * ret_p = ret = ecalloc ( cnt + 1 , sizeof ( MYSQLND * ) ) ;
p_p = p = conn_array ;
while ( * p ) {
2011-10-31 11:46:24 +00:00
if ( CONN_GET_STATE ( ( * p ) - > data ) < = CONN_READY | | CONN_GET_STATE ( ( * p ) - > data ) = = CONN_QUIT_SENT ) {
2008-11-18 16:54:38 +00:00
* ret_p = * p ;
* p = NULL ;
ret_p + + ;
} else {
* p_p = * p ;
p_p + + ;
}
p + + ;
}
2009-11-20 08:12:14 +00:00
* ret_p = NULL ;
2008-11-18 16:54:38 +00:00
}
return ret ;
}
/* {{{ stream_select mysqlnd_stream_array_to_fd_set functions */
2011-10-31 11:46:24 +00:00
static int mysqlnd_stream_array_to_fd_set ( MYSQLND * * conn_array , fd_set * fds , php_socket_t * max_fd TSRMLS_DC )
2008-11-18 16:54:38 +00:00
{
php_socket_t this_fd ;
int cnt = 0 ;
MYSQLND * * p = conn_array ;
while ( * p ) {
/* get the fd.
* NB : Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
* when casting . It is only used here so that the buffered data warning
* is not displayed .
* */
2011-10-31 11:46:24 +00:00
if ( SUCCESS = = php_stream_cast ( ( * p ) - > data - > net - > stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL ,
2008-11-18 16:54:38 +00:00
( void * ) & this_fd , 1 ) & & this_fd > = 0 ) {
2009-11-20 08:12:14 +00:00
2008-11-18 16:54:38 +00:00
PHP_SAFE_FD_SET ( this_fd , fds ) ;
if ( this_fd > * max_fd ) {
* max_fd = this_fd ;
}
cnt + + ;
}
p + + ;
}
return cnt ? 1 : 0 ;
}
2011-10-31 11:46:24 +00:00
static int mysqlnd_stream_array_from_fd_set ( MYSQLND * * conn_array , fd_set * fds TSRMLS_DC )
2008-11-18 16:54:38 +00:00
{
php_socket_t this_fd ;
int ret = 0 ;
zend_bool disproportion = FALSE ;
MYSQLND * * fwd = conn_array , * * bckwd = conn_array ;
while ( * fwd ) {
2011-10-31 11:46:24 +00:00
if ( SUCCESS = = php_stream_cast ( ( * fwd ) - > data - > net - > stream , PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL ,
2008-11-18 16:54:38 +00:00
( void * ) & this_fd , 1 ) & & this_fd > = 0 ) {
if ( PHP_SAFE_FD_ISSET ( this_fd , fds ) ) {
if ( disproportion ) {
* bckwd = * fwd ;
}
bckwd + + ;
fwd + + ;
ret + + ;
continue ;
}
}
disproportion = TRUE ;
fwd + + ;
}
* bckwd = NULL ; /* NULL-terminate the list */
2009-11-20 08:12:14 +00:00
2008-11-18 16:54:38 +00:00
return ret ;
}
2011-09-25 13:06:09 +00:00
/* }}} */
2008-11-18 16:54:38 +00:00
2011-10-31 11:46:24 +00:00
2008-11-18 16:54:38 +00:00
# ifndef PHP_WIN32
# define php_select(m, r, w, e, t) select(m, r, w, e, t)
# else
# include "win32/select.h"
# endif
2011-10-31 11:46:24 +00:00
2008-11-18 16:54:38 +00:00
/* {{{ _mysqlnd_poll */
2009-06-08 10:19:29 +00:00
PHPAPI enum_func_status
2008-11-18 16:54:38 +00:00
_mysqlnd_poll ( MYSQLND * * r_array , MYSQLND * * e_array , MYSQLND * * * dont_poll , long sec , long usec , uint * desc_num TSRMLS_DC )
{
struct timeval tv ;
struct timeval * tv_p = NULL ;
fd_set rfds , wfds , efds ;
php_socket_t max_fd = 0 ;
int retval , sets = 0 ;
int set_count , max_set_count = 0 ;
2011-10-31 11:46:24 +00:00
DBG_ENTER ( " _mysqlnd_poll " ) ;
2008-11-18 16:54:38 +00:00
if ( sec < 0 | | usec < 0 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Negative values passed for sec and/or usec " ) ;
DBG_RETURN ( FAIL ) ;
}
* dont_poll = mysqlnd_stream_array_check_for_readiness ( r_array TSRMLS_CC ) ;
FD_ZERO ( & rfds ) ;
FD_ZERO ( & wfds ) ;
FD_ZERO ( & efds ) ;
if ( r_array ! = NULL ) {
set_count = mysqlnd_stream_array_to_fd_set ( r_array , & rfds , & max_fd TSRMLS_CC ) ;
if ( set_count > max_set_count ) {
max_set_count = set_count ;
}
sets + = set_count ;
}
if ( e_array ! = NULL ) {
set_count = mysqlnd_stream_array_to_fd_set ( e_array , & efds , & max_fd TSRMLS_CC ) ;
if ( set_count > max_set_count ) {
max_set_count = set_count ;
}
sets + = set_count ;
}
if ( ! sets ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , * dont_poll ? " All arrays passed are clear " : " No stream arrays were passed " ) ;
2010-01-07 19:44:59 +00:00
DBG_ERR_FMT ( * dont_poll ? " All arrays passed are clear " : " No stream arrays were passed " ) ;
2008-11-18 16:54:38 +00:00
DBG_RETURN ( FAIL ) ;
}
PHP_SAFE_MAX_FD ( max_fd , max_set_count ) ;
/* Solaris + BSD do not like microsecond values which are >= 1 sec */
if ( usec > 999999 ) {
tv . tv_sec = sec + ( usec / 1000000 ) ;
2009-11-20 08:12:14 +00:00
tv . tv_usec = usec % 1000000 ;
2008-11-18 16:54:38 +00:00
} else {
tv . tv_sec = sec ;
tv . tv_usec = usec ;
}
tv_p = & tv ;
2009-11-20 08:12:14 +00:00
2008-11-18 16:54:38 +00:00
retval = php_select ( max_fd + 1 , & rfds , & wfds , & efds , tv_p ) ;
if ( retval = = - 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " unable to select [%d]: %s (max_fd=%d) " ,
errno , strerror ( errno ) , max_fd ) ;
DBG_RETURN ( FAIL ) ;
}
if ( r_array ! = NULL ) {
mysqlnd_stream_array_from_fd_set ( r_array , & rfds TSRMLS_CC ) ;
}
if ( e_array ! = NULL ) {
mysqlnd_stream_array_from_fd_set ( e_array , & efds TSRMLS_CC ) ;
}
* desc_num = retval ;
DBG_RETURN ( PASS ) ;
}
/* }}} */
2007-10-02 10:45:27 +00:00
/*
COM_FIELD_LIST is special , different from a SHOW FIELDS FROM :
- There is no result set header - status from the command , which
impacts us to allocate big chunk of memory for reading the metadata .
- The EOF packet is consumed by the metadata packet reader .
*/
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::list_fields */
2007-10-02 10:45:27 +00:00
MYSQLND_RES *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , list_fields ) ( MYSQLND_CONN_DATA * conn , const char * table , const char * achtung_wild TSRMLS_DC )
2007-10-02 10:45:27 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , list_fields ) ;
2007-10-02 10:45:27 +00:00
/* db + \0 + wild + \0 (for wild) */
2011-01-24 12:34:47 +00:00
zend_uchar buff [ MYSQLND_MAX_ALLOWED_DB_LEN * 2 + 1 + 1 ] , * p ;
2007-10-02 10:45:27 +00:00
size_t table_len , wild_len ;
2011-10-25 19:04:36 +00:00
MYSQLND_RES * result = NULL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::list_fields " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu table=%s wild=%s " , conn - > thread_id , table ? table : " " , achtung_wild ? achtung_wild : " " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
do {
p = buff ;
if ( table & & ( table_len = strlen ( table ) ) ) {
size_t to_copy = MIN ( table_len , MYSQLND_MAX_ALLOWED_DB_LEN ) ;
memcpy ( p , table , to_copy ) ;
p + = to_copy ;
* p + + = ' \0 ' ;
}
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( achtung_wild & & ( wild_len = strlen ( achtung_wild ) ) ) {
size_t to_copy = MIN ( wild_len , MYSQLND_MAX_ALLOWED_DB_LEN ) ;
memcpy ( p , achtung_wild , to_copy ) ;
p + = to_copy ;
* p + + = ' \0 ' ;
}
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS ! = conn - > m - > simple_command ( conn , COM_FIELD_LIST , buff , p - buff ,
PROT_LAST /* we will handle the OK packet*/ ,
FALSE , TRUE TSRMLS_CC ) ) {
conn - > m - > local_tx_end ( conn , 0 , FAIL TSRMLS_CC ) ;
break ;
}
2010-09-23 16:03:22 +00:00
2011-10-25 19:04:36 +00:00
/*
Prepare for the worst case .
MyISAM goes to 2500 BIT columns , double it for safety .
*/
result = conn - > m - > result_init ( 5000 , conn - > persistent TSRMLS_CC ) ;
if ( ! result ) {
break ;
}
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( FAIL = = result - > m . read_result_metadata ( result , conn TSRMLS_CC ) ) {
DBG_ERR ( " Error ocurred while reading metadata " ) ;
result - > m . free_result ( result , TRUE TSRMLS_CC ) ;
result = NULL ;
break ;
}
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
result - > type = MYSQLND_RES_NORMAL ;
result - > m . fetch_row = result - > m . fetch_row_normal_unbuffered ;
result - > unbuf = mnd_ecalloc ( 1 , sizeof ( MYSQLND_RES_UNBUFFERED ) ) ;
if ( ! result - > unbuf ) {
/* OOM */
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-10-25 19:04:36 +00:00
result - > m . free_result ( result , TRUE TSRMLS_CC ) ;
result = NULL ;
break ;
}
result - > unbuf - > eof_reached = TRUE ;
} while ( 0 ) ;
conn - > m - > local_tx_end ( conn , this_func , result = = NULL ? FAIL : PASS TSRMLS_CC ) ;
2010-04-29 13:13:41 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( result ) ;
}
/* }}} */
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::list_method */
2007-07-24 16:13:26 +00:00
MYSQLND_RES *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , list_method ) ( MYSQLND_CONN_DATA * conn , const char * query , const char * achtung_wild , char * par1 TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , list_method ) ;
2011-10-25 19:04:36 +00:00
char * show_query = NULL ;
2007-07-24 16:13:26 +00:00
size_t show_query_len ;
2011-10-25 19:04:36 +00:00
MYSQLND_RES * result = NULL ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::list_method " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " conn=%llu query=%s wild=%u " , conn - > thread_id , query , achtung_wild ) ;
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
if ( par1 ) {
if ( achtung_wild ) {
show_query_len = mnd_sprintf ( & show_query , 0 , query , par1 , achtung_wild ) ;
} else {
show_query_len = mnd_sprintf ( & show_query , 0 , query , par1 ) ;
}
2007-07-24 16:13:26 +00:00
} else {
2011-10-25 19:04:36 +00:00
if ( achtung_wild ) {
show_query_len = mnd_sprintf ( & show_query , 0 , query , achtung_wild ) ;
} else {
show_query_len = strlen ( show_query = ( char * ) query ) ;
}
2009-11-20 08:12:14 +00:00
}
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > query ( conn , show_query , show_query_len TSRMLS_CC ) ) {
result = conn - > m - > store_result ( conn TSRMLS_CC ) ;
}
if ( show_query ! = query ) {
mnd_sprintf_free ( show_query ) ;
}
conn - > m - > local_tx_end ( conn , this_func , result = = NULL ? FAIL : PASS TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( result ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2007-10-02 10:45:27 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::errno */
2007-07-24 16:13:26 +00:00
static unsigned int
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , errno ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > error_info - > error_no ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::error */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , error ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > error_info - > error ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::sqlstate */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , sqlstate ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > error_info - > sqlstate [ 0 ] ? conn - > error_info - > sqlstate : MYSQLND_SQLSTATE_NULL ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
/* {{{ mysqlnd_old_escape_string */
2011-10-31 11:46:24 +00:00
PHPAPI ulong
mysqlnd_old_escape_string ( char * newstr , const char * escapestr , size_t escapestr_len TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2007-10-02 10:45:27 +00:00
DBG_ENTER ( " mysqlnd_old_escape_string " ) ;
2010-08-12 11:38:08 +00:00
DBG_RETURN ( mysqlnd_cset_escape_slashes ( mysqlnd_find_charset_name ( " latin1 " ) , newstr , escapestr , escapestr_len TSRMLS_CC ) ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 11:46:24 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::ssl_set */
2010-08-06 19:47:03 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , ssl_set ) ( MYSQLND_CONN_DATA * const conn , const char * key , const char * const cert ,
2011-10-31 11:46:24 +00:00
const char * const ca , const char * const capath , const char * const cipher TSRMLS_DC )
2010-04-15 11:01:30 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , ssl_set ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::ssl_set " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = ( PASS = = conn - > net - > m . set_client_option ( conn - > net , MYSQLND_OPT_SSL_KEY , key TSRMLS_CC ) & &
PASS = = conn - > net - > m . set_client_option ( conn - > net , MYSQLND_OPT_SSL_CERT , cert TSRMLS_CC ) & &
PASS = = conn - > net - > m . set_client_option ( conn - > net , MYSQLND_OPT_SSL_CA , ca TSRMLS_CC ) & &
PASS = = conn - > net - > m . set_client_option ( conn - > net , MYSQLND_OPT_SSL_CAPATH , capath TSRMLS_CC ) & &
PASS = = conn - > net - > m . set_client_option ( conn - > net , MYSQLND_OPT_SSL_CIPHER , cipher TSRMLS_CC ) ) ? PASS : FAIL ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
2010-04-15 11:01:30 +00:00
}
/* }}} */
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::escape_string */
2007-07-24 16:13:26 +00:00
static ulong
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , escape_string ) ( MYSQLND_CONN_DATA * const conn , char * newstr , const char * escapestr , size_t escapestr_len TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , escape_string ) ;
2011-10-25 19:04:36 +00:00
ulong ret ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::escape_string " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
2011-10-25 23:01:49 +00:00
if ( conn - > upsert_status - > server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES ) {
2011-10-25 19:04:36 +00:00
ret = mysqlnd_cset_escape_quotes ( conn - > charset , newstr , escapestr , escapestr_len TSRMLS_CC ) ;
} else {
ret = mysqlnd_cset_escape_slashes ( conn - > charset , newstr , escapestr , escapestr_len TSRMLS_CC ) ;
}
conn - > m - > local_tx_end ( conn , this_func , PASS TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
2011-10-25 19:04:36 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::dump_debug_info */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , dump_debug_info ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , server_dump_debug_information ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::dump_debug_info " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > simple_command ( conn , COM_DEBUG , NULL , 0 , PROT_EOF_PACKET , FALSE , TRUE TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::select_db */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , select_db ) ( MYSQLND_CONN_DATA * const conn , const char * const db , unsigned int db_len TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , select_db ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-10-02 10:45:27 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::select_db " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu db=%s " , conn - > thread_id , db ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > simple_command ( conn , COM_INIT_DB , ( zend_uchar * ) db , db_len , PROT_OK_PACKET , FALSE , TRUE TSRMLS_CC ) ;
/*
The server sends 0 but libmysql doesn ' t read it and has established
a protocol of giving back - 1. Thus we have to follow it : (
*/
SET_ERROR_AFF_ROWS ( conn ) ;
if ( ret = = PASS ) {
if ( conn - > connect_or_select_db ) {
mnd_pefree ( conn - > connect_or_select_db , conn - > persistent ) ;
}
conn - > connect_or_select_db = mnd_pestrndup ( db , db_len , conn - > persistent ) ;
conn - > connect_or_select_db_len = db_len ;
if ( ! conn - > connect_or_select_db ) {
/* OOM */
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-10-25 19:04:36 +00:00
ret = FAIL ;
}
2010-04-29 15:49:51 +00:00
}
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2009-10-22 17:07:55 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::ping */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , ping ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , ping ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-10-02 10:45:27 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::ping " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > simple_command ( conn , COM_PING , NULL , 0 , PROT_OK_PACKET , TRUE , TRUE TSRMLS_CC ) ;
/*
The server sends 0 but libmysql doesn ' t read it and has established
a protocol of giving back - 1. Thus we have to follow it : (
*/
SET_ERROR_AFF_ROWS ( conn ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " ret=%u " , ret ) ;
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::statistic */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , statistic ) ( MYSQLND_CONN_DATA * conn , char * * message , unsigned int * message_len TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , get_server_statistics ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2010-01-11 20:10:10 +00:00
MYSQLND_PACKET_STATS * stats_header ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::statistic " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
do {
ret = conn - > m - > simple_command ( conn , COM_STATISTICS , NULL , 0 , PROT_LAST , FALSE , TRUE TSRMLS_CC ) ;
if ( FAIL = = ret ) {
break ;
}
stats_header = conn - > protocol - > m . get_stats_packet ( conn - > protocol , FALSE TSRMLS_CC ) ;
if ( ! stats_header ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-10-25 19:04:36 +00:00
break ;
}
2010-05-25 23:18:13 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = ( ret = PACKET_READ ( stats_header , conn ) ) ) {
/* will be freed by Zend, thus don't use the mnd_ allocator */
* message = estrndup ( stats_header - > message , stats_header - > message_len ) ;
* message_len = stats_header - > message_len ;
DBG_INF ( * message ) ;
}
PACKET_FREE ( stats_header ) ;
} while ( 0 ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::kill */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , kill ) ( MYSQLND_CONN_DATA * conn , unsigned int pid TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , kill_connection ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-01-24 12:34:47 +00:00
zend_uchar buff [ 4 ] ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::kill " ) ;
2011-08-26 12:14:31 +00:00
DBG_INF_FMT ( " conn=%llu pid=%u " , conn - > thread_id , pid ) ;
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
int4store ( buff , pid ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
/* If we kill ourselves don't expect OK packet, PROT_LAST will skip it */
if ( pid ! = conn - > thread_id ) {
ret = conn - > m - > simple_command ( conn , COM_PROCESS_KILL , buff , 4 , PROT_OK_PACKET , FALSE , TRUE TSRMLS_CC ) ;
/*
The server sends 0 but libmysql doesn ' t read it and has established
a protocol of giving back - 1. Thus we have to follow it : (
*/
SET_ERROR_AFF_ROWS ( conn ) ;
} else if ( PASS = = ( ret = conn - > m - > simple_command ( conn , COM_PROCESS_KILL , buff , 4 , PROT_LAST , FALSE , TRUE TSRMLS_CC ) ) ) {
CONN_SET_STATE ( conn , CONN_QUIT_SENT ) ;
}
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::set_charset */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , set_charset ) ( MYSQLND_CONN_DATA * const conn , const char * const csname TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , set_charset ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-07-24 16:13:26 +00:00
const MYSQLND_CHARSET * const charset = mysqlnd_find_charset_name ( csname ) ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::set_charset " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu cs=%s " , conn - > thread_id , csname ) ;
2007-07-24 16:13:26 +00:00
if ( ! charset ) {
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_CANT_FIND_CHARSET , UNKNOWN_SQLSTATE ,
2007-07-24 16:13:26 +00:00
" Invalid characterset or character set not supported " ) ;
2011-10-25 19:04:36 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
char * query ;
size_t query_len = mnd_sprintf ( & query , 0 , " SET NAMES %s " , csname ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
if ( FAIL = = ( ret = conn - > m - > query ( conn , query , query_len TSRMLS_CC ) ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Error executing query " ) ;
2011-10-25 23:01:49 +00:00
} else if ( conn - > error_info - > error_no ) {
2011-10-25 19:04:36 +00:00
ret = FAIL ;
} else {
conn - > charset = charset ;
}
mnd_sprintf_free ( query ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_INF ( ret = = PASS ? " PASS " : " FAIL " ) ;
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::refresh */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , refresh ) ( MYSQLND_CONN_DATA * const conn , uint8_t options TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , refresh_server ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-07-24 16:13:26 +00:00
zend_uchar bits [ 1 ] ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::refresh " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu options=%lu " , conn - > thread_id , options ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
int1store ( bits , options ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
ret = conn - > m - > simple_command ( conn , COM_REFRESH , bits , 1 , PROT_OK_PACKET , FALSE , TRUE TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::shutdown */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , shutdown ) ( MYSQLND_CONN_DATA * const conn , uint8_t level TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , shutdown_server ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-07-24 16:13:26 +00:00
zend_uchar bits [ 1 ] ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::shutdown " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu level=%lu " , conn - > thread_id , level ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
int1store ( bits , level ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
ret = conn - > m - > simple_command ( conn , COM_SHUTDOWN , bits , 1 , PROT_OK_PACKET , FALSE , TRUE TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
/* {{{ mysqlnd_send_close */
2008-01-28 18:27:49 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , send_close ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
enum_func_status ret = PASS ;
2007-10-02 10:45:27 +00:00
DBG_ENTER ( " mysqlnd_send_close " ) ;
2009-12-11 11:58:57 +00:00
DBG_INF_FMT ( " conn=%llu conn->net->stream->abstract=%p " ,
conn - > thread_id , conn - > net - > stream ? conn - > net - > stream - > abstract : NULL ) ;
2007-10-02 10:45:27 +00:00
2011-11-02 15:08:01 +00:00
if ( CONN_GET_STATE ( conn ) > = CONN_READY ) {
MYSQLND_DEC_CONN_STATISTIC ( conn - > stats , STAT_OPENED_CONNECTIONS ) ;
if ( conn - > persistent ) {
MYSQLND_DEC_CONN_STATISTIC ( conn - > stats , STAT_OPENED_PERSISTENT_CONNECTIONS ) ;
}
}
2008-01-28 18:27:49 +00:00
switch ( CONN_GET_STATE ( conn ) ) {
2007-07-24 16:13:26 +00:00
case CONN_READY :
2007-10-02 10:45:27 +00:00
DBG_INF ( " Connection clean, sending COM_QUIT " ) ;
2009-12-11 11:58:57 +00:00
if ( conn - > net - > stream ) {
2011-10-31 11:46:24 +00:00
ret = conn - > m - > simple_command ( conn , COM_QUIT , NULL , 0 , PROT_LAST , TRUE , TRUE TSRMLS_CC ) ;
2009-08-27 13:16:39 +00:00
}
2007-07-24 16:13:26 +00:00
/* Do nothing */
break ;
case CONN_SENDING_LOAD_DATA :
/*
Don ' t send COM_QUIT if we are in a middle of a LOAD DATA or we
will crash ( assert ) a debug server .
*/
case CONN_NEXT_RESULT_PENDING :
case CONN_QUERY_SENT :
case CONN_FETCHING_DATA :
2007-10-02 10:45:27 +00:00
MYSQLND_INC_GLOBAL_STATISTIC ( STAT_CLOSE_IN_MIDDLE ) ;
DBG_ERR_FMT ( " Brutally closing connection [%p][%s] " , conn , conn - > scheme ) ;
2007-07-24 16:13:26 +00:00
/*
Do nothing , the connection will be brutally closed
and the server will catch it and free close from its side .
*/
case CONN_ALLOCED :
/*
Allocated but not connected or there was failure when trying
to connect with pre - allocated connect .
Fall - through
*/
case CONN_QUIT_SENT :
/* The user has killed its own connection */
break ;
}
/*
We hold one reference , and every other object which needs the
connection does increase it by 1.
*/
2008-01-28 18:27:49 +00:00
CONN_SET_STATE ( conn , CONN_QUIT_SENT ) ;
2007-07-24 16:13:26 +00:00
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_reference */
2011-10-31 11:46:24 +00:00
static MYSQLND_CONN_DATA *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , get_reference ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::get_reference " ) ;
2007-07-24 16:13:26 +00:00
+ + conn - > refcount ;
2008-04-24 14:04:58 +00:00
DBG_INF_FMT ( " conn=%llu new_refcount=%u " , conn - > thread_id , conn - > refcount ) ;
DBG_RETURN ( conn ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::free_reference */
2007-10-02 10:45:27 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , free_reference ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2007-10-02 10:45:27 +00:00
enum_func_status ret = PASS ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::free_reference " ) ;
2008-04-24 14:04:58 +00:00
DBG_INF_FMT ( " conn=%llu old_refcount=%u " , conn - > thread_id , conn - > refcount ) ;
2007-07-24 16:13:26 +00:00
if ( ! ( - - conn - > refcount ) ) {
/*
No multithreading issues as we don ' t share the connection : )
This will free the object too , of course because references has
reached zero .
*/
2010-02-09 19:05:40 +00:00
ret = conn - > m - > send_close ( conn TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
conn - > m - > dtor ( conn TSRMLS_CC ) ;
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_state */
2008-01-28 18:27:49 +00:00
static enum mysqlnd_connection_state
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , get_state ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2008-01-28 18:27:49 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::get_state " ) ;
2008-01-28 18:27:49 +00:00
DBG_RETURN ( conn - > state ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::set_state */
2008-01-28 18:27:49 +00:00
static void
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , set_state ) ( MYSQLND_CONN_DATA * const conn , enum mysqlnd_connection_state new_state TSRMLS_DC )
2008-01-28 18:27:49 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::set_state " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " New state=%u " , new_state ) ;
2008-01-28 18:27:49 +00:00
conn - > state = new_state ;
DBG_VOID_RETURN ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::field_count */
2007-07-24 16:13:26 +00:00
static unsigned int
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , field_count ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > field_count ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::server_status */
2011-10-25 23:01:49 +00:00
static unsigned int
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , server_status ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2011-10-25 23:01:49 +00:00
{
return conn - > upsert_status - > server_status ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::insert_id */
2008-10-31 20:30:33 +00:00
static uint64_t
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , insert_id ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > upsert_status - > last_insert_id ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::affected_rows */
2008-10-31 20:30:33 +00:00
static uint64_t
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , affected_rows ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > upsert_status - > affected_rows ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::warning_count */
2007-07-24 16:13:26 +00:00
static unsigned int
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , warning_count ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-25 23:01:49 +00:00
return conn - > upsert_status - > warning_count ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::info */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , info ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > last_message ;
}
/* }}} */
/* {{{ mysqlnd_get_client_info */
PHPAPI const char * mysqlnd_get_client_info ( )
{
return MYSQLND_VERSION ;
}
/* }}} */
/* {{{ mysqlnd_get_client_version */
PHPAPI unsigned int mysqlnd_get_client_version ( )
{
return MYSQLND_VERSION_ID ;
}
/* }}} */
2011-10-31 11:46:24 +00:00
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_server_info */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , get_server_info ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > server_version ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_host_info */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , get_host_info ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > host_info ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_proto_info */
2007-07-24 16:13:26 +00:00
static unsigned int
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , get_proto_info ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > protocol_version ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::charset_name */
2007-07-24 16:13:26 +00:00
static const char *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , charset_name ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > charset - > name ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::thread_id */
2008-10-31 20:30:33 +00:00
static uint64_t
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , thread_id ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
return conn - > thread_id ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_server_version */
2007-07-24 16:13:26 +00:00
static unsigned long
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , get_server_version ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
long major , minor , patch ;
char * p ;
if ( ! ( p = conn - > server_version ) ) {
return 0 ;
}
major = strtol ( p , & p , 10 ) ;
p + = 1 ; /* consume the dot */
minor = strtol ( p , & p , 10 ) ;
p + = 1 ; /* consume the dot */
patch = strtol ( p , & p , 10 ) ;
2009-11-20 08:12:14 +00:00
2007-07-24 16:13:26 +00:00
return ( unsigned long ) ( major * 10000L + ( unsigned long ) ( minor * 100L + patch ) ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::more_results */
2007-07-24 16:13:26 +00:00
static zend_bool
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , more_results ) ( const MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::more_results " ) ;
2007-07-24 16:13:26 +00:00
/* (conn->state == CONN_NEXT_RESULT_PENDING) too */
2011-10-25 23:01:49 +00:00
DBG_RETURN ( conn - > upsert_status - > server_status & SERVER_MORE_RESULTS_EXISTS ? TRUE : FALSE ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::next_result */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , next_result ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , next_result ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::next_result " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
do {
if ( CONN_GET_STATE ( conn ) ! = CONN_NEXT_RESULT_PENDING ) {
break ;
}
2007-07-24 16:13:26 +00:00
2011-10-25 23:01:49 +00:00
SET_EMPTY_ERROR ( * conn - > error_info ) ;
2011-10-25 19:04:36 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
/*
We are sure that there is a result set , since conn - > state is set accordingly
in mysqlnd_store_result ( ) or mysqlnd_fetch_row_unbuffered ( )
*/
if ( FAIL = = ( ret = conn - > m - > query_read_result_set_header ( conn , NULL TSRMLS_CC ) ) ) {
/*
There can be an error in the middle of a multi - statement , which will cancel the multi - statement .
So there are no more results and we should just return FALSE , error_no has been set
*/
2011-10-25 23:01:49 +00:00
if ( ! conn - > error_info - > error_no ) {
2011-10-25 19:04:36 +00:00
DBG_ERR_FMT ( " Serious error. %s::%u " , __FILE__ , __LINE__ ) ;
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Serious error. PID=%d " , getpid ( ) ) ;
CONN_SET_STATE ( conn , CONN_QUIT_SENT ) ;
} else {
2011-10-25 23:01:49 +00:00
DBG_INF_FMT ( " Error from the server : (%u) %s " , conn - > error_info - > error_no , conn - > error_info - > error ) ;
2011-10-25 19:04:36 +00:00
}
break ;
}
2011-10-25 23:01:49 +00:00
if ( conn - > last_query_type = = QUERY_UPSERT & & conn - > upsert_status - > affected_rows ) {
MYSQLND_INC_CONN_STATISTIC_W_VALUE ( conn - > stats , STAT_ROWS_AFFECTED_NORMAL , conn - > upsert_status - > affected_rows ) ;
2011-10-25 19:04:36 +00:00
}
} while ( 0 ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2010-12-16 12:56:19 +00:00
}
2007-07-24 16:13:26 +00:00
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
/* {{{ mysqlnd_field_type_name */
PHPAPI const char * mysqlnd_field_type_name ( enum mysqlnd_field_types field_type )
{
switch ( field_type ) {
case FIELD_TYPE_STRING :
case FIELD_TYPE_VAR_STRING :
return " string " ;
case FIELD_TYPE_TINY :
case FIELD_TYPE_SHORT :
case FIELD_TYPE_LONG :
case FIELD_TYPE_LONGLONG :
case FIELD_TYPE_INT24 :
return " int " ;
case FIELD_TYPE_FLOAT :
case FIELD_TYPE_DOUBLE :
case FIELD_TYPE_DECIMAL :
case FIELD_TYPE_NEWDECIMAL :
return " real " ;
case FIELD_TYPE_TIMESTAMP :
return " timestamp " ;
case FIELD_TYPE_YEAR :
return " year " ;
case FIELD_TYPE_DATE :
case FIELD_TYPE_NEWDATE :
return " date " ;
case FIELD_TYPE_TIME :
return " time " ;
case FIELD_TYPE_SET :
return " set " ;
case FIELD_TYPE_ENUM :
return " enum " ;
case FIELD_TYPE_GEOMETRY :
return " geometry " ;
case FIELD_TYPE_DATETIME :
return " datetime " ;
case FIELD_TYPE_TINY_BLOB :
case FIELD_TYPE_MEDIUM_BLOB :
case FIELD_TYPE_LONG_BLOB :
case FIELD_TYPE_BLOB :
return " blob " ;
case FIELD_TYPE_NULL :
return " null " ;
case FIELD_TYPE_BIT :
return " bit " ;
default :
return " unknown " ;
}
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::change_user */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , change_user ) ( MYSQLND_CONN_DATA * const conn ,
2011-10-31 11:46:24 +00:00
const char * user ,
const char * passwd ,
const char * db ,
2011-01-14 13:00:42 +00:00
zend_bool silent ,
size_t passwd_len
TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , change_user ) ;
2007-07-24 16:13:26 +00:00
/*
User could be max 16 * 3 ( utf8 ) , pass is 20 usually , db is up to 64 * 3
Stack space is not that expensive , so use a bit more to be protected against
2010-04-27 08:26:24 +00:00
buffer overflows .
2007-07-24 16:13:26 +00:00
*/
2010-05-25 23:18:13 +00:00
enum_func_status ret = FAIL ;
2011-10-25 19:04:36 +00:00
zend_bool local_tx_started = FALSE ;
2011-01-11 13:02:57 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::change_user " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " conn=%llu user=%s passwd=%s db=%s silent=%u " ,
2009-10-15 20:46:08 +00:00
conn - > thread_id , user ? user : " " , passwd ? " *** " : " null " , db ? db : " " , ( silent = = TRUE ) ? 1 : 0 ) ;
2007-10-02 10:45:27 +00:00
2011-10-25 19:04:36 +00:00
if ( PASS ! = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
goto end ;
}
local_tx_started = TRUE ;
2011-10-25 23:01:49 +00:00
SET_EMPTY_ERROR ( * conn - > error_info ) ;
2010-05-25 23:18:13 +00:00
SET_ERROR_AFF_ROWS ( conn ) ;
2007-07-24 16:13:26 +00:00
if ( ! user ) {
user = " " ;
}
if ( ! passwd ) {
passwd = " " ;
}
if ( ! db ) {
db = " " ;
}
2010-04-29 15:49:51 +00:00
2011-01-12 21:40:05 +00:00
{
2011-01-24 12:34:47 +00:00
zend_bool first_call = TRUE ;
2011-01-12 21:40:05 +00:00
char * switch_to_auth_protocol = NULL ;
2011-01-24 12:34:47 +00:00
size_t switch_to_auth_protocol_len = 0 ;
char * requested_protocol = NULL ;
zend_uchar * plugin_data ;
size_t plugin_data_len ;
plugin_data_len = conn - > auth_plugin_data_len ;
plugin_data = mnd_emalloc ( plugin_data_len ) ;
if ( ! plugin_data ) {
ret = FAIL ;
goto end ;
}
memcpy ( plugin_data , conn - > auth_plugin_data , plugin_data_len ) ;
2011-10-25 23:01:49 +00:00
requested_protocol = mnd_pestrdup ( conn - > options - > auth_protocol ? conn - > options - > auth_protocol : " mysql_native_password " , FALSE ) ;
2011-01-24 12:34:47 +00:00
if ( ! requested_protocol ) {
ret = FAIL ;
goto end ;
}
2011-01-12 21:40:05 +00:00
do {
struct st_mysqlnd_authentication_plugin * auth_plugin ;
2011-01-24 12:34:47 +00:00
{
char * plugin_name = NULL ;
2011-03-18 14:56:20 +00:00
mnd_sprintf ( & plugin_name , 0 , " auth_plugin_%s " , requested_protocol ) ;
2011-01-24 12:34:47 +00:00
DBG_INF_FMT ( " looking for %s auth plugin " , plugin_name ) ;
auth_plugin = mysqlnd_plugin_find ( plugin_name ) ;
2011-03-18 14:56:20 +00:00
mnd_sprintf_free ( plugin_name ) ;
2011-01-24 12:34:47 +00:00
if ( ! auth_plugin ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " The server requested authentication method unknown to the client [%s] " , requested_protocol ) ;
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_NOT_IMPLEMENTED , UNKNOWN_SQLSTATE , " The server requested authentication method umknown to the client " ) ;
2011-01-24 12:34:47 +00:00
break ;
2011-01-12 21:40:05 +00:00
}
2011-01-24 12:34:47 +00:00
}
2011-01-12 21:40:05 +00:00
DBG_INF ( " plugin found " ) ;
2011-01-14 20:04:17 +00:00
2011-01-24 12:34:47 +00:00
{
zend_uchar * switch_to_auth_protocol_data = NULL ;
size_t switch_to_auth_protocol_data_len = 0 ;
zend_uchar * scrambled_data = NULL ;
size_t scrambled_data_len = 0 ;
switch_to_auth_protocol = NULL ;
switch_to_auth_protocol_len = 0 ;
if ( conn - > auth_plugin_data ) {
mnd_pefree ( conn - > auth_plugin_data , conn - > persistent ) ;
conn - > auth_plugin_data = NULL ;
}
conn - > auth_plugin_data_len = plugin_data_len ;
conn - > auth_plugin_data = mnd_pemalloc ( conn - > auth_plugin_data_len , conn - > persistent ) ;
if ( ! conn - > auth_plugin_data ) {
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-01-24 12:34:47 +00:00
ret = FAIL ;
goto end ;
}
memcpy ( conn - > auth_plugin_data , plugin_data , plugin_data_len ) ;
DBG_INF_FMT ( " salt=[%*s] " , plugin_data_len - 1 , plugin_data ) ;
/* The data should be allocated with malloc() */
scrambled_data =
auth_plugin - > methods . get_auth_data ( NULL , & scrambled_data_len , conn , user , passwd , passwd_len ,
plugin_data , plugin_data_len , 0 , conn - > server_capabilities TSRMLS_CC ) ;
2011-01-24 13:58:18 +00:00
ret = mysqlnd_auth_change_user ( conn , user , strlen ( user ) , passwd , passwd_len , db , strlen ( db ) , silent ,
2011-01-24 12:34:47 +00:00
first_call ,
requested_protocol ,
scrambled_data , scrambled_data_len ,
& switch_to_auth_protocol , & switch_to_auth_protocol_len ,
& switch_to_auth_protocol_data , & switch_to_auth_protocol_data_len
TSRMLS_CC ) ;
first_call = FALSE ;
free ( scrambled_data ) ;
DBG_INF_FMT ( " switch_to_auth_protocol=%s " , switch_to_auth_protocol ? switch_to_auth_protocol : " n/a " ) ;
if ( requested_protocol ) {
mnd_efree ( requested_protocol ) ;
}
requested_protocol = switch_to_auth_protocol ;
if ( plugin_data ) {
mnd_efree ( plugin_data ) ;
}
plugin_data_len = switch_to_auth_protocol_data_len ;
plugin_data = switch_to_auth_protocol_data ;
}
2011-10-25 23:01:49 +00:00
DBG_INF_FMT ( " conn->error_info->error_no = %d " , conn - > error_info - > error_no ) ;
} while ( ret = = FAIL & & conn - > error_info - > error_no = = 0 & & switch_to_auth_protocol ! = NULL ) ;
2011-01-24 12:34:47 +00:00
if ( plugin_data ) {
mnd_efree ( plugin_data ) ;
}
2011-01-12 21:40:05 +00:00
if ( ret = = PASS ) {
conn - > m - > set_client_option ( conn , MYSQLND_OPT_AUTH_PROTOCOL , requested_protocol TSRMLS_CC ) ;
2007-10-02 10:45:27 +00:00
}
2011-01-24 12:34:47 +00:00
if ( requested_protocol ) {
mnd_efree ( requested_protocol ) ;
2010-06-14 17:16:20 +00:00
}
2007-10-02 10:45:27 +00:00
}
2007-07-24 16:13:26 +00:00
/*
Here we should close all statements . Unbuffered queries should not be a
problem as we won ' t allow sending COM_CHANGE_USER .
*/
2011-01-24 12:34:47 +00:00
end :
2011-10-25 19:04:36 +00:00
if ( TRUE = = local_tx_started ) {
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2007-10-02 10:45:27 +00:00
DBG_INF ( ret = = PASS ? " PASS " : " FAIL " ) ;
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::set_client_option */
2007-07-24 16:13:26 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , set_client_option ) ( MYSQLND_CONN_DATA * const conn ,
2007-07-24 16:13:26 +00:00
enum mysqlnd_option option ,
2007-10-02 10:45:27 +00:00
const char * const value
TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , set_client_option ) ;
2010-04-29 15:49:51 +00:00
enum_func_status ret = PASS ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::set_client_option " ) ;
2010-06-21 15:32:26 +00:00
DBG_INF_FMT ( " conn=%llu option=%u " , conn - > thread_id , option ) ;
2011-10-25 19:04:36 +00:00
if ( PASS ! = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
goto end ;
}
2007-07-24 16:13:26 +00:00
switch ( option ) {
2009-12-15 13:13:51 +00:00
case MYSQL_OPT_COMPRESS :
# ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_READ_TIMEOUT :
case MYSQL_OPT_WRITE_TIMEOUT :
# endif
2010-04-15 11:01:30 +00:00
case MYSQLND_OPT_SSL_KEY :
case MYSQLND_OPT_SSL_CERT :
case MYSQLND_OPT_SSL_CA :
case MYSQLND_OPT_SSL_CAPATH :
case MYSQLND_OPT_SSL_CIPHER :
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT :
2009-12-15 13:13:51 +00:00
case MYSQL_OPT_CONNECT_TIMEOUT :
case MYSQLND_OPT_NET_CMD_BUFFER_SIZE :
case MYSQLND_OPT_NET_READ_BUFFER_SIZE :
2010-04-29 15:49:51 +00:00
ret = conn - > net - > m . set_client_option ( conn - > net , option , value TSRMLS_CC ) ;
2009-12-15 13:13:51 +00:00
break ;
2010-08-12 12:02:02 +00:00
# if MYSQLND_UNICODE
2007-07-24 16:13:26 +00:00
case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE :
2011-10-25 23:01:49 +00:00
conn - > options - > numeric_and_datetime_as_unicode = * ( unsigned int * ) value ;
2007-07-24 16:13:26 +00:00
break ;
2007-10-02 10:45:27 +00:00
# endif
2007-07-24 16:13:26 +00:00
# ifdef MYSQLND_STRING_TO_INT_CONVERSION
2008-09-15 18:10:38 +00:00
case MYSQLND_OPT_INT_AND_FLOAT_NATIVE :
2011-10-25 23:01:49 +00:00
conn - > options - > int_and_float_native = * ( unsigned int * ) value ;
2007-07-24 16:13:26 +00:00
break ;
# endif
case MYSQL_OPT_LOCAL_INFILE :
2008-11-06 10:36:30 +00:00
if ( ! value | | ( * ( unsigned int * ) value ) ? 1 : 0 ) {
2011-10-25 23:01:49 +00:00
conn - > options - > flags | = CLIENT_LOCAL_FILES ;
2007-07-24 16:13:26 +00:00
} else {
2011-10-25 23:01:49 +00:00
conn - > options - > flags & = ~ CLIENT_LOCAL_FILES ;
2007-07-24 16:13:26 +00:00
}
break ;
2009-08-27 13:16:39 +00:00
case MYSQL_INIT_COMMAND :
2010-05-03 13:45:58 +00:00
{
char * * new_init_commands ;
char * new_command ;
2009-08-27 13:16:39 +00:00
/* when num_commands is 0, then realloc will be effectively a malloc call, internally */
2011-10-25 23:01:49 +00:00
/* Don't assign to conn->options->init_commands because in case of OOM we will lose the pointer and leak */
new_init_commands = mnd_perealloc ( conn - > options - > init_commands , sizeof ( char * ) * ( conn - > options - > num_commands + 1 ) , conn - > persistent ) ;
2010-05-03 13:45:58 +00:00
if ( ! new_init_commands ) {
2010-04-29 15:49:51 +00:00
goto oom ;
2010-04-29 13:13:41 +00:00
}
2011-10-25 23:01:49 +00:00
conn - > options - > init_commands = new_init_commands ;
2010-05-03 13:45:58 +00:00
new_command = mnd_pestrdup ( value , conn - > persistent ) ;
if ( ! new_command ) {
2010-04-29 15:49:51 +00:00
goto oom ;
2010-04-29 13:13:41 +00:00
}
2011-10-25 23:01:49 +00:00
conn - > options - > init_commands [ conn - > options - > num_commands ] = new_command ;
+ + conn - > options - > num_commands ;
2009-08-27 13:16:39 +00:00
break ;
2010-05-03 13:45:58 +00:00
}
2007-07-24 16:13:26 +00:00
case MYSQL_READ_DEFAULT_FILE :
case MYSQL_READ_DEFAULT_GROUP :
# ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_SET_CLIENT_IP :
case MYSQL_REPORT_DATA_TRUNCATION :
# endif
/* currently not supported. Todo!! */
break ;
case MYSQL_SET_CHARSET_NAME :
2010-05-03 13:45:58 +00:00
{
char * new_charset_name = mnd_pestrdup ( value , conn - > persistent ) ;
if ( ! new_charset_name ) {
goto oom ;
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > charset_name ) {
mnd_pefree ( conn - > options - > charset_name , conn - > persistent ) ;
2010-04-29 15:49:51 +00:00
}
2011-10-25 23:01:49 +00:00
conn - > options - > charset_name = new_charset_name ;
DBG_INF_FMT ( " charset=%s " , conn - > options - > charset_name ) ;
2007-07-24 16:13:26 +00:00
break ;
2010-05-03 13:45:58 +00:00
}
2010-08-09 17:01:57 +00:00
case MYSQL_OPT_NAMED_PIPE :
2011-10-25 23:01:49 +00:00
conn - > options - > protocol = MYSQL_PROTOCOL_PIPE ;
2010-08-09 17:01:57 +00:00
break ;
case MYSQL_OPT_PROTOCOL :
if ( * ( unsigned int * ) value < MYSQL_PROTOCOL_LAST ) {
2011-10-25 23:01:49 +00:00
conn - > options - > protocol = * ( unsigned int * ) value ;
2010-08-09 17:01:57 +00:00
}
break ;
2007-07-24 16:13:26 +00:00
# ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_SET_CHARSET_DIR :
case MYSQL_OPT_RECONNECT :
/* we don't need external character sets, all character sets are
compiled in . For compatibility we just ignore this setting .
Same for protocol , we don ' t support old protocol */
case MYSQL_OPT_USE_REMOTE_CONNECTION :
case MYSQL_OPT_USE_EMBEDDED_CONNECTION :
case MYSQL_OPT_GUESS_CONNECTION :
/* todo: throw an error, we don't support embedded */
break ;
# endif
2011-01-12 21:40:05 +00:00
case MYSQLND_OPT_MAX_ALLOWED_PACKET :
if ( * ( unsigned int * ) value > ( 1 < < 16 ) ) {
2011-10-25 23:01:49 +00:00
conn - > options - > max_allowed_packet = * ( unsigned int * ) value ;
2011-01-12 21:40:05 +00:00
}
break ;
case MYSQLND_OPT_AUTH_PROTOCOL :
{
2011-01-24 12:34:47 +00:00
char * new_auth_protocol = value ? mnd_pestrdup ( value , conn - > persistent ) : NULL ;
if ( value & & ! new_auth_protocol ) {
2011-01-12 21:40:05 +00:00
goto oom ;
}
2011-10-25 23:01:49 +00:00
if ( conn - > options - > auth_protocol ) {
mnd_pefree ( conn - > options - > auth_protocol , conn - > persistent ) ;
2011-01-12 21:40:05 +00:00
}
2011-10-25 23:01:49 +00:00
conn - > options - > auth_protocol = new_auth_protocol ;
DBG_INF_FMT ( " auth_protocol=%s " , conn - > options - > auth_protocol ) ;
2011-01-12 21:40:05 +00:00
break ;
}
2007-07-24 16:13:26 +00:00
# ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_SHARED_MEMORY_BASE_NAME :
case MYSQL_OPT_USE_RESULT :
case MYSQL_SECURE_AUTH :
/* not sure, todo ? */
# endif
default :
2010-04-29 15:49:51 +00:00
ret = FAIL ;
2007-07-24 16:13:26 +00:00
}
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
2010-04-29 15:49:51 +00:00
DBG_RETURN ( ret ) ;
oom :
2011-10-25 23:01:49 +00:00
SET_OOM_ERROR ( * conn - > error_info ) ;
2011-10-25 19:04:36 +00:00
conn - > m - > local_tx_end ( conn , this_func , FAIL TSRMLS_CC ) ;
end :
2010-04-29 15:49:51 +00:00
DBG_RETURN ( FAIL ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::use_result */
2008-01-23 19:09:33 +00:00
static MYSQLND_RES *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , use_result ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , use_result ) ;
2011-10-25 19:04:36 +00:00
MYSQLND_RES * result = NULL ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::use_result " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
do {
if ( ! conn - > current_result ) {
break ;
}
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
/* Nothing to store for UPSERT/LOAD DATA */
if ( conn - > last_query_type ! = QUERY_SELECT | | CONN_GET_STATE ( conn ) ! = CONN_FETCHING_DATA ) {
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_COMMANDS_OUT_OF_SYNC , UNKNOWN_SQLSTATE , mysqlnd_out_of_sync ) ;
2011-10-25 19:04:36 +00:00
DBG_ERR ( " Command out of sync " ) ;
break ;
}
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_UNBUFFERED_SETS ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
conn - > current_result - > conn = conn - > m - > get_reference ( conn TSRMLS_CC ) ;
result = conn - > current_result - > m . use_result ( conn - > current_result , FALSE TSRMLS_CC ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
if ( ! result ) {
conn - > current_result - > m . free_result ( conn - > current_result , TRUE TSRMLS_CC ) ;
}
conn - > current_result = NULL ;
} while ( 0 ) ;
conn - > m - > local_tx_end ( conn , this_func , result = = NULL ? FAIL : PASS TSRMLS_CC ) ;
2010-05-03 17:07:18 +00:00
}
2010-09-23 16:03:22 +00:00
2007-10-02 10:45:27 +00:00
DBG_RETURN ( result ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::store_result */
2008-01-23 19:09:33 +00:00
static MYSQLND_RES *
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , store_result ) ( MYSQLND_CONN_DATA * const conn TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , store_result ) ;
2011-10-25 19:04:36 +00:00
MYSQLND_RES * result = NULL ;
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::store_result " ) ;
2007-10-02 10:45:27 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
do {
if ( ! conn - > current_result ) {
break ;
}
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
/* Nothing to store for UPSERT/LOAD DATA*/
if ( conn - > last_query_type ! = QUERY_SELECT | | CONN_GET_STATE ( conn ) ! = CONN_FETCHING_DATA ) {
2011-10-25 23:01:49 +00:00
SET_CLIENT_ERROR ( * conn - > error_info , CR_COMMANDS_OUT_OF_SYNC , UNKNOWN_SQLSTATE , mysqlnd_out_of_sync ) ;
2011-10-25 19:04:36 +00:00
DBG_ERR ( " Command out of sync " ) ;
break ;
}
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , STAT_BUFFERED_SETS ) ;
2007-07-24 16:13:26 +00:00
2011-10-25 19:04:36 +00:00
result = conn - > current_result - > m . store_result ( conn - > current_result , conn , FALSE TSRMLS_CC ) ;
if ( ! result ) {
conn - > current_result - > m . free_result ( conn - > current_result , TRUE TSRMLS_CC ) ;
}
conn - > current_result = NULL ;
} while ( 0 ) ;
conn - > m - > local_tx_end ( conn , this_func , result = = NULL ? FAIL : PASS TSRMLS_CC ) ;
2010-05-03 17:07:18 +00:00
}
2007-10-02 10:45:27 +00:00
DBG_RETURN ( result ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::get_connection_stats */
2008-01-23 19:09:33 +00:00
static void
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , get_connection_stats ) ( const MYSQLND_CONN_DATA * const conn ,
2011-10-31 11:46:24 +00:00
zval * return_value TSRMLS_DC ZEND_FILE_LINE_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::get_connection_stats " ) ;
2010-01-11 18:27:31 +00:00
mysqlnd_fill_stats_hash ( conn - > stats , mysqlnd_stats_values_names , return_value TSRMLS_CC ZEND_FILE_LINE_CC ) ;
2007-10-02 10:45:27 +00:00
DBG_VOID_RETURN ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::set_autocommit */
2011-02-25 12:25:36 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , set_autocommit ) ( MYSQLND_CONN_DATA * conn , unsigned int mode TSRMLS_DC )
2011-02-25 12:25:36 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , set_autocommit ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::set_autocommit " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > query ( conn , ( mode ) ? " SET AUTOCOMMIT=1 " : " SET AUTOCOMMIT=0 " , sizeof ( " SET AUTOCOMMIT=1 " ) - 1 TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2011-02-25 12:25:36 +00:00
DBG_RETURN ( ret ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::tx_commit */
2011-02-25 12:25:36 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , tx_commit ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2011-02-25 12:25:36 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , tx_commit ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::tx_commit " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > query ( conn , " COMMIT " , sizeof ( " COMMIT " ) - 1 TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2011-02-25 12:25:36 +00:00
DBG_RETURN ( ret ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::tx_rollback */
2011-02-25 12:25:36 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , tx_rollback ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2011-02-25 12:25:36 +00:00
{
2011-10-31 14:33:56 +00:00
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_data_methods , tx_rollback ) ;
2011-10-25 19:04:36 +00:00
enum_func_status ret = FAIL ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::tx_rollback " ) ;
2011-10-25 19:04:36 +00:00
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
ret = conn - > m - > query ( conn , " ROLLBACK " , sizeof ( " ROLLBACK " ) - 1 TSRMLS_CC ) ;
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
}
2011-02-25 12:25:36 +00:00
DBG_RETURN ( ret ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::local_tx_start */
2011-10-25 19:04:36 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , local_tx_start ) ( MYSQLND_CONN_DATA * conn , size_t this_func TSRMLS_DC )
2011-10-25 19:04:36 +00:00
{
enum_func_status ret = PASS ;
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::local_tx_start " ) ;
2011-10-25 19:04:36 +00:00
DBG_RETURN ( ret ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::local_tx_end */
2011-10-25 19:04:36 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , local_tx_end ) ( MYSQLND_CONN_DATA * conn , size_t this_func , enum_func_status status TSRMLS_DC )
2011-10-25 19:04:36 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::local_tx_end " ) ;
2011-10-25 19:04:36 +00:00
DBG_RETURN ( status ) ;
}
/* }}} */
2011-10-31 14:33:56 +00:00
/* {{{ mysqlnd_conn_data::init */
2011-10-21 15:28:58 +00:00
static enum_func_status
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , init ) ( MYSQLND_CONN_DATA * conn TSRMLS_DC )
2011-10-21 15:28:58 +00:00
{
2011-10-31 14:33:56 +00:00
DBG_ENTER ( " mysqlnd_conn_data::init " ) ;
2011-10-21 15:28:58 +00:00
mysqlnd_stats_init ( & conn - > stats , STAT_LAST ) ;
SET_ERROR_AFF_ROWS ( conn ) ;
2011-10-25 23:01:49 +00:00
conn - > net = mysqlnd_net_init ( conn - > persistent , conn - > stats , conn - > error_info TSRMLS_CC ) ;
2011-10-21 15:28:58 +00:00
conn - > protocol = mysqlnd_protocol_init ( conn - > persistent TSRMLS_CC ) ;
DBG_RETURN ( conn - > stats & & conn - > net & & conn - > protocol ? PASS : FAIL ) ;
}
/* }}} */
2011-02-25 12:25:36 +00:00
2011-10-31 14:33:56 +00:00
2011-10-31 11:46:24 +00:00
MYSQLND_STMT * _mysqlnd_stmt_init ( MYSQLND_CONN_DATA * const conn TSRMLS_DC ) ;
2009-12-28 11:17:10 +00:00
2011-10-21 15:28:58 +00:00
2011-10-31 14:33:56 +00:00
MYSQLND_CLASS_METHODS_START ( mysqlnd_conn_data )
MYSQLND_METHOD ( mysqlnd_conn_data , init ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , connect ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , escape_string ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , set_charset ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , query ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , send_query ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , reap_query ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , use_result ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , store_result ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , next_result ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , more_results ) ,
2007-07-24 16:13:26 +00:00
_mysqlnd_stmt_init ,
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , shutdown ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , refresh ) ,
2007-07-24 16:13:26 +00:00
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , ping ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , kill ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , select_db ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , dump_debug_info ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , change_user ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , errno ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , error ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , sqlstate ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , thread_id ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , get_connection_stats ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , get_server_version ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , get_server_info ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , statistic ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , get_host_info ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , get_proto_info ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , info ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , charset_name ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , list_fields ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , list_method ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , insert_id ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , affected_rows ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , warning_count ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , field_count ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , server_status ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , set_server_option ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , set_client_option ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , free_contents ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , free_options ) ,
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , dtor ) ,
2007-07-24 16:13:26 +00:00
2009-11-20 08:12:14 +00:00
mysqlnd_query_read_result_set_header ,
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , get_reference ) ,
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , free_reference ) ,
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , get_state ) ,
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn_data , set_state ) ,
2009-12-11 10:18:00 +00:00
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , simple_command ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , simple_command_handle_response ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , restart_psession ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , end_psession ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , send_close ) ,
2010-04-15 11:01:30 +00:00
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , ssl_set ) ,
2011-02-25 12:25:36 +00:00
mysqlnd_result_init ,
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn_data , set_autocommit ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , tx_commit ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , tx_rollback ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , local_tx_start ) ,
MYSQLND_METHOD ( mysqlnd_conn_data , local_tx_end )
MYSQLND_CLASS_METHODS_END ;
/* {{{ mysqlnd_conn::get_reference */
static MYSQLND *
MYSQLND_METHOD ( mysqlnd_conn , clone_object ) ( MYSQLND * const conn TSRMLS_DC )
{
MYSQLND * ret ;
DBG_ENTER ( " mysqlnd_conn::get_reference " ) ;
ret = MYSQLND_CLASS_METHOD_TABLE_NAME ( mysqlnd_object_factory ) . clone_connection_object ( conn TSRMLS_CC ) ;
DBG_RETURN ( ret ) ;
}
/* }}} */
/* {{{ mysqlnd_conn_data::dtor */
static void
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn , dtor ) ( MYSQLND * conn TSRMLS_DC )
{
2011-11-02 14:20:35 +00:00
DBG_ENTER ( " mysqlnd_conn::dtor " ) ;
2011-10-31 14:33:56 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > data - > thread_id ) ;
conn - > data - > m - > free_reference ( conn - > data TSRMLS_CC ) ;
mnd_pefree ( conn , conn - > persistent ) ;
DBG_VOID_RETURN ;
}
/* }}} */
/* {{{ mysqlnd_conn_data::close */
static enum_func_status
MYSQLND_METHOD ( mysqlnd_conn , close ) ( MYSQLND * conn_handle , enum_connection_close_type close_type TSRMLS_DC )
{
size_t this_func = STRUCT_OFFSET ( struct st_mysqlnd_conn_methods , close ) ;
MYSQLND_CONN_DATA * conn = conn_handle - > data ;
enum_func_status ret = FAIL ;
2011-11-02 14:20:35 +00:00
DBG_ENTER ( " mysqlnd_conn::close " ) ;
2011-10-31 14:33:56 +00:00
DBG_INF_FMT ( " conn=%llu " , conn - > thread_id ) ;
if ( PASS = = conn - > m - > local_tx_start ( conn , this_func TSRMLS_CC ) ) {
if ( CONN_GET_STATE ( conn ) > = CONN_READY ) {
2011-11-02 15:08:01 +00:00
static enum_mysqlnd_collected_stats close_type_to_stat_map [ MYSQLND_CLOSE_LAST ] = {
STAT_CLOSE_EXPLICIT ,
STAT_CLOSE_IMPLICIT ,
STAT_CLOSE_DISCONNECT
} ;
MYSQLND_INC_CONN_STATISTIC ( conn - > stats , close_type_to_stat_map [ close_type ] ) ;
2011-10-31 14:33:56 +00:00
}
/*
Close now , free_reference will try ,
if we are last , but that ' s not a problem .
*/
ret = conn - > m - > send_close ( conn TSRMLS_CC ) ;
2011-11-02 15:08:01 +00:00
/* do it after free_reference/dtor and we might crash */
2011-10-31 14:33:56 +00:00
conn - > m - > local_tx_end ( conn , this_func , ret TSRMLS_CC ) ;
conn_handle - > m - > dtor ( conn_handle TSRMLS_CC ) ;
}
DBG_RETURN ( ret ) ;
}
/* }}} */
MYSQLND_CLASS_METHODS_START ( mysqlnd_conn )
2011-11-02 17:06:30 +00:00
MYSQLND_METHOD ( mysqlnd_conn , connect ) ,
2011-10-31 14:33:56 +00:00
MYSQLND_METHOD ( mysqlnd_conn , clone_object ) ,
MYSQLND_METHOD_PRIVATE ( mysqlnd_conn , dtor ) ,
MYSQLND_METHOD ( mysqlnd_conn , close )
2007-07-24 16:13:26 +00:00
MYSQLND_CLASS_METHODS_END ;
2011-10-24 12:34:44 +00:00
/* {{{ _mysqlnd_init */
PHPAPI MYSQLND *
_mysqlnd_init ( zend_bool persistent TSRMLS_DC )
2007-07-24 16:13:26 +00:00
{
2011-10-24 12:34:44 +00:00
MYSQLND * ret ;
2007-10-02 10:45:27 +00:00
DBG_ENTER ( " mysqlnd_init " ) ;
2011-10-24 12:34:44 +00:00
ret = MYSQLND_CLASS_METHOD_TABLE_NAME ( mysqlnd_object_factory ) . get_connection ( persistent TSRMLS_CC ) ;
2007-10-02 10:45:27 +00:00
DBG_RETURN ( ret ) ;
2007-07-24 16:13:26 +00:00
}
/* }}} */
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
* vim600 : noet sw = 4 ts = 4 fdm = marker
* vim < 600 : noet sw = 4 ts = 4
*/