Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

PHP mysqlnd svn commit: r529 - in trunk/php6/ext: . mysql

From: <ahristov(at)mysql.com>
Date: Wed Jun 27 2007 - 10:03:24 EDT


Author: ahristov
Date: 2007-06-27 16:03:24 +0200 (Wed, 27 Jun 2007) New Revision: 529

Added:

   trunk/php6/ext/mysql/
   trunk/php6/ext/mysql/CREDITS
   trunk/php6/ext/mysql/INSTALL
   trunk/php6/ext/mysql/README
   trunk/php6/ext/mysql/config.m4
   trunk/php6/ext/mysql/config.w32
   trunk/php6/ext/mysql/mysql.mak
   trunk/php6/ext/mysql/mysql_mysqlnd.h
   trunk/php6/ext/mysql/package.xml
   trunk/php6/ext/mysql/php_mysql.c
   trunk/php6/ext/mysql/php_mysql.h

Log:
ext/mysql from PHP6 CVS patched for mysqlnd.

Now we have mysqlnd patched ext/mysql for both PHP5 and PHP6

Added: trunk/php6/ext/mysql/CREDITS


  • trunk/php6/ext/mysql/CREDITS 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/CREDITS 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,2 @@
    +MySQL
    +Zeev Suraski, Zak Greant, Georg Richter

Added: trunk/php6/ext/mysql/INSTALL


  • trunk/php6/ext/mysql/INSTALL 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/INSTALL 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,50 @@
    +REQUIREMENTS
    +
    +The new MySQL native driver for PHP (mysqlnd) requires:
    +
    + - PHP 6
    + - MySQL 4.1 or newer
    +
    +
    +BUILDING ON UNIX
    +
    +1) Get a copy of PHP 6
    +
    +For example, you can check out PHP 6, the current development
    +version of PHP, from the CVS repository on php.net.
    +See http://www.php.net/anoncvs.php for detailed instructions.
    +
    +me@myhost:~> cvs -d :pserver:cvsread@cvs.php.net:/repository checkout php6
    +
    +2) Copy mysqlnd into the PHP 6 source tree
    +
    +Remove the ext/mysqli directory from your PHP directory,
    +for example:
    +
    +me@myhost:~> cd php6
    +me@myhost:~/php6> rm -rf ext/mysql
    +
    +Copy mysqlnd into your PHP directory, for
    +example:
    +
    +me@myhost:~/php6> cp -R ~/php-mysqlnd/php6/ext/mysql ext/mysql
    +
    +3) Run buildconf
    +
    +me@myhost:~/php6> ./buildconf --force
    +
    +4) Configure PHP with mysqlnd support
    +
    +To configure PHP with ext/mysql using mysqlnd, you
    +add ext/mysql to your PHP using '--with-mysql' and tell
    +it not to link against the MySQL client library, but to
    +use mysqlnd by adding '--enable-mysqlnd'.
    +
    +me@myhost:~/php6> ./configure --with-mysql --enable-mysqlnd
    +
    +Note that you must not specify the path to the MySQL
    +utility mysql_config.
    +
    +5) Build PHP
    +
    +me@myhost:~/php6> make clean; make; make install

Added: trunk/php6/ext/mysql/README


  • trunk/php6/ext/mysql/README 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/README 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,10 @@
    +This is an experimental (alpha) port of the MySQL native driver
    +for PHP 6 and the ext/mysql PHP extension.
    +
    +It requires PHP 6 to be build and can be used
    +to connect to the MySQL Server 4.1 and newer.
    +
    +See INSTALL for installation instructions.
    +
    +The software is distributed under the terms of the
    +PHP License, see also LICENSE.
    \ No newline at end of file

Added: trunk/php6/ext/mysql/config.m4


  • trunk/php6/ext/mysql/config.m4 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/config.m4 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,164 @@
    +dnl
    +dnl $Id: config.m4,v 1.67.2.1.2.1 2006/06/01 19:14:48 mike Exp $
    +dnl
    +
    +AC_DEFUN([MYSQL_LIB_CHK], [
    + str="$MYSQL_DIR/$1/lib$MYSQL_LIBNAME.*"
    + for j in `echo $str`; do
    + if test -r $j; then
    + MYSQL_LIB_DIR=$MYSQL_DIR/$1
    + break 2
    + fi
    + done
    +])
    +
    +AC_DEFUN([PHP_MYSQL_SOCKET_SEARCH], [
    + for i in \
    + /var/run/mysqld/mysqld.sock \
    + /var/tmp/mysql.sock \
    + /var/run/mysql/mysql.sock \
    + /var/lib/mysql/mysql.sock \
    + /var/mysql/mysql.sock \
    + /usr/local/mysql/var/mysql.sock \
    + /Private/tmp/mysql.sock \
    + /private/tmp/mysql.sock \
    + /tmp/mysql.sock \
    + ; do
    + if test -r $i; then
    + MYSQL_SOCK=$i
    + break 2
    + fi
    + done
    +
    + if test -n "$MYSQL_SOCK"; then
    + AC_DEFINE_UNQUOTED(MYSQL_UNIX_ADDR, "$MYSQL_SOCK", [ ])
    + AC_MSG_RESULT([$MYSQL_SOCK])
    + else
    + AC_MSG_RESULT([no])
    + fi
    +])
    +
    +
    +PHP_ARG_WITH(mysql, for MySQL support,
    +[ --with-mysql[=DIR] Include MySQL support. DIR is the MySQL base directory.
    + If mysqlnd is passed as DIR, the MySQL native driver will be used])
    +
    +PHP_ARG_WITH(mysql-sock, for specified location of the MySQL UNIX socket,
    +[ --with-mysql-sock[=DIR] MySQL: Location of the MySQL unix socket pointer.
    + If unspecified, the default locations are searched], no, no)
    +
    +if test -z "$PHP_ZLIB_DIR"; then
    + PHP_ARG_WITH(zlib-dir, for the location of libz,
    + [ --with-zlib-dir[=DIR] MySQL: Set the path to libz install prefix], no, no)
    +fi
    +
    +if test "$PHP_MYSQL" = "mysqlnd"; then
    + dnl enables build of mysqnd library
    + PHP_MYSQLND_ENABLED=yes
    +
    +elif test "$PHP_MYSQL" != "no"; then
    +
    + AC_MSG_CHECKING([for MySQL UNIX socket location])
    + if test "$PHP_MYSQL_SOCK" != "no" && test "$PHP_MYSQL_SOCK" != "yes"; then
    + MYSQL_SOCK=$PHP_MYSQL_SOCK
    + AC_DEFINE_UNQUOTED(MYSQL_UNIX_ADDR, "$MYSQL_SOCK", [ ])
    + AC_MSG_RESULT([$MYSQL_SOCK])
    + elif test "$PHP_MYSQL" = "yes" || test "$PHP_MYSQL_SOCK" = "yes"; then
    + PHP_MYSQL_SOCKET_SEARCH
    + else
    + AC_MSG_RESULT([no])
    + fi
    +
    + MYSQL_DIR=
    + MYSQL_INC_DIR=
    +
    + for i in $PHP_MYSQL /usr/local /usr; do
    + if test -r $i/include/mysql/mysql.h; then
    + MYSQL_DIR=$i
    + MYSQL_INC_DIR=$i/include/mysql
    + break
    + elif test -r $i/include/mysql.h; then
    + MYSQL_DIR=$i
    + MYSQL_INC_DIR=$i/include
    + break
    + fi
    + done
    +
    + if test -z "$MYSQL_DIR"; then
    + AC_MSG_ERROR([Cannot find MySQL header files under $PHP_MYSQL.
    +Note that the MySQL client library is not bundled anymore!])
    + fi
    +
    + if test "$enable_maintainer_zts" = "yes"; then
    + MYSQL_LIBNAME=mysqlclient_r
    + else
    + MYSQL_LIBNAME=mysqlclient
    + fi
    + case $host_alias in
    + *netware*[)]
    + MYSQL_LIBNAME=mysql
    + ;;
    + esac
    +
    + dnl for compat with PHP 4 build system
    + if test -z "$PHP_LIBDIR"; then
    + PHP_LIBDIR=lib
    + fi
    +
    + for i in $PHP_LIBDIR $PHP_LIBDIR/mysql; do
    + MYSQL_LIB_CHK($i)
    + done
    +
    + if test -z "$MYSQL_LIB_DIR"; then
    + AC_MSG_ERROR([Cannot find lib$MYSQL_LIBNAME under $MYSQL_DIR.
    +Note that the MySQL client library is not bundled anymore!])
    + fi
    +
    + PHP_CHECK_LIBRARY($MYSQL_LIBNAME, mysql_close, [ ],
    + [
    + if test "$PHP_ZLIB_DIR" != "no"; then
    + PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR, MYSQL_SHARED_LIBADD)
    + PHP_CHECK_LIBRARY($MYSQL_LIBNAME, mysql_error, [], [
    + AC_MSG_ERROR([mysql configure failed. Please check config.log for more information.])
    + ], [
    + -L$PHP_ZLIB_DIR/$PHP_LIBDIR -L$MYSQL_LIB_DIR
    + ])
    + MYSQL_LIBS="-L$PHP_ZLIB_DIR/$PHP_LIBDIR -lz"
    + else
    + PHP_ADD_LIBRARY(z,, MYSQL_SHARED_LIBADD)
    + PHP_CHECK_LIBRARY($MYSQL_LIBNAME, mysql_errno, [], [
    + AC_MSG_ERROR([Try adding --with-zlib-dir=<DIR>. Please check config.log for more information.])
    + ], [
    + -L$MYSQL_LIB_DIR
    + ])
    + MYSQL_LIBS="-lz"
    + fi
    + ], [
    + -L$MYSQL_LIB_DIR
    + ])
    +
    + PHP_ADD_LIBRARY_WITH_PATH($MYSQL_LIBNAME, $MYSQL_LIB_DIR, MYSQL_SHARED_LIBADD)
    + PHP_ADD_INCLUDE($MYSQL_INC_DIR)
    +
    +
    + MYSQL_MODULE_TYPE=external
    + MYSQL_LIBS="-L$MYSQL_LIB_DIR -l$MYSQL_LIBNAME $MYSQL_LIBS"
    + MYSQL_INCLUDE=-I$MYSQL_INC_DIR
    +
    + PHP_SUBST_OLD(MYSQL_MODULE_TYPE)
    + PHP_SUBST_OLD(MYSQL_LIBS)
    + PHP_SUBST_OLD(MYSQL_INCLUDE)
    +fi
    +
    +dnl Enable extension
    +if test "$PHP_MYSQL" != "no"; then
    + AC_DEFINE(HAVE_MYSQL, 1, [Whether you have MySQL])
    + PHP_NEW_EXTENSION(mysql, php_mysql.c, $ext_shared)
    + PHP_SUBST(MYSQL_SHARED_LIBADD)
    +
    + dnl These 3 lines are neeeded to be able to build ext/mysql and/or ext/mysqli with/without mysqlnd.
    + dnl Need to do this here for the file to be always available.
    + $php_shtool mkdir -p ext/mysql/
    + echo > ext/mysql/php_have_mysqlnd.h
    + test "$PHP_MYSQL" = "mysqlnd" && PHP_DEFINE(HAVE_MYSQLND, 1, [ext/mysql])
    +fi

