|
PHP mysqlnd svn commit: r542 - in trunk: . php4 php4/ext php4/ext/mysql
Author: ahristov
Date: 2007-06-27 19:52:12 +0200 (Wed, 27 Jun 2007)
New Revision: 542
Added:
trunk/php4/
trunk/php4/ext/
trunk/php4/ext/mysql/
trunk/php4/ext/mysql/CREDITS
trunk/php4/ext/mysql/INSTALL
trunk/php4/ext/mysql/LICENSE
trunk/php4/ext/mysql/README
trunk/php4/ext/mysql/config.m4
trunk/php4/ext/mysql/config.w32
trunk/php4/ext/mysql/mysql.dsp
trunk/php4/ext/mysql/mysql.mak
trunk/php4/ext/mysql/mysql_mysqlnd.h
trunk/php4/ext/mysql/php_mysql.c
trunk/php4/ext/mysql/php_mysql.h
Log:
ext/mysql for PHP4 for mysqlnd. Streams are different
in PHP4 so it will need some investigation. php_mysql.c
is however patched for mysqlnd. Thus, only mysqlnd has to be
ported for PHP4.
Added: trunk/php4/ext/mysql/CREDITS
- trunk/php4/ext/mysql/CREDITS 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/CREDITS 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,2 @@
+MySQL +Zeev Suraski, Zak Greant, Georg Richter
Added: trunk/php4/ext/mysql/INSTALL
- trunk/php4/ext/mysql/INSTALL 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/INSTALL 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,50 @@
+REQUIREMENTS
+ +The new MySQL native driver for PHP (mysqlnd) requires: + + - PHP 4
+ - MySQL 4.1 or newer + + +BUILDING ON UNIX
+ +1) Get a copy of PHP 4 + +For example, you can check out PHP 4, 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 -r PHP_4_4 php-src + +2) Copy mysqlnd into the PHP 4 source tree + +Remove the ext/mysqli directory from your PHP directory, +for example: + +me@myhost:~> cd php4 +me@myhost:~/php4> rm -rf ext/mysql + +Copy mysqlnd into your PHP directory, for +example: + +me@myhost:~/php4> cp -R ~/php-mysqlnd/php4/ext/mysql ext/mysql + +3) Run buildconf + +me@myhost:~/php4> ./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:~/php4> ./configure --with-mysql=mysqlnd + +Note that you must not specify the path to the MySQL +utility mysql_config. + +5) Build PHP + +me@myhost:~/php4> make clean; make; make install
Added: trunk/php4/ext/mysql/LICENSE
- trunk/php4/ext/mysql/LICENSE 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/LICENSE 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,68 @@
+-------------------------------------------------------------------- + The PHP License, version 3.01 +Copyright (c) 1999 - 2006 The PHP Group. All rights reserved. +-------------------------------------------------------------------- + +Redistribution and use in source and binary forms, with or without +modification, is permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. The name "PHP" must not be used to endorse or promote products + derived from this software without prior written permission. For + written permission, please contact group@php.net. + + 4. Products derived from this software may not be called "PHP", nor + may "PHP" appear in their name, without prior written permission + from group@php.net. You may indicate that your software works in + conjunction with PHP by saying "Foo for PHP" instead of calling + it "PHP Foo" or "phpfoo" + + 5. The PHP Group may publish revised and/or new versions of the + license from time to time. Each version will be given a + distinguishing version number. + Once covered code has been published under a particular version + of the license, you may always continue to use it under the terms + of that version. You may also choose to use such covered code + under the terms of any subsequent version of the license + published by the PHP Group. No one other than the PHP Group has + the right to modify the terms applicable to covered code created + under this License. + + 6. Redistributions of any form whatsoever must retain the following + acknowledgment: + "This product includes PHP software, freely available from + <http://www.php.net/software/>". + +THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
+ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
+DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+ +-------------------------------------------------------------------- + +This software consists of voluntary contributions made by many +individuals on behalf of the PHP Group. + +The PHP Group can be contacted via Email at group@php.net. + +For more information on the PHP Group and the PHP project, +please see <http://www.php.net>. + +PHP includes the Zend Engine, freely available at +<http://www.zend.com>.
Added: trunk/php4/ext/mysql/README
- trunk/php4/ext/mysql/README 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/README 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,10 @@
+This is an experimental (alpha) port of the MySQL native driver +for PHP 4 and the ext/mysql PHP extension. + +It requires PHP 4 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/php4/ext/mysql/config.m4
- trunk/php4/ext/mysql/config.m4 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/config.m4 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,182 @@
+dnl +dnl $Id: config.m4,v 1.54.2.3.2.1 2005/07/26 14:02:00 hyanantha Exp $ +dnl + +sinclude(ext/mysql/libmysql/acinclude.m4) +sinclude(ext/mysql/libmysql/mysql.m4) +sinclude(libmysql/acinclude.m4) +sinclude(libmysql/mysql.m4) + +AC_DEFUN([MYSQL_LIB_CHK], [
+ str="$MYSQL_DIR/$1/lib$MY_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 unspecified, the bundled MySQL library will be used. + mysqlnd for the bundled mysqlnd library], yes) + +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" != "no" && test "$PHP_MYSQLI" != "mysqlnd"; then + AC_DEFINE(HAVE_MYSQL, 1, [Whether you have MySQL]) + + 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 +fi + +if test "$PHP_MYSQL" = "mysqlnd"; then + MYSQL_MODULE_TYPE=builtin + MYSQL_CHECKS
+ sources="mysqlnd/mysqlnd.c mysqlnd/mysqlnd_charset.c mysqlnd/mysqlnd_wireprotocol.c \ + mysqlnd/mysqlnd_ps.c mysqlnd/mysqlnd_loaddata.c mysqlnd/mysqlnd_palloc.c \ + mysqlnd/mysqlnd_ps_codec.c mysqlnd/mysqlnd_statistics.c mysqlnd/mysqlnd_qcache.c\ + mysqlnd/mysqlnd_result.c mysqlnd/mysqlnd_result_meta.c" + + PHP_NEW_EXTENSION(mysql, php_mysql.c $sources, $ext_shared,,-I@ext_srcdir@/mysqlnd) + PHP_ADD_BUILD_DIR($ext_builddir/mysqlnd) + echo > ext/mysql/php_have_mysqlnd.h + test "$PHP_MYSQL" = "mysqlnd" && PHP_DEFINE(HAVE_MYSQLND, 1, [ext/mysql]) + +elif test "$PHP_MYSQL" = "yes"; then + MYSQL_MODULE_TYPE=builtin + MYSQL_CHECKS
+ sources="libmysql/libmysql.c libmysql/errmsg.c libmysql/net.c libmysql/violite.c libmysql/password.c \ + libmysql/my_init.c libmysql/my_lib.c libmysql/my_static.c libmysql/my_malloc.c libmysql/my_realloc.c libmysql/my_create.c \ + libmysql/my_delete.c libmysql/my_tempnam.c libmysql/my_open.c libmysql/mf_casecnv.c libmysql/my_read.c \ + libmysql/my_write.c libmysql/errors.c libmysql/my_error.c libmysql/my_getwd.c libmysql/my_div.c libmysql/mf_pack.c \ + libmysql/my_messnc.c libmysql/mf_dirname.c libmysql/mf_fn_ext.c libmysql/mf_wcomp.c libmysql/typelib.c libmysql/safemalloc.c \ + libmysql/my_alloc.c libmysql/mf_format.c libmysql/mf_path.c libmysql/mf_unixpath.c libmysql/my_fopen.c libmysql/mf_loadpath.c \ + libmysql/my_pthread.c libmysql/my_thr_init.c libmysql/thr_mutex.c libmysql/mulalloc.c libmysql/string.c libmysql/default.c \ + libmysql/my_compress.c libmysql/array.c libmysql/my_once.c libmysql/list.c libmysql/my_net.c libmysql/dbug.c \ + libmysql/strmov.c libmysql/strxmov.c libmysql/strnmov.c libmysql/strmake.c libmysql/strend.c libmysql/strfill.c \ + libmysql/is_prefix.c libmysql/int2str.c libmysql/str2int.c libmysql/strinstr.c \ + libmysql/strcont.c libmysql/strcend.c libmysql/bchange.c libmysql/bmove.c libmysql/bmove_upp.c \ + libmysql/longlong2str.c libmysql/strtoull.c libmysql/strtoll.c libmysql/charset.c libmysql/ctype.c" + + PHP_NEW_EXTENSION(mysql, php_mysql.c $sources, $ext_shared,,-I@ext_srcdir@/libmysql) + PHP_ADD_BUILD_DIR($ext_builddir/libmysql) + +elif test "$PHP_MYSQL" != "no"; then + + MYSQL_TYPE_CHECKS
+ + PHP_NEW_EXTENSION(mysql, php_mysql.c, $ext_shared) + + for i in $PHP_MYSQL; do + if test -r $i/include/mysql/mysql.h; then + MYSQL_DIR=$i + MYSQL_INC_DIR=$i/include/mysql + elif test -r $i/include/mysql.h; then + MYSQL_DIR=$i + MYSQL_INC_DIR=$i/include + fi + done + + if test -z "$MYSQL_DIR"; then + AC_MSG_ERROR(Cannot find MySQL header files under $PHP_MYSQL) + fi + + MYSQL_MODULE_TYPE=external + + MY_LIBNAME=mysqlclient + case $host_alias in + *netware*[)] + MY_LIBNAME=mysql + ;; + esac + + for i in lib lib/mysql; do + MYSQL_LIB_CHK($i) + done + + if test -z "$MYSQL_LIB_DIR"; then + AC_MSG_ERROR(Cannot find lib$MY_LIBNAME library under $MYSQL_DIR) + fi + + PHP_CHECK_LIBRARY($MY_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($MY_LIBNAME, mysql_error, [], [ + AC_MSG_ERROR([mysql configure failed. Please check config.log for more information.]) + ], [ + -L$PHP_ZLIB_DIR/lib -L$MYSQL_LIB_DIR + ]) + MYSQL_LIBS="-L$PHP_ZLIB_DIR/lib -lz" + else + PHP_ADD_LIBRARY(z,, MYSQL_SHARED_LIBADD) + PHP_CHECK_LIBRARY($MY_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($MY_LIBNAME, $MYSQL_LIB_DIR, MYSQL_SHARED_LIBADD)
+ MYSQL_LIBS="-L$MYSQL_LIB_DIR -l$MY_LIBNAME $MYSQL_LIBS" + + PHP_ADD_INCLUDE($MYSQL_INC_DIR)
+ MYSQL_INCLUDE=-I$MYSQL_INC_DIR
+ +else + MYSQL_MODULE_TYPE=none +fi + +PHP_SUBST(MYSQL_SHARED_LIBADD)
+PHP_SUBST_OLD(MYSQL_MODULE_TYPE)
+PHP_SUBST_OLD(MYSQL_LIBS)
+PHP_SUBST_OLD(MYSQL_INCLUDE)
Added: trunk/php4/ext/mysql/config.w32
- trunk/php4/ext/mysql/config.w32 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/config.w32 2007-06-27 17:52:12 UTC (rev 542)
@@ -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"); + } +}
Added: trunk/php4/ext/mysql/mysql.dsp
- trunk/php4/ext/mysql/mysql.dsp 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/mysql.dsp 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,171 @@
+# Microsoft Developer Studio Project File - Name="mysql" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT **
+ +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=mysql - Win32 Debug_TS +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE
+!MESSAGE NMAKE /f "mysql.mak". +!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE
+!MESSAGE NMAKE /f "mysql.mak" CFG="mysql - Win32 Debug_TS" +!MESSAGE
+!MESSAGE Possible choices for configuration are: +!MESSAGE
+!MESSAGE "mysql - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "mysql - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "mysql - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "mysql - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE
+ +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "mysql - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MYSQL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\MySQL\include" /I "..\..\TSRM" /D "NDEBUG" /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL_MYSQL" /D HAVE_MYSQL=1 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZEND_WIN32" /D "PHP_WIN32" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40d /d "NDEBUG" +# ADD RSC /l 0x40d /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmySQL.lib php4nts.lib /nologo /dll /machine:I386 /out:"Release/php_mysql.dll" /libpath:"..\..\..\MySQL\lib\opt" /libpath:"..\..\Release" + +!ELSEIF "$(CFG)" == "mysql - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MYSQL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\MySQL\include" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL_MYSQL" /D HAVE_MYSQL=1 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZEND_WIN32" /D "PHP_WIN32" /FR /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40d /d "_DEBUG" +# ADD RSC /l 0x40d /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmySQL.lib php4nts_debug.lib /nologo /dll /debug /machine:I386 /out:"Debug/php_mysql.dll" /pdbtype:sept /libpath:"..\..\..\MySQL\lib\Debug" /libpath:"..\..\Debug" + +!ELSEIF "$(CFG)" == "mysql - Win32 Debug_TS" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug_TS" +# PROP BASE Intermediate_Dir "Debug_TS" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug_TS" +# PROP Intermediate_Dir "Debug_TS" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL" /D HAVE_MYSQL=1 /FR /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\MySQL\include" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL_MYSQL" /D HAVE_MYSQL=1 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZEND_WIN32" /D "PHP_WIN32" /FR /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40d /d "_DEBUG" +# ADD RSC /l 0x40d /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmySQL.lib php4ts.lib /nologo /dll /debug /machine:I386 /out:"Debug_TS/php_mysql.dll" /pdbtype:sept /libpath:"..\..\..\MySQL\lib\Debug" /libpath:"..\..\Debug_TS" + +!ELSEIF "$(CFG)" == "mysql - Win32 Release_TS" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release_TS" +# PROP BASE Intermediate_Dir "Release_TS" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release_TS" +# PROP Intermediate_Dir "Release_TS" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL" /D HAVE_MYSQL=1 /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\MySQL\include" /I "..\..\TSRM" /D "NDEBUG" /D "ZTS" /D "MYSQL_EXPORTS" /D "COMPILE_DL_MYSQL_MYSQL" /D HAVE_MYSQL=1 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "ZEND_WIN32" /D "PHP_WIN32" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x40d /d "NDEBUG" +# ADD RSC /l 0x40d /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libmySQL.lib php4ts.lib /nologo /dll /machine:I386 /out:"Release_TS/php_mysql.dll" /libpath:"..\..\..\MySQL\lib\opt" /libpath:"..\..\Release_TS" + +!ENDIF
+ +# Begin Target + +# Name "mysql - Win32 Release" +# Name "mysql - Win32 Debug" +# Name "mysql - Win32 Debug_TS" +# Name "mysql - Win32 Release_TS" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\php_mysql.c +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\php_mysql.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\Readme_w32.txt +# End Source File +# End Target +# End Project
Added: trunk/php4/ext/mysql/mysql.mak
- trunk/php4/ext/mysql/mysql.mak 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/mysql.mak 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,168 @@
+# 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 MySQL Extension" +VMAJ = 0
+VMIN = 60
+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 -align 1 +C_FLAGS += -nostdinc -nosyspath +C_FLAGS += -DNETWARE -DZTS -DNEW_LIBC -DUSE_OLD_FUNCTIONS -DCOMPILE_DL=1
+C_FLAGS += -I. -I$(PROJECT_ROOT)/main -I$(PROJECT_ROOT)/ext/standard -I$(PROJECT_ROOT) -I$(PROJECT_ROOT)/netware +C_FLAGS += -I$(PROJECT_ROOT)/zend -I$(PROJECT_ROOT)/tsrm +C_FLAGS += -I- -I$(SDK_DIR)/include -I$(MWCIncludes) +C_FLAGS += -I$(MYSQL_DIR)/include -DCOMPILE_DL_MYSQL=1 +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 = mysql_functions \ +# mysql_module_entry \ +# ($(MODULE_NAME).nlm) get_module +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): $(DEPDS) $(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 _NonAppStart >> $(basename $@).def + @echo Exit _NonAppStop >> $(basename $@).def + + @echo Linking $@... + @echo $(LD_FLAGS) -commandfile $(basename $@).def > $(basename $@).link + @echo $(LIBRARY) $(OBJECTS) >> $(basename $@).link + @$(LINK) @$(basename $@).link + + +.PHONY: clean +clean: cleand 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/php4/ext/mysql/mysql_mysqlnd.h
- trunk/php4/ext/mysql/mysql_mysqlnd.h 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/mysql_mysqlnd.h 2007-06-27 17:52:12 UTC (rev 542)
@@ -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/php4/ext/mysql/php_mysql.c
- trunk/php4/ext/mysql/php_mysql.c 2007-06-27 17:25:18 UTC (rev 541)
+++ trunk/php4/ext/mysql/php_mysql.c 2007-06-27 17:52:12 UTC (rev 542)
@@ -0,0 +1,2614 @@
+/* + +----------------------------------------------------------------------+ + | PHP Version 4 | + +----------------------------------------------------------------------+ + | 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.174.2.29.2.5 2007/06/18 22:01:56 stas 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" + +#if HAVE_MYSQL + +#ifdef PHP_WIN32 +# include <winsock.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" + +#ifdef HAVE_MYSQLND +#define MYSQL_PORT 0 +#endif + +/* 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 + +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[] + */ +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_FE(mysql_create_db, NULL) + PHP_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_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) + + /* 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_FALIAS(mysql_createdb, mysql_create_db, NULL) + PHP_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_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), + NO_VERSION_YET,
+ STANDARD_MODULE_PROPERTIES
+}; +/* }}} */ + +ZEND_DECLARE_MODULE_GLOBALS(mysql) + +#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 */ +#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 + } else { + MySG(default_port) = atoi(new_value); + } + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_INI */
+PHP_INI_BEGIN()
+ STD_PHP_INI_BOOLEAN("mysql.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, zend_mysql_globals, mysql_globals) + STD_PHP_INI_ENTRY_EX("mysql.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_persistent, zend_mysql_globals, mysql_globals, display_link_numbers) + STD_PHP_INI_ENTRY_EX("mysql.max_links", "-1", PHP_INI_SYSTEM, OnUpdateInt, 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, OnUpdateInt, connect_timeout, zend_mysql_globals, mysql_globals) + STD_PHP_INI_BOOLEAN("mysql.trace_mode", "0", PHP_INI_ALL, OnUpdateInt, trace_mode, zend_mysql_globals, mysql_globals) +#ifdef HAVE_MYSQLND + STD_PHP_INI_ENTRY("mysql.cache_size", "2000", PHP_INI_SYSTEM, OnUpdateInt, cache_size, zend_mysql_globals, mysql_globals) +#endif +PHP_INI_END()
+/* }}} */ + +/* {{{ php_mysql_init_globals + */ +static void php_mysql_init_globals(zend_mysql_globals *mysql_globals) +{ + 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) +{ + ZEND_INIT_MODULE_GLOBALS(mysql, php_mysql_init_globals, NULL); + + 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 + +#if !defined(HAVE_MYSQLND) && MYSQL_VERSION_ID >= 40000 + if (mysql_server_init(0, NULL, NULL)) { + return FAILURE; + } +#endif + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION
+ */ +PHP_MSHUTDOWN_FUNCTION(mysql) +{ +#if !defined(HAVE_MYSQLND) && MYSQL_VERSION_ID >= 40000 +#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) && MYSQL_VERSION_ID >= 40000 + 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) && MYSQL_VERSION_ID >= 40000 + 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;
+ +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; + 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 + zval **z_host=NULL, **z_user=NULL, **z_passwd=NULL, **z_new_link=NULL, **z_client_flags=NULL; + zend_bool free_host=0, new_link=0; + long connect_timeout; + + + connect_timeout = MySG(connect_timeout); + + socket = MySG(default_socket); + + 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 = strlen(user)+5+3; + hashed_details = (char *) emalloc(hashed_details_length+1); + sprintf(hashed_details, "mysql__%s_", user); + client_flags = CLIENT_INTERACTIVE; + } else { + host_and_port = MySG(default_host); + user = MySG(default_user); + passwd = MySG(default_password); + + switch(ZEND_NUM_ARGS()) { + case 0: /* defaults */ + break; + case 1: { + if (zend_get_parameters_ex(1, &z_host)==FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + } + break; + case 2: { + if (zend_get_parameters_ex(2, &z_host, &z_user)==FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + convert_to_string_ex(z_user); + user = Z_STRVAL_PP(z_user); + } + break; + case 3: { + if (zend_get_parameters_ex(3, &z_host, &z_user, &z_passwd) == FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + convert_to_string_ex(z_user); + convert_to_string_ex(z_passwd); + user = Z_STRVAL_PP(z_user); + passwd = Z_STRVAL_PP(z_passwd); + } + break; + case 4: { + if (!persistent) { + if (zend_get_parameters_ex(4, &z_host, &z_user, &z_passwd, &z_new_link) == FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + convert_to_string_ex(z_user); + convert_to_string_ex(z_passwd); + convert_to_boolean_ex(z_new_link); + user = Z_STRVAL_PP(z_user); + passwd = Z_STRVAL_PP(z_passwd); + new_link = Z_BVAL_PP(z_new_link); + } + else { + if (zend_get_parameters_ex(4, &z_host, &z_user, &z_passwd, &z_client_flags) == FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + convert_to_string_ex(z_user); + convert_to_string_ex(z_passwd); + convert_to_long_ex(z_client_flags); + user = Z_STRVAL_PP(z_user); + passwd = Z_STRVAL_PP(z_passwd); + client_flags = Z_LVAL_PP(z_client_flags); + } + } + break; + case 5: { + if (zend_get_parameters_ex(5, &z_host, &z_user, &z_passwd, &z_new_link, &z_client_flags) == FAILURE) { + MYSQL_DO_CONNECT_RETURN_FALSE();
+ } + convert_to_string_ex(z_user); + convert_to_string_ex(z_passwd); + convert_to_boolean_ex(z_new_link); + convert_to_long_ex(z_client_flags); + user = Z_STRVAL_PP(z_user); + passwd = Z_STRVAL_PP(z_passwd); + new_link = Z_BVAL_PP(z_new_link); + client_flags = Z_LVAL_PP(z_client_flags); + } + break; + default: + WRONG_PARAM_COUNT;
+ break; + } + /* disable local infile option for open_basedir and safe_mode */ + if (((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode)) && (client_flags & CLIENT_LOCAL_FILES)) { + client_flags ^= CLIENT_LOCAL_FILES; + } + + if (z_host) { + SEPARATE_ZVAL(z_host); /* We may modify z_host if it contains a port, separate */ + convert_to_string_ex(z_host); + host_and_port = Z_STRVAL_PP(z_host); + if (z_user) { + convert_to_string_ex(z_user); + user = Z_STRVAL_PP(z_user); + if (z_passwd) { + convert_to_string_ex(z_passwd); + passwd = Z_STRVAL_PP(z_passwd); + } + } + } + + hashed_details_length = sizeof("mysql___")-1 + strlen(SAFE_STRING(host_and_port))+strlen(SAFE_STRING(user))+strlen(SAFE_STRING(passwd)); + hashed_details = (char *) emalloc(hashed_details_length+1); + sprintf(hashed_details, "mysql_%s_%s_%s", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd)); + } + + /* We cannot use mysql_port anymore in windows, need to use + * mysql_real_connect() to set the port. + */ + if (host_and_port && (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) { + 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 */ + 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();
+ } + + /* 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(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 */ + 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(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]]]]]) + 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]]]]) + 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]) + 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:
|