summaryrefslogtreecommitdiff
path: root/ext/mysqli
diff options
context:
space:
mode:
authorGeorg Richter <georg@php.net>2003-10-29 20:48:47 +0000
committerGeorg Richter <georg@php.net>2003-10-29 20:48:47 +0000
commit8caae993a328dd425d503c0a3a9bcb20a1b6d5b3 (patch)
tree559fa70ffc225964e44a12f08c2005ef4fd15573 /ext/mysqli
parent28369f6e86c2d322938ac672811f9eaa8502055b (diff)
downloadphp-git-8caae993a328dd425d503c0a3a9bcb20a1b6d5b3.tar.gz
added support for embedded MySQL Server
some prototype fixes
Diffstat (limited to 'ext/mysqli')
-rw-r--r--ext/mysqli/config.m423
-rw-r--r--ext/mysqli/mysqli_api.c43
-rw-r--r--ext/mysqli/mysqli_nonapi.c61
-rw-r--r--ext/mysqli/php_mysqli.h28
4 files changed, 137 insertions, 18 deletions
diff --git a/ext/mysqli/config.m4 b/ext/mysqli/config.m4
index 141e058d6d..65c1e1ede0 100644
--- a/ext/mysqli/config.m4
+++ b/ext/mysqli/config.m4
@@ -6,7 +6,11 @@ PHP_ARG_WITH(mysqli, for MySQLi support,
[ --with-mysqli[=FILE] Include MySQLi support. FILE is the optional
pathname to mysql_config.])
-if test "$PHP_MYSQLI" != "no"; then
+PHP_ARG_WITH(embedded_mysqli, for embedded MySQLi support,
+[ --with-embedded-mysqli[=FILE] Include embedded MySQLi support. FILE is the optional
+ pathname to mysql_config.])
+
+if test "$PHP_MYSQLI" != "no" '-o' "$PHP_EMBEDDED_MYSQLI" != "no"; then
if test "$PHP_MYSQL" = "yes"; then
AC_MSG_ERROR([--with-mysql (using bundled libs) can not be used together with --with-mysqli.])
@@ -15,12 +19,23 @@ if test "$PHP_MYSQLI" != "no"; then
if test "$PHP_MYSQLI" = "yes"; then
MYSQL_CONFIG=`$php_shtool path mysql_config`
else
- MYSQL_CONFIG=$PHP_MYSQLI
+ if test "$PHP_MYSQLI" != "no"; then
+ MYSQL_CONFIG=$PHP_MYSQLI
+ else
+ MYSQL_CONFIG=$PHP_EMBEDDED_MYSQLI
+ fi
+ fi
+
+ if test "$PHP_MYSQLI" != "no"; then
+ MYSQL_LIB_CFG='--libs'
+ else
+ AC_DEFINE([HAVE_EMBEDDED_MYSQLI],[1], [embedded MySQL support enabled])
+ MYSQL_LIB_CFG='--libmysqld-libs'
fi
- if test -x "$MYSQL_CONFIG" && $MYSQL_CONFIG --libs > /dev/null 2>&1; then
+ if test -x "$MYSQL_CONFIG" && $MYSQL_CONFIG $MYSQL_LIB_CFG > /dev/null 2>&1; then
MYSQLI_INCLINE=`$MYSQL_CONFIG --cflags | sed -e "s/'//g"`
- MYSQLI_LIBLINE=`$MYSQL_CONFIG --libs | sed -e "s/'//g"`
+ MYSQLI_LIBLINE=`$MYSQL_CONFIG $MYSQL_LIB_CFG | sed -e "s/'//g"`
else
AC_MSG_RESULT([mysql_config not found])
AC_MSG_ERROR([Please reinstall the mysql distribution])
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 6e0e408410..42695bee56 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1614,6 +1614,41 @@ PHP_FUNCTION(mysqli_send_query)
}
/* }}} */
+#ifdef HAVE_EMBEDDED_MYSQLI
+/* {{{ proto bool mysqli_server_init(void)
+ initialize embedded server */
+PHP_FUNCTION(mysqli_server_init)
+{
+ zval *server;
+ zval *groups;
+
+ if (MyG(embedded)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Embedded server already initialized.");
+ RETURN_FALSE;
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &server, &groups) == FAILURE) {
+ return;
+ }
+
+ if (mysql_server_init(0, NULL, NULL)) {
+ RETURN_FALSE;
+ }
+ MyG(embedded) = 1;
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto void mysqli_server_end(void)
+*/
+PHP_FUNCTION(mysqli_server_end)
+{
+ mysql_server_end();
+}
+/* }}} */
+#endif
+
+
/* {{{ proto bool mysqli_slave_query(object link, string query)
Enforce execution of a query on a slave in a master/slave setup */
PHP_FUNCTION(mysqli_slave_query)
@@ -1832,7 +1867,7 @@ PHP_FUNCTION(mysqli_stmt_error)
}
/* }}} */
-/* {{{ proto resource mysqli_stmt_store_result(stmt)
+/* {{{ proto object mysqli_stmt_store_result(stmt)
*/
PHP_FUNCTION(mysqli_stmt_store_result)
{
@@ -1871,7 +1906,7 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
#endif
/* }}} */
-/* {{{ proto resource mysqli_store_result(object link)
+/* {{{ proto object mysqli_store_result(object link)
Buffer result set on client */
PHP_FUNCTION(mysqli_store_result)
{
@@ -1921,7 +1956,7 @@ PHP_FUNCTION(mysqli_thread_safe)
/* }}} */
-/* {{{ proto resource mysqli_use_result(object link)
+/* {{{ proto object mysqli_use_result(object link)
Directly retrieve query results - do not buffer results on client side */
PHP_FUNCTION(mysqli_use_result)
{
@@ -1945,7 +1980,7 @@ PHP_FUNCTION(mysqli_use_result)
}
/* }}} */
-/* {{{ proto resource mysqli_warning_count (object link)
+/* {{{ proto int mysqli_warning_count (object link)
Return number of warnings from the last query for the given link */
PHP_FUNCTION(mysqli_warning_count)
{
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 610c24e2cd..d5c8f22b3f 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -29,7 +29,7 @@
#include "ext/standard/info.h"
#include "php_mysqli.h"
-/* {{{ proto resource mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]])
+/* {{{ proto object mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]])
Open a connection to a mysql server */
PHP_FUNCTION(mysqli_connect)
{
@@ -100,6 +100,65 @@ PHP_FUNCTION(mysqli_connect)
}
/* }}} */
+#ifdef HAVE_EMBEDDED_MYSQLI
+/* {{{ proto object mysqli_embedded_connect(void)
+ Open a connection to a embedded mysql server */
+PHP_FUNCTION(mysqli_embedded_connect)
+{
+ MYSQL *mysql;
+ MYSQLI_RESOURCE *mysqli_resource;
+ PR_MYSQL *prmysql = NULL;
+ zval *object = getThis();
+ char *dbname = NULL;
+ int dblen = 0;
+ struct timeval starttime;
+
+ if (!MyG(embedded)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Embedded server was not initialized.");
+ RETURN_FALSE;
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &dbname, &dblen) == FAILURE) {
+ return;
+ }
+
+ if (MyG(profiler)){
+ gettimeofday(&starttime, NULL);
+ }
+
+ mysql = mysql_init(NULL);
+
+ if (mysql_real_connect(mysql, NULL, NULL, NULL, dbname, 0, NULL, 0) == NULL) {
+ php_mysqli_set_error(mysql_errno(mysql), (char *) mysql_error(mysql) TSRMLS_CC);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql));
+ /* free mysql structure */
+ mysql_close(mysql);
+ RETURN_FALSE;
+ }
+
+ php_mysqli_set_error(mysql_errno(mysql), (char *) mysql_error(mysql) TSRMLS_CC);
+
+ if (MyG(profiler)) {
+ prmysql = (PR_MYSQL *)MYSQLI_PROFILER_NEW(prmain, MYSQLI_PR_MYSQL, 0);
+ php_mysqli_profiler_timediff(starttime, &prmysql->header.elapsedtime);
+ MYSQLI_PROFILER_STARTTIME(prmysql);
+ prmysql->hostname = prmysql->username = NULL;
+ prmysql->thread_id = mysql->thread_id;
+ }
+
+ mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
+ mysqli_resource->ptr = (void *)mysql;
+ mysqli_resource->prinfo = prmysql;
+
+ if (!object) {
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
+ } else {
+ ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr = mysqli_resource;
+ }
+}
+/* }}} */
+#endif
+
/* {{{ proto int mysqli_connect_errno()
Returns the numerical value of the error message from last connect command */
PHP_FUNCTION(mysqli_connect_errno)
diff --git a/ext/mysqli/php_mysqli.h b/ext/mysqli/php_mysqli.h
index 8ae19652fc..0d0f15f1dd 100644
--- a/ext/mysqli/php_mysqli.h
+++ b/ext/mysqli/php_mysqli.h
@@ -210,6 +210,9 @@ PHP_FUNCTION(mysqli_debug);
PHP_FUNCTION(mysqli_disable_reads_from_master);
PHP_FUNCTION(mysqli_disable_rpl_parse);
PHP_FUNCTION(mysqli_dump_debug_info);
+#ifdef HAVE_EMBEDDED_MYSQLI
+PHP_FUNCTION(mysqli_embedded_connect);
+#endif
PHP_FUNCTION(mysqli_enable_reads_from_master);
PHP_FUNCTION(mysqli_enable_rpl_parse);
PHP_FUNCTION(mysqli_errno);
@@ -260,6 +263,10 @@ PHP_FUNCTION(mysqli_rpl_query_type);
PHP_FUNCTION(mysqli_select_db);
PHP_FUNCTION(mysqli_send_long_data);
PHP_FUNCTION(mysqli_send_query);
+#ifdef HAVE_EMBEDDED_MYSQLI
+PHP_FUNCTION(mysqli_server_init);
+PHP_FUNCTION(mysqli_server_end);
+#endif
PHP_FUNCTION(mysqli_slave_query);
#if MYSQL_VERSION_ID >= 40101
PHP_FUNCTION(mysqli_sqlstate);
@@ -283,17 +290,20 @@ PHP_FUNCTION(mysqli_use_result);
PHP_FUNCTION(mysqli_warning_count);
ZEND_BEGIN_MODULE_GLOBALS(mysqli)
- long default_link;
- long num_links;
- long max_links;
+ long default_link;
+ long num_links;
+ long max_links;
unsigned int default_port;
- char *default_host;
- char *default_user;
- char *default_pw;
- char *default_socket;
- long error_no;
- char *error_msg;
+ char *default_host;
+ char *default_user;
+ char *default_pw;
+ char *default_socket;
+ long error_no;
+ char *error_msg;
unsigned int profiler;
+#ifdef HAVE_EMBEDDED_MYSQLI
+ unsigned int embedded;
+#endif
ZEND_END_MODULE_GLOBALS(mysqli)
#ifdef ZTS