Added: trunk/php6/ext/mysql/config.w32


  • trunk/php6/ext/mysql/config.w32 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/config.w32 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,15 @@
    +// $Id: config.w32,v 1.2 2005/06/05 19:25:00 wez Exp $
    +// vim:ft=javascript
    +
    +ARG_WITH("mysql", "MySQL support", "no");
    +
    +if (PHP_MYSQL != "no") {
    + if (CHECK_LIB("libmysql.lib", "mysql", PHP_MYSQL) &&
    + CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQL",
    + PHP_MYSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\mysql;" + PHP_MYSQL)) {
    + EXTENSION("mysql", "php_mysql.c");
    + AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
    + } else {
    + WARNING("mysql not enabled; libraries and headers not found");
    + }
    +}
Do you need help?X

Added: trunk/php6/ext/mysql/mysql.mak


  • trunk/php6/ext/mysql/mysql.mak 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/mysql.mak 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,169 @@
    +# Temporarily here -- later may go into some batch file
    +# which will set this as an environment variable
    +PROJECT_ROOT = ..\..
    +
    +# Module details
    +MODULE_NAME = phpmysql
    +MODULE_DESC = "PHP 4.3 - MySQL Extension"
    +VMAJ = 3
    +VMIN = 0
    +VREV = 0
    +
    +#include the common settings
    +include $(PROJECT_ROOT)/netware/common.mif
    +
    +# MYSQL stuff
    +MYSQL_DIR = P:/APPS/script/sw/mysql
    +
    +# Build type defaults to 'release'
    +ifndef BUILD
    +BUILD = release
    +endif
    +
    +# Extensions of all input and output files
    +.SUFFIXES:
    +.SUFFIXES: .nlm .lib .obj .cpp .c .msg .mlc .mdb .xdc .d
    +
    +# Source files
    +C_SRC = php_mysql.c \
    + start.c
    +
    +CPP_SRC_NODIR = $(notdir $(CPP_SRC))
    +C_SRC_NODIR = $(notdir $(C_SRC))
    +SRC_DIR = $(dir $(CPP_SRC) $(C_SRC))
    +
    +# Library files
    +LIBRARY = $(MYSQL_DIR)/lib/libmysqlclient.lib
    +
    +# Destination directories and files
    +OBJ_DIR = $(BUILD)
    +FINAL_DIR = $(BUILD)
    +OBJECTS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.obj) $(C_SRC_NODIR:.c=.obj))
    +DEPDS = $(addprefix $(OBJ_DIR)/,$(CPP_SRC_NODIR:.c=.d) $(C_SRC_NODIR:.c=.d))
    +
    +# Binary file
    +ifndef BINARY
    + BINARY=$(FINAL_DIR)\$(MODULE_NAME).nlm
    +endif
    +
    +# Compile flags
    +C_FLAGS = -c -maxerrors 25 -msgstyle gcc -wchar_t on -bool on -processor Pentium
    +C_FLAGS += -nostdinc -nosyspath
    +C_FLAGS += -relax_pointers # To remove type-casting errors
    +C_FLAGS += -DNETWARE -DZTS -DNEW_LIBC -DUSE_OLD_FUNCTIONS -DCOMPILE_DL_MYSQL=1
    +C_FLAGS += -I. -I- -I$(PROJECT_ROOT) -I$(PROJECT_ROOT)/main
    +C_FLAGS += -I$(PROJECT_ROOT)/ext/standard -I$(PROJECT_ROOT)/netware
    +C_FLAGS += -I$(PROJECT_ROOT)/zend -I$(PROJECT_ROOT)/tsrm
    +C_FLAGS += -I$(SDK_DIR)/include -I$(MWCIncludes)
    +C_FLAGS += -I$(MYSQL_DIR)/include
    +C_FLAGS += -I$(WINSOCK_DIR)/include/nlm -I$(WINSOCK_DIR)/include
    +
    +
    +# Extra stuff based on debug / release builds
    +ifeq '$(BUILD)' 'debug'
    + SYM_FILE = $(FINAL_DIR)\$(MODULE_NAME).sym
    + C_FLAGS += -inline smart -sym on -sym codeview4 -opt off -opt intrinsics -DDEBUGGING -DDKFBPON
    + C_FLAGS += -exc cw -DZEND_DEBUG=1
    + LD_FLAGS += -sym on -sym codeview4 -osym $(SYM_FILE)
    + export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtld.lib
    +else
    + C_FLAGS += -opt speed -inline on -inline smart -inline auto -sym off -opt intrinsics
    + C_FLAGS += -opt level=4 -DZEND_DEBUG=0
    + LD_FLAGS += -sym off
    + export MWLibraryFiles=$(SDK_DIR)/imports/libcpre.o;mwcrtl.lib
    +endif
    +
    +
    +# Dependencies
    +MODULE = LibC \
    + phplib
    +IMPORT = @$(SDK_DIR)/imports/libc.imp \
    + @$(SDK_DIR)/imports/ws2nlm.imp \
    + @$(MPK_DIR)/import/mpkOrg.imp \
    + @$(PROJECT_ROOT)/netware/phplib.imp
    +EXPORT = ($(MODULE_NAME)) get_module
    +API = OutputToScreen
    +
    +# Virtual paths
    +vpath %.cpp .
    +vpath %.c . ..\..\netware
    +vpath %.obj $(OBJ_DIR)
    +
    +
    +all: prebuild project
    +
    +.PHONY: all
    +
    +prebuild:
    + @if not exist $(OBJ_DIR) md $(OBJ_DIR)
    +
    +project: $(BINARY)
    + @echo Build complete.
    +
    +$(OBJ_DIR)/%.d: %.cpp
    + @echo Building Dependencies for $(<F)
    + @$(CC) -M $< $(C_FLAGS) -o $@
    +
    +$(OBJ_DIR)/%.d: %.c
    + @echo Building Dependencies for $(<F)
    + @$(CC) -M $< $(C_FLAGS) -o $@
    +
    +$(OBJ_DIR)/%.obj: %.cpp
    + @echo Compiling $?...
    + @$(CC) $< $(C_FLAGS) -o $@
    +
    +$(OBJ_DIR)/%.obj: %.c
    + @echo Compiling $?...
    + @$(CC) $< $(C_FLAGS) -o $@
    +
    +
    +$(BINARY): $(OBJECTS)
    + @echo Import $(IMPORT) > $(basename $@).def
    +ifdef API
    + @echo Import $(API) >> $(basename $@).def
    +endif
    + @echo Module $(MODULE) >> $(basename $@).def
    +ifdef EXPORT
    + @echo Export $(EXPORT) >> $(basename $@).def
    +endif
    + @echo AutoUnload >> $(basename $@).def
    +ifeq '$(BUILD)' 'debug'
    + @echo Debug >> $(basename $@).def
    +endif
    + @echo Flag_On 0x00000008 >> $(basename $@).def
    + @echo Start _LibCPrelude >> $(basename $@).def
    + @echo Exit _LibCPostlude >> $(basename $@).def
    +
    + $(MPKTOOL) $(XDCFLAGS) $(basename $@).xdc
    + @echo xdcdata $(basename $@).xdc >> $(basename $@).def
    +
    + @echo Linking $@...
    + @echo $(LD_FLAGS) -commandfile $(basename $@).def > $(basename $@).link
    + @echo $(LIBRARY) $(OBJECTS) >> $(basename $@).link
    + @$(LINK) @$(basename $@).link
    +
    +
    +.PHONY: clean
    +clean: cleanobj cleanbin
    +
    +.PHONY: cleand
    +cleand:
    + @echo Deleting all dependency files...
    + -@del "$(OBJ_DIR)\*.d"
    +
    +.PHONY: cleanobj
    +cleanobj:
    + @echo Deleting all object files...
    + -@del "$(OBJ_DIR)\*.obj"
    +
    +.PHONY: cleanbin
    +cleanbin:
    + @echo Deleting binary files...
    + -@del "$(FINAL_DIR)\$(MODULE_NAME).nlm"
    + @echo Deleting MAP, DEF files, etc....
    + -@del "$(FINAL_DIR)\$(MODULE_NAME).map"
    + -@del "$(FINAL_DIR)\$(MODULE_NAME).def"
    + -@del "$(FINAL_DIR)\$(MODULE_NAME).link"
    +ifeq '$(BUILD)' 'debug'
    + -@del $(FINAL_DIR)\$(MODULE_NAME).sym
    +endif

