Skip to content

Commit 31c8104

Browse files
author
Sean Bright
committed
Added the mysql_get_*_info() functions.
# If anyone knows of a version of mysql lower then 3.20.32 that implements # all 3 of these functions, please change the conditionals. @- Added mysql_get_client_info(), mysql_get_server_info(), @ mysql_get_proto_info(), and mysql_get_host_info() functions. (Sean)
1 parent 0611acb commit 31c8104

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

ext/mysql/php_mysql.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static int le_result, le_link, le_plink;
7373
# endif
7474
#endif
7575

76+
#if MYSQL_VERSION_ID >= 32032
77+
#define HAVE_GETINFO_FUNCS
78+
#endif
79+
7680
#if MYSQL_VERSION_ID > 32133 || defined(FIELD_TYPE_TINY)
7781
#define MYSQL_HAS_TINY
7882
#endif
@@ -132,6 +136,12 @@ function_entry mysql_functions[] = {
132136
PHP_FE(mysql_field_type, NULL)
133137
PHP_FE(mysql_field_flags, NULL)
134138
PHP_FE(mysql_escape_string, NULL)
139+
#ifdef HAVE_GETINFO_FUNCS
140+
PHP_FE(mysql_get_client_info, NULL)
141+
PHP_FE(mysql_get_host_info, NULL)
142+
PHP_FE(mysql_get_proto_info, NULL)
143+
PHP_FE(mysql_get_server_info, NULL)
144+
#endif
135145

136146
/* for downwards compatability */
137147
PHP_FALIAS(mysql, mysql_db_query, NULL)
@@ -689,6 +699,115 @@ PHP_FUNCTION(mysql_select_db)
689699
}
690700
/* }}} */
691701

702+
#ifdef HAVE_GETINFO_FUNCS
703+
704+
/* {{{ proto string mysql_get_client_info([int link_identifier])
705+
Returns a string that represents the client library version */
706+
PHP_FUNCTION(mysql_get_client_info)
707+
{
708+
if (ZEND_NUM_ARGS() != 0) {
709+
WRONG_PARAM_COUNT;
710+
}
711+
712+
RETURN_STRING(mysql_get_client_info(),1);
713+
}
714+
/* }}} */
715+
716+
/* {{{ proto string mysql_get_host_info([int link_identifier])
717+
Returns a string describing the type of connection in use, including the
718+
server host name */
719+
PHP_FUNCTION(mysql_get_host_info)
720+
{
721+
zval **mysql_link;
722+
int id;
723+
MYSQL *mysql;
724+
MySLS_FETCH();
725+
726+
switch(ZEND_NUM_ARGS()) {
727+
case 0:
728+
id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU MySLS_CC);
729+
CHECK_LINK(id);
730+
break;
731+
case 1:
732+
if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
733+
RETURN_FALSE;
734+
}
735+
id = -1;
736+
break;
737+
default:
738+
WRONG_PARAM_COUNT;
739+
break;
740+
}
741+
742+
ZEND_FETCH_RESOURCE2(mysql, MYSQL *, mysql_link, id, "MySQL-Link", le_link, le_plink);
743+
744+
RETURN_STRING(mysql_get_host_info(mysql),1);
745+
}
746+
/* }}} */
747+
748+
/* {{{ proto int mysql_get_proto_info([int link_identifier])
749+
Returns the protocol version used by current connection */
750+
PHP_FUNCTION(mysql_get_proto_info)
751+
{
752+
zval **mysql_link;
753+
int id;
754+
MYSQL *mysql;
755+
MySLS_FETCH();
756+
757+
switch(ZEND_NUM_ARGS()) {
758+
case 0:
759+
id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU MySLS_CC);
760+
CHECK_LINK(id);
761+
break;
762+
case 1:
763+
if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
764+
RETURN_FALSE;
765+
}
766+
id = -1;
767+
break;
768+
default:
769+
WRONG_PARAM_COUNT;
770+
break;
771+
}
772+
773+
ZEND_FETCH_RESOURCE2(mysql, MYSQL *, mysql_link, id, "MySQL-Link", le_link, le_plink);
774+
775+
RETURN_LONG(mysql_get_proto_info(mysql));
776+
}
777+
/* }}} */
778+
779+
/* {{{ proto string mysql_get_server_info([int link_identifier])
780+
Returns a string that represents the server version number */
781+
PHP_FUNCTION(mysql_get_server_info)
782+
{
783+
zval **mysql_link;
784+
int id;
785+
MYSQL *mysql;
786+
MySLS_FETCH();
787+
788+
switch(ZEND_NUM_ARGS()) {
789+
case 0:
790+
id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU MySLS_CC);
791+
CHECK_LINK(id);
792+
break;
793+
case 1:
794+
if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
795+
RETURN_FALSE;
796+
}
797+
id = -1;
798+
break;
799+
default:
800+
WRONG_PARAM_COUNT;
801+
break;
802+
}
803+
804+
ZEND_FETCH_RESOURCE2(mysql, MYSQL *, mysql_link, id, "MySQL-Link", le_link, le_plink);
805+
806+
RETURN_STRING(mysql_get_server_info(mysql),1);
807+
}
808+
/* }}} */
809+
810+
#endif
692811

693812
/* {{{ proto int mysql_create_db(string database_name [, int link_identifier])
694813
Create a MySQL database */

ext/mysql/php_mysql.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ PHP_FUNCTION(mysql_field_len);
7676
PHP_FUNCTION(mysql_field_type);
7777
PHP_FUNCTION(mysql_field_flags);
7878
PHP_FUNCTION(mysql_escape_string);
79+
PHP_FUNCTION(mysql_get_client_info);
80+
PHP_FUNCTION(mysql_get_host_info);
81+
PHP_FUNCTION(mysql_get_proto_info);
82+
PHP_FUNCTION(mysql_get_server_info);
7983

8084
ZEND_BEGIN_MODULE_GLOBALS(mysql)
8185
long default_link;

0 commit comments

Comments
 (0)