Added: trunk/php6/ext/mysql/mysql_mysqlnd.h


  • trunk/php6/ext/mysql/mysql_mysqlnd.h 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/mysql_mysqlnd.h 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,128 @@
    +/*
    + +----------------------------------------------------------------------+
    + | PHP Version 6 |
    + +----------------------------------------------------------------------+
    + | Copyright (c) 2006-2007 The PHP Group |
    + +----------------------------------------------------------------------+
    + | 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. |
    + +----------------------------------------------------------------------+
    + | Authors: Georg Richter <georg@mysql.com> |
    + | Andrey Hristov <andrey@mysql.com> |
    + | Ulf Wendel <uwendel@mysql.com> |
    + +----------------------------------------------------------------------+
    +
    +*/
    +
    +#ifndef MYSQL_MYSQLND_H
    +#define MYSQL_MYSQLND_H
    +
    +/* Global types and definitions*/
    +#define MYSQL_NO_DATA MYSQLND_NO_DATA
    +#define MYSQL_DATA_TRUNCATED MYSQLND_DATA_TRUNCATED
    +#define MYSQL_STMT MYSQLND_STMT
    +#define MYSQL_FIELD MYSQLND_FIELD
    +#define MYSQL_RES MYSQLND_RES
    +#define MYSQL_ROW MYSQLND_ROW
    +#define MYSQL MYSQLND
    +#define my_bool zend_bool
    +#define my_ulonglong mynd_ulonglong
    +
    +#define MYSQL_VERSION_ID MYSQLND_VERSION_ID
    +#define MYSQL_SERVER_VERSION MYSQLND_VERSION
    +#define MYSQL_ERRMSG_SIZE MYSQLND_ERRMSG_SIZE
    +#define SQLSTATE_LENGTH MYSQLND_SQLSTATE_LENGTH
    +
    +#define SERVER_QUERY_NO_GOOD_INDEX_USED MYSQLND_SERVER_QUERY_NO_GOOD_INDEX_USED
    +#define SERVER_QUERY_NO_INDEX_USED MYSQLND_SERVER_QUERY_NO_INDEX_USED
    +
    +
    +/* functions */
    +#define mysql_affected_rows(r) mysqlnd_affected_rows((r))
    +#define mysql_autocommit(r,m) mysqlnd_autocommit((r),(m))
    +#define mysql_change_user(r,a,b,c) mysqlnd_change_user((r), (a), (b), (c))
    +#define mysql_character_set_name(c) mysqlnd_character_set_name((c))
    +#define mysql_close(r) mysqlnd_close((r), MYSQLND_CLOSE_EXPLICIT)
    +#define mysql_commit(r) mysqlnd_commit((r))
    +#define mysql_data_seek(r,o) mysqlnd_data_seek((r),(o))
    +#define mysql_dump_debug_info(r) mysqlnd_dump_debug_info((r))
    +#define mysql_errno(r) mysqlnd_errno((r))
    +#define mysql_error(r) mysqlnd_error((r))
    +#define mysql_fetch_field(r) mysqlnd_fetch_field((r))
    +#define mysql_fetch_field_direct(r,o) mysqlnd_fetch_field_direct((r), (o))
    +#define mysql_fetch_lengths(r) mysqlnd_fetch_lengths((r))
    +#define mysql_fetch_row(r) mysqlnd_fetch_row((r))
    +#define mysql_field_count(r) mysqlnd_field_count((r))
    +#define mysql_field_seek(r,o) mysqlnd_field_seek((r), (o))
    +#define mysql_field_tell(r) mysqlnd_field_tell((r))
    +#define mysql_init(a) mysqlnd_init((a))
    +#define mysql_insert_id(r) mysqlnd_insert_id((r))
    +#define mysql_kill(r,n) mysqlnd_kill((r), (n))
    +#define mysql_more_results(r) mysqlnd_more_results((r))
    +#define mysql_next_result(r) mysqlnd_next_result((r))
    +#define mysql_num_fields(r) mysqlnd_num_fields((r))
    +#define mysql_num_rows(r) mysqlnd_num_rows((r))
    +#define mysql_ping(r) mysqlnd_ping((r))
    +#define mysql_real_escape_string(r,a,b,c) mysqlnd_real_escape_string((r), (a), (b), (c))
    +#define mysql_real_query(r,a,b) mysqlnd_query((r), (a), (b))
    +#define mysql_rollback(r) mysqlnd_rollback((r))
    +#define mysql_select_db(r,a) mysqlnd_select_db((r), (a) ,strlen((a)))
    +#define mysql_set_server_option(r,o) mysqlnd_set_server_option((r), (o))
    +#define mysql_set_character_set(r,a) mysqlnd_set_charset((r), (a))
    +#define mysql_sqlstate(r) mysqlnd_sqlstate((r))
    +#define mysql_stmt_affected_rows(s) mysqlnd_stmt_affected_rows((s))
    +#define mysql_stmt_field_count(s) mysqlnd_stmt_field_count((s))
    +#define mysql_stmt_param_count(s) mysqlnd_stmt_param_count((s))
    +#define mysql_stmt_num_rows(s) mysqlnd_stmt_num_rows((s))
    +#define mysql_stmt_insert_id(s) mysqlnd_stmt_insert_id((s))
    +#define mysql_stmt_close(s) mysqlnd_stmt_close((s))
    +#define mysql_stmt_errno(s) mysqlnd_stmt_errno((s))
    +#define mysql_stmt_error(s) mysqlnd_stmt_error((s))
    +#define mysql_stmt_sqlstate(s) mysqlnd_stmt_sqlstate((s))
    +#define mysql_stmt_prepare(s,q,l) mysqlnd_stmt_prepare((s), (q), (l))
    +#define mysql_stmt_execute(s) mysqlnd_stmt_execute((s))
    +#define mysql_stmt_reset(s) mysqlnd_stmt_reset((s))
    +#define mysql_stmt_store_result(s) mysqlnd_stmt_store_result((s))
    +#define mysql_stmt_free_result(s) mysqlnd_stmt_free_result((s))
    +#define mysql_stmt_data_seek(s,r) mysqlnd_stmt_data_seek((s), (r))
    +#define mysql_stmt_send_long_data(s,p,d,l) mysqlnd_stmt_send_long_data((s), (p), (d), (l))
    +#define mysql_stmt_attr_get(s,a,v) mysqlnd_stmt_attr_get((s), (a), (v))
    +#define mysql_stmt_attr_set(s,a,v) mysqlnd_stmt_attr_set((s), (a), (v))
    +#define mysql_stmt_param_metadata(s) mysqlnd_stmt_param_metadata((s))
    +#define mysql_stmt_result_metadata(s) mysqlnd_stmt_result_metadata((s))
    +#define mysql_thread_safe() mysqlnd_thread_safe()
    +#define mysql_info(r) mysqlnd_info((r))
    +#define mysql_options(r,a,b) mysqlnd_options((r), (a), (b))
    +#define mysql_stmt_init(r) mysqlnd_stmt_init((r))
    +#define mysql_free_result(r) mysqlnd_free_result((r), FALSE)
    +#define mysql_store_result(r) mysqlnd_store_result((r))
    +#define mysql_use_result(r) mysqlnd_use_result((r))
    +#define mysql_thread_id(r) mysqlnd_thread_id((r))
    +#define mysql_get_client_info() mysqlnd_get_client_info()
    +#define mysql_get_client_version() mysqlnd_get_client_version()
    +#define mysql_get_host_info(r) mysqlnd_get_host_info((r))
    +#define mysql_get_proto_info(r) mysqlnd_get_proto_info((r))
    +#define mysql_get_server_info(r) mysqlnd_get_server_info((r))
    +#define mysql_get_server_version(r) mysqlnd_get_server_version((r))
    +#define mysql_warning_count(r) mysqlnd_warning_count((r))
    +
    +/* Here comes non-libmysql API to have less ifdefs in mysqli*/
    +#define MYSQLI_CLOSE_EXPLICIT MYSQLND_CLOSE_EXPLICIT
    +#define MYSQLI_CLOSE_IMPLICIT MYSQLND_CLOSE_IMPLICIT
    +#define MYSQLI_CLOSE_DISCONNECTED MYSQLND_CLOSE_DISCONNECTED
    +
    +#define mysqli_result_is_unbuffered(r) ((r)->conn)
    +#define mysqli_server_status(c) (c)->upsert_status.server_status
    +#define mysqli_stmt_warning_count(s) mysqlnd_stmt_warning_count((s))
    +#define mysqli_stmt_server_status(s) (s)->upsert_status.server_status
    +#define mysqli_stmt_get_connection(s) (s)->conn
    +#define mysqli_close(c, how) mysqlnd_close((c), (how))
    +#define mysqli_stmt_close(c, implicit) mysqlnd_stmt_close((c), (implicit))
    +#define mysqli_free_result(r, implicit) mysqlnd_free_result((r), (implicit))
    +
    +#endif

Added: trunk/php6/ext/mysql/package.xml


  • trunk/php6/ext/mysql/package.xml 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/package.xml 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,64 @@
    +<?xml version="1.0" encoding="ISO-8859-1" ?>
    +<!DOCTYPE package SYSTEM "../pear/package.dtd">
    +<package>
    + <name>mysqli</name>
    + <summary>MySQL database access functions</summary>
    + <maintainers>
    + <maintainer>
    + <user>georg</user>
    + <name>Georg Richter</name>
    + <email>georg@php.net</email>
    + <role>lead</role>
    + </maintainer>
    + <maintainer>
    + <user>zak</user>
    + <name>Zak Greant</name>
    + <email>zak@php.net</email>
    + <role>developer</role>
    + </maintainer>
    + <maintainer>
    + <user>zeev</user>
    + <name>Zeev Suraski</name>
    + <email>zeev@php.net</email>
    + <role>developer</role>
    + </maintainer>
    + </maintainers>
    + <description>
    +These functions allow you to access MySQL database servers.
    + </description>
    + <license>PHP</license>
    + <release>
    + <state>beta</state>
    + <version>5.0.0rc1</version>
    + <date>2004-03-19</date>
    + <notes>
    +package.xml added to support installation using pear installer
    + </notes>
    + <configureoptions>
    + <configureoption name="with-mysql" default="autodetect" prompt="mysql installation dir?"/>
    + <configureoption name="with-mysql-sock" default="autodetect" prompt="MySQL Unix socket?"/>
    + <configureoption name="with-zlib-dir" default="autodetect" prompt="zlib installation dir?"/>
    + </configureoptions>
    + <filelist>
    + <file role="src" name="config.m4"/>
    + <file role="src" name="config.w32"/>
    + <file role="doc" name="CREDITS"/>
    + <file role="src" name="mysql.dsp"/>
    + <file role="src" name="mysql.mak"/>
    + <file role="src" name="php_mysql.c"/>
    + <file role="src" name="php_mysql.h"/>
    + <file role="src" name="mysql_mysqlnd.h"/>
    + <file role="test" name="tests/001.phpt"/>
    + <file role="test" name="tests/002.phpt"/>
    + <file role="test" name="tests/003.phpt"/>
    + <file role="test" name="tests/connect.inc"/>
    + <file role="test" name="tests/skipif.inc"/>
    + </filelist>
    + <deps>
    + <dep type="php" rel="ge" version="5" />
    + </deps>
    + </release>
    +</package>
    +<!--
    +vim:et:ts=1:sw=1
    +-->

Added: trunk/php6/ext/mysql/php_mysql.c


  • trunk/php6/ext/mysql/php_mysql.c 2007-06-27 13:40:15 UTC (rev 528)
    +++ trunk/php6/ext/mysql/php_mysql.c 2007-06-27 14:03:24 UTC (rev 529)
    @@ -0,0 +1,2591 @@
    +/*
    + +----------------------------------------------------------------------+
    + | PHP Version 5 |
    + +----------------------------------------------------------------------+
    + | Copyright (c) 1997-2007 The PHP Group |
    + +----------------------------------------------------------------------+
    + | 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. |
    + +----------------------------------------------------------------------+
    + | Authors: Zeev Suraski <zeev@zend.com> |
    + | Zak Greant <zak@mysql.com> |
    + | Georg Richter <georg@php.net> |
    + +----------------------------------------------------------------------+
    +*/
    +
    +/* $Id: php_mysql.c,v 1.238 2007/06/25 20:19:30 scottmac Exp $ */
    +
    +/* TODO:
    + *
    + * ? Safe mode implementation
    + */
    +
    +#ifdef HAVE_CONFIG_H
    +# include "config.h"
    +#endif
    +
    +#include "php.h"
    +#include "php_globals.h"
    +#include "ext/standard/info.h"
    +#include "ext/standard/php_string.h"
    +#include "ext/standard/basic_functions.h"
    +#include "zend_exceptions.h"
    +
    +#if HAVE_MYSQL
    +
    +#ifdef PHP_WIN32
    +# include <winsock2.h>
    +# define signal(a, b) NULL
    +#elif defined(NETWARE)
    +# include <sys/socket.h>
    +# define signal(a, b) NULL
    +#else
    +# if HAVE_SIGNAL_H
    +# include <signal.h>
    +# endif
    +# if HAVE_SYS_TYPES_H
    +# include <sys/types.h>
    +# endif
    +# include <netdb.h>
    +# include <netinet/in.h>
    +# if HAVE_ARPA_INET_H
    +# include <arpa/inet.h>
    +# endif
    +#endif
    +
    +#include "php_ini.h"
    +#include "php_mysql.h"
    +
    +/* True globals, no need for thread safety */
    +static int le_result, le_link, le_plink;
    +
    +#ifdef HAVE_MYSQL_REAL_CONNECT
    +# ifdef HAVE_ERRMSG_H
    +# include <errmsg.h>
    +# endif
    +#endif
    +
    +#define SAFE_STRING(s) ((s)?(s):"")
    +
    +#if MYSQL_VERSION_ID > 32199
    +# define mysql_row_length_type unsigned long
    +# define HAVE_MYSQL_ERRNO
    +#else
    +# define mysql_row_length_type unsigned int
    +# ifdef mysql_errno
    +# define HAVE_MYSQL_ERRNO
    +# endif
    +#endif
    +
    +#if MYSQL_VERSION_ID >= 32032
    +#define HAVE_GETINFO_FUNCS
    +#endif
    +
    +#if MYSQL_VERSION_ID > 32133 || defined(FIELD_TYPE_TINY)
    +#define MYSQL_HAS_TINY
    +#endif
    +
    +#if MYSQL_VERSION_ID >= 32200
    +#define MYSQL_HAS_YEAR
    +#endif
    +
    +#define MYSQL_ASSOC 1<<0
    +#define MYSQL_NUM 1<<1
    +#define MYSQL_BOTH (MYSQL_ASSOC|MYSQL_NUM)
    +
    +#define MYSQL_USE_RESULT 0
    +#define MYSQL_STORE_RESULT 1
    +
    +#if MYSQL_VERSION_ID < 32224
    +#define PHP_MYSQL_VALID_RESULT(mysql) \
    + (mysql_num_fields(mysql)>0)
    +#else
    +#define PHP_MYSQL_VALID_RESULT(mysql) \
    + (mysql_field_count(mysql)>0)
    +#endif
    +
    +ZEND_DECLARE_MODULE_GLOBALS(mysql)
    +static PHP_GINIT_FUNCTION(mysql);
    +
    +typedef struct _php_mysql_conn {
    + MYSQL *conn;
    + int active_result_id;
    +} php_mysql_conn;
    +
    +#ifdef HAVE_MYSQLND
    +static MYSQLND_ZVAL_PCACHE *mysql_mysqlnd_zval_cache;
    +static MYSQLND_QCACHE *mysql_mysqlnd_qcache;
    +#endif
    +
    +/* {{{ mysql_functions[]
    + */
    +zend_function_entry mysql_functions[] = {
    + PHP_FE(mysql_connect, NULL)
    + PHP_FE(mysql_pconnect, NULL)
    + PHP_FE(mysql_close, NULL)
    + PHP_FE(mysql_select_db, NULL)
    +#ifndef NETWARE /* The below two functions not supported on NetWare */
    +#if MYSQL_VERSION_ID < 40000
    + PHP_DEP_FE(mysql_create_db, NULL)
    + PHP_DEP_FE(mysql_drop_db, NULL)
    +#endif
    +#endif /* NETWARE */
    + PHP_FE(mysql_query, NULL)
    + PHP_FE(mysql_unbuffered_query, NULL)
    + PHP_FE(mysql_db_query, NULL)
    +#ifndef HAVE_MYSQLND
    + PHP_FE(mysql_list_dbs, NULL)
    + PHP_DEP_FE(mysql_list_tables, NULL)
    + PHP_FE(mysql_list_fields, NULL)
    + PHP_FE(mysql_list_processes, NULL)
    +#endif
    + PHP_FE(mysql_error, NULL)
    +#ifdef HAVE_MYSQL_ERRNO
    + PHP_FE(mysql_errno, NULL)
    +#endif
    + PHP_FE(mysql_affected_rows, NULL)
    + PHP_FE(mysql_insert_id, NULL)
    +#ifndef HAVE_MYSQLND
    + PHP_FE(mysql_result, NULL)
    +#endif
    + PHP_FE(mysql_num_rows, NULL)
    + PHP_FE(mysql_num_fields, NULL)
    + PHP_FE(mysql_fetch_row, NULL)
    + PHP_FE(mysql_fetch_array, NULL)
    + PHP_FE(mysql_fetch_assoc, NULL)
    + PHP_FE(mysql_fetch_object, NULL)
    + PHP_FE(mysql_data_seek, NULL)
    + PHP_FE(mysql_fetch_lengths, NULL)
    + PHP_FE(mysql_fetch_field, NULL)
    + PHP_FE(mysql_field_seek, NULL)
    + PHP_FE(mysql_free_result, NULL)
    + PHP_FE(mysql_field_name, NULL)
    + PHP_FE(mysql_field_table, NULL)
    + PHP_FE(mysql_field_len, NULL)
    + PHP_FE(mysql_field_type, NULL)
    + PHP_FE(mysql_field_flags, NULL)
    +#ifndef HAVE_MYSQLND
    + PHP_FE(mysql_escape_string, NULL)
    +#endif
    + PHP_FE(mysql_real_escape_string, NULL)
    + PHP_FE(mysql_stat, NULL)
    + PHP_FE(mysql_thread_id, NULL)
    + PHP_FE(mysql_client_encoding, NULL)
    + PHP_FE(mysql_ping, NULL)
    +#ifdef HAVE_GETINFO_FUNCS
    + PHP_FE(mysql_get_client_info, NULL)
    + PHP_FE(mysql_get_host_info, NULL)
    + PHP_FE(mysql_get_proto_info, NULL)
    + PHP_FE(mysql_get_server_info, NULL)
    +#endif
    +
    + PHP_FE(mysql_info, NULL)
    +#ifdef MYSQL_HAS_SET_CHARSET
    + PHP_FE(mysql_set_charset, NULL)
    +#endif
    + /* for downwards compatability */
    + PHP_FALIAS(mysql, mysql_db_query, NULL)
    + PHP_FALIAS(mysql_fieldname, mysql_field_name, NULL)
    + PHP_FALIAS(mysql_fieldtable, mysql_field_table, NULL)
    + PHP_FALIAS(mysql_fieldlen, mysql_field_len, NULL)
    + PHP_FALIAS(mysql_fieldtype, mysql_field_type, NULL)
    + PHP_FALIAS(mysql_fieldflags, mysql_field_flags, NULL)
    + PHP_FALIAS(mysql_selectdb, mysql_select_db, NULL)
    +#ifndef NETWARE /* The below two functions not supported on NetWare */
    +#if MYSQL_VERSION_ID < 40000
    + PHP_DEP_FALIAS(mysql_createdb, mysql_create_db, NULL)
    + PHP_DEP_FALIAS(mysql_dropdb, mysql_drop_db, NULL)
    +#endif
    +#endif /* NETWARE */
    + PHP_FALIAS(mysql_freeresult, mysql_free_result, NULL)
    + PHP_FALIAS(mysql_numfields, mysql_num_fields, NULL)
    + PHP_FALIAS(mysql_numrows, mysql_num_rows, NULL)
    +#ifndef HAVE_MYSQLND
    + PHP_FALIAS(mysql_listdbs, mysql_list_dbs, NULL)
    + PHP_DEP_FALIAS(mysql_listtables,mysql_list_tables, NULL)
    + PHP_FALIAS(mysql_listfields, mysql_list_fields, NULL)
    + PHP_FALIAS(mysql_db_name, mysql_result, NULL)
    + PHP_FALIAS(mysql_dbname, mysql_result, NULL)
    + PHP_FALIAS(mysql_tablename, mysql_result, NULL)
    + PHP_FALIAS(mysql_table_name, mysql_result, NULL)
    +#endif
    + {NULL, NULL, NULL}
    +};
    +/* }}} */
    +
    +/* {{{ mysql_module_entry
    + */
    +zend_module_entry mysql_module_entry = {
    + STANDARD_MODULE_HEADER,
    + "mysql",
    + mysql_functions,
    + ZEND_MODULE_STARTUP_N(mysql),
    + PHP_MSHUTDOWN(mysql),
    + PHP_RINIT(mysql),
    + PHP_RSHUTDOWN(mysql),
    + PHP_MINFO(mysql),
    + "1.0",
    + PHP_MODULE_GLOBALS(mysql),
    + PHP_GINIT(mysql),
    + NULL,
    + NULL,
    + STANDARD_MODULE_PROPERTIES_EX
    +};
    +/* }}} */
    +
    +#ifdef COMPILE_DL_MYSQL
    +ZEND_GET_MODULE(mysql)
    +#endif
    +
    +void timeout(int sig);
    +
    +#define CHECK_LINK(link) { if (link==-1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
    +
    +#if defined(HAVE_MYSQLND)
    +#define PHPMY_UNBUFFERED_QUERY_CHECK() \
    +{\
    + if (mysql->active_result_id) { \
    + do { \
    + int type; \
    + MYSQL_RES *result; \
    + \
    + result = (MYSQL_RES *) zend_list_find(mysql->active_result_id, &type); \
    + MYSQLND_RES_UNBUFFERED *unbuf = result->unbuf; \
    + if (unbuf) { \
    + if (unbuf->last_row_data) { \
    + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Function called without first fetching all rows from a previous unbuffered query"); \
    + mysql_free_result(result); \
    + } \
    + zend_list_delete(mysql->active_result_id); \
    + mysql->active_result_id = 0; \
    + } \
    + } while(0); \
    + }\
    +}
    +#else
    +#define PHPMY_UNBUFFERED_QUERY_CHECK() \
    +{ \
    + if (mysql->active_result_id) { \
    + do { \
    + int type; \
    + MYSQL_RES *mysql_result; \
    + \
    + mysql_result = (MYSQL_RES *) zend_list_find(mysql->active_result_id, &type); \
    + if (mysql_result && type==le_result) { \
    + if (!mysql_eof(mysql_result)) { \
    + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Function called without first fetching all rows from a previous unbuffered query"); \
    + while (mysql_fetch_row(mysql_result)); \
    + } \
    + zend_list_delete(mysql->active_result_id); \
    + mysql->active_result_id = 0; \
    + } \
    + } while(0); \
    + } \
    +}
    +#endif
    +
    +/* {{{ _free_mysql_result
    + * This wrapper is required since mysql_free_result() returns an integer, and
    + * thus, cannot be used directly
    + */
    +static void _free_mysql_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
    +{
    + MYSQL_RES *mysql_result = (MYSQL_RES *)rsrc->ptr;
    +
    + mysql_free_result(mysql_result);
    + MySG(result_allocated)--;
    +}
    +/* }}} */
    +
    +/* {{{ php_mysql_set_default_link
    + */
    +static void php_mysql_set_default_link(int id TSRMLS_DC)
    +{
    + if (MySG(default_link) != -1) {
    + zend_list_delete(MySG(default_link));
    + }
    + MySG(default_link) = id;
    + zend_list_addref(id);
    +}
    +/* }}} */
    +
    +/* {{{ php_mysql_select_db
    +*/
    +static int php_mysql_select_db(php_mysql_conn *mysql, char *db TSRMLS_DC)
    +{
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    +
    + if (mysql_select_db(mysql->conn, db) != 0) {
    + return 0;
    + } else {
    + return 1;
    + }
    +}
    +/* }}} */
    +
    +/* {{{ _close_mysql_link
    + */
    +static void _close_mysql_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
    +{
    + php_mysql_conn *link = (php_mysql_conn *)rsrc->ptr;
    + void (*handler) (int);
    +
    + handler = signal(SIGPIPE, SIG_IGN);
    + mysql_close(link->conn);
    + signal(SIGPIPE, handler);
    + efree(link);
    + MySG(num_links)--;
    +}
    +/* }}} */
    +
    +/* {{{ _close_mysql_plink
    + */
    +static void _close_mysql_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
    +{
    + php_mysql_conn *link = (php_mysql_conn *)rsrc->ptr;
    + void (*handler) (int);
    +
    + handler = signal(SIGPIPE, SIG_IGN);
    + mysql_close(link->conn);
    + signal(SIGPIPE, handler);
    +
    + free(link);
    + MySG(num_persistent)--;
    + MySG(num_links)--;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_INI_MH
    + */
    +static PHP_INI_MH(OnMySQLPort)
    +{
    + if (new_value != NULL) { /* default port */
    + MySG(default_port) = atoi(new_value);
    + } else {
    + MySG(default_port) = -1;
    + }
    +
    + return SUCCESS;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_INI */
    +PHP_INI_BEGIN()
    + STD_PHP_INI_BOOLEAN("mysql.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateLong, allow_persistent, zend_mysql_globals, mysql_globals)
    + STD_PHP_INI_ENTRY_EX("mysql.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_persistent, zend_mysql_globals, mysql_globals, display_link_numbers)
    + STD_PHP_INI_ENTRY_EX("mysql.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_mysql_globals, mysql_globals, display_link_numbers)
    + STD_PHP_INI_ENTRY("mysql.default_host", NULL, PHP_INI_ALL, OnUpdateString, default_host, zend_mysql_globals, mysql_globals)
    + STD_PHP_INI_ENTRY("mysql.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_mysql_globals, mysql_globals)
    + STD_PHP_INI_ENTRY("mysql.default_password", NULL, PHP_INI_ALL, OnUpdateString, default_password, zend_mysql_globals, mysql_globals)
    + PHP_INI_ENTRY("mysql.default_port", NULL, PHP_INI_ALL, OnMySQLPort)
    + STD_PHP_INI_ENTRY("mysql.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysql_globals, mysql_globals)
    + STD_PHP_INI_ENTRY("mysql.connect_timeout", "60", PHP_INI_ALL, OnUpdateLong, connect_timeout, zend_mysql_globals, mysql_globals)
    + STD_PHP_INI_BOOLEAN("mysql.trace_mode", "0", PHP_INI_ALL, OnUpdateLong, trace_mode, zend_mysql_globals, mysql_globals)
    +#ifdef HAVE_MYSQLND
    + STD_PHP_INI_ENTRY("mysql.cache_size", "2000", PHP_INI_SYSTEM, OnUpdateLong, cache_size, zend_mysql_globals, mysql_globals)
    +#endif
    +PHP_INI_END()
    +/* }}} */
    +
    +/* {{{ PHP_GINIT_FUNCTION
    + */
    +static PHP_GINIT_FUNCTION(mysql)
    +{
    + mysql_globals->num_persistent = 0;
    + mysql_globals->default_socket = NULL;
    + mysql_globals->default_host = NULL;
    + mysql_globals->default_user = NULL;
    + mysql_globals->default_password = NULL;
    + mysql_globals->connect_errno = 0;
    + mysql_globals->connect_error = NULL;
    + mysql_globals->connect_timeout = 0;
    + mysql_globals->trace_mode = 0;
    + mysql_globals->result_allocated = 0;
    +#ifdef HAVE_MYSQLND
    + mysql_globals->cache_size = 0;
    + mysql_globals->mysqlnd_thd_zval_cache = NULL;
    +#endif
    +}
    +/* }}} */
    +
    +/* {{{ PHP_MINIT_FUNCTION
    + */
    +ZEND_MODULE_STARTUP_D(mysql)
    +{
    + REGISTER_INI_ENTRIES();
    + le_result = zend_register_list_destructors_ex(_free_mysql_result, NULL, "mysql result", module_number);
    + le_link = zend_register_list_destructors_ex(_close_mysql_link, NULL, "mysql link", module_number);
    + le_plink = zend_register_list_destructors_ex(NULL, _close_mysql_plink, "mysql link persistent", module_number);
    + Z_TYPE(mysql_module_entry) = type;
    +
    + REGISTER_LONG_CONSTANT("MYSQL_ASSOC", MYSQL_ASSOC, CONST_CS | CONST_PERSISTENT);
    + REGISTER_LONG_CONSTANT("MYSQL_NUM", MYSQL_NUM, CONST_CS | CONST_PERSISTENT);
    + REGISTER_LONG_CONSTANT("MYSQL_BOTH", MYSQL_BOTH, CONST_CS | CONST_PERSISTENT);
    + REGISTER_LONG_CONSTANT("MYSQL_CLIENT_COMPRESS", CLIENT_COMPRESS, CONST_CS | CONST_PERSISTENT);
    +#if MYSQL_VERSION_ID >= 40000
    + REGISTER_LONG_CONSTANT("MYSQL_CLIENT_SSL", CLIENT_SSL, CONST_CS | CONST_PERSISTENT);
    +#endif
    + REGISTER_LONG_CONSTANT("MYSQL_CLIENT_INTERACTIVE", CLIENT_INTERACTIVE, CONST_CS | CONST_PERSISTENT);
    + REGISTER_LONG_CONSTANT("MYSQL_CLIENT_IGNORE_SPACE", CLIENT_IGNORE_SPACE, CONST_CS | CONST_PERSISTENT);
    +
    +#ifdef HAVE_MYSQLND
    + mysqlnd_library_init();
    + mysql_mysqlnd_zval_cache = mysqlnd_palloc_init_cache(MySG(cache_size));
    + mysql_mysqlnd_qcache = mysqlnd_qcache_init_cache();
    +#endif
    +
    +#ifndef HAVE_MYSQLND
    + if (mysql_server_init(0, NULL, NULL)) {
    + return FAILURE;
    + }
    +#endif
    +
    + return SUCCESS;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_MSHUTDOWN_FUNCTION
    + */
    +PHP_MSHUTDOWN_FUNCTION(mysql)
    +{
    +#ifndef HAVE_MYSQLND
    +#ifdef PHP_WIN32
    + unsigned long client_ver = mysql_get_client_version;
    + /* Can't call mysql_server_end() multiple times prior to 5.0.42 on Windows */
    + if ((client_ver > 50042 && client_ver < 50100) || client_ver > 50122) {
    + mysql_server_end();
    + }
    +#else
    + mysql_server_end();
    +#endif
    +#endif
    +
    +#ifdef HAVE_MYSQLND
    + mysqlnd_palloc_free_cache(mysql_mysqlnd_zval_cache);
    + mysqlnd_qcache_free_cache_reference(&mysql_mysqlnd_qcache);
    + mysqlnd_library_end();
    +#endif
    +
    + UNREGISTER_INI_ENTRIES();
    + return SUCCESS;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_RINIT_FUNCTION
    + */
    +PHP_RINIT_FUNCTION(mysql)
    +{
    +#if !defined(HAVE_MYSQLND) && defined(ZTS)
    + if (mysql_thread_init()) {
    + return FAILURE;
    + }
    +#endif
    + MySG(default_link)=-1;
    + MySG(num_links) = MySG(num_persistent);
    + /* Reset connect error/errno on every request */
    + MySG(connect_error) = NULL;
    + MySG(connect_errno) =0;
    + MySG(result_allocated) = 0;
    +
    +#ifdef HAVE_MYSQLND
    + MySG(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(mysql_mysqlnd_zval_cache);
    +#endif
    +
    + return SUCCESS;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_RSHUTDOWN_FUNCTION
    + */
    +PHP_RSHUTDOWN_FUNCTION(mysql)
    +{
    +#if !defined(HAVE_MYSQLND) && defined(ZTS)
    + if (mysql_thread_end()) {
    + return FAILURE;
    + }
    +#endif
    +
    + if (MySG(trace_mode)) {
    + if (MySG(result_allocated)){
    + php_error_docref("function.mysql-free-result" TSRMLS_CC, E_WARNING, "%lu result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query()", MySG(result_allocated));
    + }
    + }
    +
    + if (MySG(connect_error)!=NULL) {
    + efree(MySG(connect_error));
    + }
    +#ifdef HAVE_MYSQLND
    + mysqlnd_palloc_rshutdown(MySG(mysqlnd_thd_zval_cache));
    +#endif
    +
    + return SUCCESS;
    +}
    +/* }}} */
    +
    +/* {{{ PHP_MINFO_FUNCTION
    + */
    +PHP_MINFO_FUNCTION(mysql)
    +{
    + char buf[32];
    +
    + php_info_print_table_start();
    + php_info_print_table_header(2, "MySQL Support", "enabled");
    + snprintf(buf, sizeof(buf), "%ld", MySG(num_persistent));
    + php_info_print_table_row(2, "Active Persistent Links", buf);
    + snprintf(buf, sizeof(buf), "%ld", MySG(num_links));
    + php_info_print_table_row(2, "Active Links", buf);
    + php_info_print_table_row(2, "Client API version", mysql_get_client_info());
    +#if !defined (PHP_WIN32) && !defined (NETWARE) && !defined(HAVE_MYSQLND)
    + php_info_print_table_row(2, "MYSQL_MODULE_TYPE", PHP_MYSQL_TYPE);
    + php_info_print_table_row(2, "MYSQL_SOCKET", MYSQL_UNIX_ADDR);
    + php_info_print_table_row(2, "MYSQL_INCLUDE", PHP_MYSQL_INCLUDE);
    + php_info_print_table_row(2, "MYSQL_LIBS", PHP_MYSQL_LIBS);
    +#endif
    +
    + php_info_print_table_end();
    +
    + DISPLAY_INI_ENTRIES();
    +
    +}
    +/* }}} */
    +
    +/* {{{ php_mysql_do_connect
    + */
    +#define MYSQL_DO_CONNECT_CLEANUP() \
    + if (free_host) { \
    + efree(host); \
    + }
    +
    +#define MYSQL_DO_CONNECT_RETURN_FALSE() \
    + MYSQL_DO_CONNECT_CLEANUP(); \
    + RETURN_FALSE;
    +
    +#ifdef HAVE_MYSQLND
    +#define MYSQL_PORT 0
    +#endif
    +
    +static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
    +{
    + char *user=NULL, *passwd=NULL, *host_and_port=NULL, *socket=NULL, *tmp=NULL, *host=NULL;
    + int user_len, passwd_len, host_len;
    + char *hashed_details=NULL;
    + int hashed_details_length, port = MYSQL_PORT;
    + int client_flags = 0;
    + php_mysql_conn *mysql=NULL;
    +#if MYSQL_VERSION_ID <= 32230
    + void (*handler) (int);
    +#endif
    + zend_bool free_host=0, new_link=0;
    + long connect_timeout;
    +
    +
    + connect_timeout = MySG(connect_timeout);
    +
    + socket = MySG(default_socket);
    +
    + if (MySG(default_port) < 0) {
    +#if !defined(PHP_WIN32) && !defined(NETWARE)
    + struct servent *serv_ptr;
    + char *env;
    +
    + MySG(default_port) = MYSQL_PORT;
    + if ((serv_ptr = getservbyname("mysql", "tcp"))) {
    + MySG(default_port) = (uint) ntohs((ushort) serv_ptr->s_port);
    + }
    + if ((env = getenv("MYSQL_TCP_PORT"))) {
    + MySG(default_port) = (uint) atoi(env);
    + }
    +#else
    + MySG(default_port) = MYSQL_PORT;
    +#endif
    + }
    +
    + if (PG(sql_safe_mode)) {
    + if (ZEND_NUM_ARGS()>0) {
    + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "SQL safe mode in effect - ignoring host/user/password information");
    + }
    + host_and_port=passwd=NULL;
    + user=php_get_current_user();
    + hashed_details_length = spprintf(&hashed_details, 0, "mysql__%s_", user);
    + client_flags = CLIENT_INTERACTIVE;
    + } else {
    + host_and_port = MySG(default_host);
    + user = MySG(default_user);
    + passwd = MySG(default_password);
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s&s&s&ll", &host_and_port, &host_len, UG(utf8_conv),
    + &user, &user_len, UG(utf8_conv), &passwd, &passwd_len, UG(utf8_conv),
    + &new_link, &client_flags)==FAILURE) {
    + WRONG_PARAM_COUNT;
    + }
    +
    + /* mysql_pconnect does not support new_link parameter */
    + if (persistent) {
    + client_flags= new_link;
    + }
    +
    + /* disable local infile option for open_basedir */
    + if (((PG(open_basedir) && PG(open_basedir)[0] != '\0')) && (client_flags & CLIENT_LOCAL_FILES)) {
    + client_flags ^= CLIENT_LOCAL_FILES;
    + }
    +
    + hashed_details_length = spprintf(&hashed_details, 0, "mysql_%s_%s_%s_%d", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd), client_flags);
    + }
    +
    + /* We cannot use mysql_port anymore in windows, need to use
    + * mysql_real_connect() to set the port.
    + */
    + if (host_len && (tmp=strchr(host_and_port, ':'))) {
    + host = estrndup(host_and_port, tmp-host_and_port);
    + free_host = 1;
    + tmp++;
    + if (tmp[0] != '/') {
    + port = atoi(tmp);
    + if ((tmp=strchr(tmp, ':'))) {
    + tmp++;
    + socket=tmp;
    + }
    + } else {
    + socket = tmp;
    + }
    + } else {
    + host = host_and_port;
    + port = MySG(default_port);
    + }
    +
    +#if MYSQL_VERSION_ID < 32200
    + mysql_port = port;
    +#endif
    +
    + if (!MySG(allow_persistent)) {
    + persistent=0;
    + }
    + if (persistent) {
    + zend_rsrc_list_entry *le;
    +
    + /* try to find if we already have this link in our persistent list */
    + if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length+1, (void **) &le)==FAILURE) { /* we don't */
    + zend_rsrc_list_entry new_le;
    +
    + if (MySG(max_links) != -1 && MySG(num_links) >= MySG(max_links)) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MySG(num_links));
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + if (MySG(max_persistent) != -1 && MySG(num_persistent) >= MySG(max_persistent)) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open persistent links (%ld)", MySG(num_persistent));
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + /* create the link */
    + mysql = (php_mysql_conn *) malloc(sizeof(php_mysql_conn));
    + mysql->active_result_id = 0;
    +#ifndef HAVE_MYSQLND
    + mysql->conn = mysql_init(NULL);
    +#else
    + mysql->conn = mysql_init(persistent);
    +#endif
    +
    + if (connect_timeout != -1)
    + mysql_options(mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout);
    +#ifndef HAVE_MYSQLND
    + if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
    +#else
    + if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
    + port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
    +#endif
    + {
    + /* Populate connect error globals so that the error functions can read them */
    + if (MySG(connect_error) != NULL) {
    + efree(MySG(connect_error));
    + }
    + MySG(connect_error) = estrdup(mysql_error(mysql->conn));
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error));
    +#if defined(HAVE_MYSQL_ERRNO)
    + MySG(connect_errno) = mysql_errno(mysql->conn);
    +#endif
    + free(mysql);
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    +
    + if (UG(unicode)) {
    +#ifdef MYSQL_HAS_SET_CHARSET
    + mysql_set_character_set(mysql->conn, "utf8");
    +#else
    + char *encoding = mysql_character_set_name(mysql->conn);
    + if (strcasecmp((char*)encoding, "utf8")) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't connect in Unicode mode. Client library was compiled with default charset %s", encoding);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    +#endif
    + }
    +
    + /* hash it up */
    + Z_TYPE(new_le) = le_plink;
    + new_le.ptr = mysql;
    + if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) {
    + free(mysql);
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + MySG(num_persistent)++;
    + MySG(num_links)++;
    + } else { /* The link is in our list of persistent connections */
    + if (Z_TYPE_P(le) != le_plink) {
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + mysql = (php_mysql_conn *) le->ptr;
    + mysql->active_result_id = 0;
    + /* ensure that the link did not die */
    + if (mysql_ping(mysql->conn)) {
    + if (mysql_errno(mysql->conn) == 2006) {
    +#ifndef HAVE_MYSQLND
    + if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
    +#else
    + if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
    + port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
    +#endif
    + {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect");
    + zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length+1);
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + }
    + }
    + }
    + ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);
    + } else { /* non persistent */
    + zend_rsrc_list_entry *index_ptr, new_index_ptr;
    +
    + /* first we check the hash for the hashed_details key. if it exists,
    + * it should point us to the right offset where the actual mysql link sits.
    + * if it doesn't, open a new mysql link, add it to the resource list,
    + * and add a pointer to it with hashed_details as the key.
    + */
    + if (!new_link && zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
    + int type;
    + long link;
    + void *ptr;
    +
    + if (Z_TYPE_P(index_ptr) != le_index_ptr) {
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + link = (long) index_ptr->ptr;
    + ptr = zend_list_find(link,&type); /* check if the link is still there */
    + if (ptr && (type==le_link || type==le_plink)) {
    + zend_list_addref(link);
    + Z_LVAL_P(return_value) = link;
    + php_mysql_set_default_link(link TSRMLS_CC);
    + Z_TYPE_P(return_value) = IS_RESOURCE;
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_CLEANUP();
    + return;
    + } else {
    + zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length+1);
    + }
    + }
    + if (MySG(max_links) != -1 && MySG(num_links) >= MySG(max_links)) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MySG(num_links));
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    +
    + mysql = (php_mysql_conn *) emalloc(sizeof(php_mysql_conn));
    + mysql->active_result_id = 0;
    +#ifndef HAVE_MYSQLND
    + mysql->conn = mysql_init(NULL);
    +#else
    + mysql->conn = mysql_init(persistent);
    +#endif
    +
    + if (connect_timeout != -1)
    + mysql_options(mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout);
    +
    +#ifndef HAVE_MYSQLND
    + if (mysql_real_connect(&mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
    +#else
    + if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
    + port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
    +#endif
    + {
    + /* Populate connect error globals so that the error functions can read them */
    + if (MySG(connect_error) != NULL) {
    + efree(MySG(connect_error));
    + }
    + MySG(connect_error) = estrdup(mysql_error(mysql->conn));
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error));
    +#if defined(HAVE_MYSQL_ERRNO)
    + MySG(connect_errno) = mysql_errno(mysql->conn);
    +#endif
    + efree(hashed_details);
    + efree(mysql);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    +
    + /* add it to the list */
    + ZEND_REGISTER_RESOURCE(return_value, mysql, le_link);
    +
    + /* add it to the hash */
    + new_index_ptr.ptr = (void *) Z_LVAL_P(return_value);
    + Z_TYPE(new_index_ptr) = le_index_ptr;
    + if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length+1,(void *) &new_index_ptr, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) {
    + efree(hashed_details);
    + MYSQL_DO_CONNECT_RETURN_FALSE();
    + }
    + MySG(num_links)++;
    + }
    +
    + efree(hashed_details);
    + php_mysql_set_default_link(Z_LVAL_P(return_value) TSRMLS_CC);
    + MYSQL_DO_CONNECT_CLEANUP();
    +}
    +/* }}} */
    +
    +/* {{{ php_mysql_get_default_link
    + */
    +static int php_mysql_get_default_link(INTERNAL_FUNCTION_PARAMETERS)
    +{
    + if (MySG(default_link)==-1) { /* no link opened yet, implicitly open one */
    + ht = 0;
    + php_mysql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    + }
    + return MySG(default_link);
    +}
    +/* }}} */
    +
    +/* {{{ proto resource mysql_connect([string hostname[:port][:/path/to/socket] [, string username [, string password [, bool new [, int flags]]]]]) U
    + Opens a connection to a MySQL Server */
    +PHP_FUNCTION(mysql_connect)
    +{
    + php_mysql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
    +}
    +/* }}} */
    +
    +/* {{{ proto resource mysql_pconnect([string hostname[:port][:/path/to/socket] [, string username [, string password [, int flags]]]]) U
    + Opens a persistent connection to a MySQL Server */
    +PHP_FUNCTION(mysql_pconnect)
    +{
    + php_mysql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
    +}
    +/* }}} */
    +
    +/* {{{ proto bool mysql_close([int link_identifier]) U
    + Close a MySQL connection */
    +PHP_FUNCTION(mysql_close)
    +{
    + zval **mysql_link=NULL;
    + int id;
    + php_mysql_conn *mysql;
    +
    + switch (ZEND_NUM_ARGS()) {
    + case 0:
    + id = MySG(default_link);
    + break;
    + case 1:
    + if (zend_get_parameters_ex(1, &mysql_link)==FAILURE) {
    + RETURN_FALSE;
    + }
    + id = -1;
    + break;
    + default:
    + WRONG_PARAM_COUNT;
    + break;
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + if (id==-1) { /* explicit resource number */
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    + zend_list_delete(Z_RESVAL_PP(mysql_link));
    + }
    +
    + if (id!=-1
    + || (mysql_link && Z_RESVAL_PP(mysql_link)==MySG(default_link))) {
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    + zend_list_delete(MySG(default_link));
    + MySG(default_link) = -1;
    + }
    +
    + RETURN_TRUE;
    +}
    +/* }}} */
    +
    +/* {{{ proto bool mysql_select_db(string database_name [, int link_identifier]) U
    + Selects a MySQL database */
    +PHP_FUNCTION(mysql_select_db)
    +{
    + zval *mysql_link;
    + char *db;
    + int id=-1, db_len;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|r", &db, &db_len, UG(utf8_conv), &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 1) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + if (php_mysql_select_db(mysql, db TSRMLS_CC)) {
    + RETURN_TRUE;
    + } else {
    + RETURN_FALSE;
    + }
    +}
    +/* }}} */
    +
    +#ifdef HAVE_GETINFO_FUNCS
    +
    +/* {{{ proto string mysql_get_client_info(void) U
    + Returns a string that represents the client library version */
    +PHP_FUNCTION(mysql_get_client_info)
    +{
    + if (ZEND_NUM_ARGS() != 0) {
    + WRONG_PARAM_COUNT;
    + }
    +
    + RETURN_UTF8_STRING((char *)mysql_get_client_info(), ZSTR_DUPLICATE);
    +}
    +/* }}} */
    +
    +/* {{{ proto string mysql_get_host_info([int link_identifier]) U
    + Returns a string describing the type of connection in use, including the server host name */
    +PHP_FUNCTION(mysql_get_host_info)
    +{
    + zval **mysql_link;
    + int id;
    + php_mysql_conn *mysql;
    +
    + switch(ZEND_NUM_ARGS()) {
    + case 0:
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + break;
    + case 1:
    + if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
    + RETURN_FALSE;
    + }
    + id = -1;
    + break;
    + default:
    + WRONG_PARAM_COUNT;
    + break;
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + RETURN_UTF8_STRING((char *)mysql_get_host_info(mysql->conn), ZSTR_DUPLICATE);
    +}
    +/* }}} */
    +
    +/* {{{ proto int mysql_get_proto_info([int link_identifier]) U
    + Returns the protocol version used by current connection */
    +PHP_FUNCTION(mysql_get_proto_info)
    +{
    + zval **mysql_link;
    + int id;
    + php_mysql_conn *mysql;
    +
    + switch(ZEND_NUM_ARGS()) {
    + case 0:
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + break;
    + case 1:
    + if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
    + RETURN_FALSE;
    + }
    + id = -1;
    + break;
    + default:
    + WRONG_PARAM_COUNT;
    + break;
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + RETURN_LONG(mysql_get_proto_info(mysql->conn));
    +}
    +/* }}} */
    +
    +/* {{{ proto string mysql_get_server_info([int link_identifier]) U
    + Returns a string that represents the server version number */
    +PHP_FUNCTION(mysql_get_server_info)
    +{
    + zval **mysql_link;
    + int id;
    + php_mysql_conn *mysql;
    +
    + switch(ZEND_NUM_ARGS()) {
    + case 0:
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + break;
    + case 1:
    + if (zend_get_parameters_ex(1,&mysql_link)==FAILURE) {
    + RETURN_FALSE;
    + }
    + id = -1;
    + break;
    + default:
    + WRONG_PARAM_COUNT;
    + break;
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + RETURN_UTF8_STRING((char *)mysql_get_server_info(mysql->conn), ZSTR_DUPLICATE);
    +}
    +/* }}} */
    +
    +/* {{{ proto string mysql_info([int link_identifier]) U
    + Returns a string containing information about the most recent query */
    +PHP_FUNCTION(mysql_info)
    +{
    + zval *mysql_link;
    + int id = -1;
    + char *str;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 0) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + if ((str = (char *)mysql_info(mysql->conn))) {
    + RETURN_UTF8_STRING(str,ZSTR_DUPLICATE);
    + } else {
    + RETURN_FALSE;
    + }
    +}
    +/* }}} */
    +
    +/* {{{ proto int mysql_thread_id([int link_identifier]) U
    + Returns the thread id of current connection */
    +PHP_FUNCTION(mysql_thread_id)
    +{
    + zval *mysql_link = NULL;
    + int id = -1;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 0) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + RETURN_LONG(mysql_thread_id(mysql->conn));
    +}
    +/* }}} */
    +
    +/* {{{ proto string mysql_stat([int link_identifier]) U
    + Returns a string containing status information */
    +PHP_FUNCTION(mysql_stat)
    +{
    + zval *mysql_link = NULL;
    + int id = -1;
    + php_mysql_conn *mysql;
    + char *stat;
    +#ifdef HAVE_MYSQLND
    + uint stat_len;
    +#endif
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 0) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    +#ifndef HAVE_MYSQLND
    + if ((stat = (char *)mysql_stat(mysql->conn))) {
    + RETURN_UTF8_STRING(stat, ZSTR_DUPLICATE);
    +#else
    + if (mysqlnd_stat(mysql->conn, &stat, &stat_len) == PASS) {
    + RETURN_UTF8_STRINGL(stat, stat_len, ZSTR_AUTOFREE);
    +#endif
    + } else {
    + RETURN_FALSE;
    + }
    +
    +}
    +/* }}} */
    +
    +/* {{{ proto string mysql_client_encoding([int link_identifier]) U
    + Returns the default character set for the current connection */
    +PHP_FUNCTION(mysql_client_encoding)
    +{
    + zval *mysql_link = NULL;
    + int id = -1;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 0) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + RETURN_UTF8_STRING((char *)mysql_character_set_name(mysql->conn), ZSTR_DUPLICATE);
    +}
    +/* }}} */
    +#endif
    +
    +#ifdef MYSQL_HAS_SET_CHARSET
    +/* {{{ proto bool mysql_set_charset(string csname [, int link_identifier]) U
    + sets client character set */
    +PHP_FUNCTION(mysql_set_charset)
    +{
    + zval *mysql_link = NULL;
    + char *csname;
    + int id = -1, csname_len;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|r", &csname, &csname_len, UG(utf8_conv), &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 1) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + /* Only allow the use of this function with unicode.semantics=On */
    + if (UG(unicode) && (csname_len != 4 || strncasecmp(csname, "utf8", 4))) {
    + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Character set %s is not supported when running PHP with unicode.semantics=On.", csname);
    + RETURN_FALSE;
    + }
    +
    + if (!mysql_set_character_set(mysql->conn, csname)) {
    + RETURN_TRUE;
    + } else {
    + RETURN_FALSE;
    + }
    +}
    +/* }}} */
    +#endif
    +
    +#ifndef NETWARE /* The below two functions not supported on NetWare */
    +#if MYSQL_VERSION_ID < 40000
    +/* {{{ proto bool mysql_create_db(string database_name [, int link_identifier]) U
    + Create a MySQL database */
    +PHP_FUNCTION(mysql_create_db)
    +{
    + zval *mysql_link;
    + int id = -1, db_len;
    + char *db;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|r", &db, &db_len, UG(utf8_conv), &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 1) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    +
    + if (mysql_create_db(mysql->conn, db)==0) {
    + RETURN_TRUE;
    + } else {
    + RETURN_FALSE;
    + }
    +}
    +/* }}} */
    +
    +/* {{{ proto bool mysql_drop_db(string database_name [, int link_identifier]) U
    + Drops (delete) a MySQL database */
    +PHP_FUNCTION(mysql_drop_db)
    +{
    + zval *mysql_link;
    + char *db;
    + int id = -1, db_len;
    + php_mysql_conn *mysql;
    +
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|r", &db, &db_len, UG(utf8_conv), &mysql_link) == FAILURE) {
    + return;
    + }
    +
    + if (ZEND_NUM_ARGS() == 1) {
    + id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
    + CHECK_LINK(id);
    + }
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
    +
    + if (mysql_drop_db(mysql->conn, db)==0) {
    + RETURN_TRUE;
    + } else {
    + RETURN_FALSE;
    + }
    +}
    +/* }}} */
    +#endif
    +#endif /* NETWARE */
    +
    +/* {{{ php_mysql_do_query_general
    + */
    +static void php_mysql_do_query_general(char *query, zval **mysql_link, int link_id, char *db, int use_store, zval *return_value TSRMLS_DC)
    +{
    + php_mysql_conn *mysql;
    + MYSQL_RES *mysql_result;
    +
    + ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, link_id, "MySQL-Link", le_link, le_plink);
    +
    + if (db) {
    + if (!php_mysql_select_db(mysql, db TSRMLS_CC)) {
    + RETURN_FALSE;
    + }
    + }
    +
    + PHPMY_UNBUFFERED_QUERY_CHECK();
    +
    +#ifndef HAVE_MYSQLND
    + /* check explain */
    + if (MySG(trace_mode)) {
    + if (!strncasecmp("select", query, 6)){
    + MYSQL_ROW row;
    +
    + char *newquery;
    + spprintf(&newquery, 0, "EXPLAIN %s", query);
    + mysql_real_query(mysql->conn, newquery, strlen(newquery));
    + efree (newquery);
    + if (mysql_errno(mysql->conn)) {
    + php_error_docref("