Back to index

php5  5.3.10
mysqli_embedded.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Georg Richter <georg@php.net>                                |
00016   +----------------------------------------------------------------------+
00017 
00018 */
00019 #ifdef HAVE_CONFIG_H
00020 #include "config.h"
00021 #endif
00022 
00023 #include <signal.h>
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "php_mysqli_structs.h"
00029 
00030 /* {{{ proto bool mysqli_embedded_server_start(bool start, array arguments, array groups)
00031    initialize and start embedded server */
00032 PHP_FUNCTION(mysqli_embedded_server_start)
00033 {
00034 #ifdef HAVE_EMBEDDED_MYSQLI
00035        long start;
00036        zval *args;
00037        zval *grps;
00038 
00039        int    argc = 0;
00040        char **arguments;
00041        char **groups;
00042        HashPosition pos;
00043        int index, rc;
00044 
00045        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", &start, &args, &grps) == FAILURE) {
00046               return;
00047        }
00048 
00049        if (!start) {
00050               mysql_server_init(-1,NULL, NULL);
00051               RETURN_TRUE;
00052        }
00053        /* get arguments */
00054        if ((argc = zend_hash_num_elements(HASH_OF(args)))) {
00055               arguments = safe_emalloc(sizeof(char *), argc + 1, 0);
00056               arguments[0] = NULL;
00057 
00058               zend_hash_internal_pointer_reset_ex(HASH_OF(args), &pos);
00059 
00060               for (index = 0;; zend_hash_move_forward_ex(HASH_OF(args), &pos))      {
00061                      zval **item;
00062 
00063                      if (zend_hash_get_current_data_ex(HASH_OF(args), (void **) &item, &pos) == FAILURE) {
00064                             break;
00065                      }
00066 
00067                      convert_to_string_ex(item);
00068 
00069                      arguments[++index] = Z_STRVAL_PP(item);
00070               }
00071               argc++;
00072        }
00073 
00074        /* get groups */
00075        if ((zend_hash_num_elements(HASH_OF(grps)))) {
00076               groups = safe_emalloc(sizeof(char *), zend_hash_num_elements(HASH_OF(grps)) + 1, 0);
00077               groups[0] = NULL;
00078 
00079               zend_hash_internal_pointer_reset_ex(HASH_OF(grps), &pos);
00080 
00081               for (index = 0;; zend_hash_move_forward_ex(HASH_OF(grps), &pos))      {
00082                      zval ** item;
00083 
00084                      if (zend_hash_get_current_data_ex(HASH_OF(grps), (void **) &item, &pos) == FAILURE) {
00085                             break;
00086                      }
00087 
00088                      convert_to_string_ex(item);
00089 
00090                      groups[++index] = Z_STRVAL_PP(item);
00091               }
00092               groups[index] = NULL;
00093        } else {
00094               groups = safe_emalloc(sizeof(char *), 1, 0);
00095               groups[0] = NULL;
00096        }
00097 
00098        rc = mysql_server_init(argc, arguments, groups);
00099 
00100        if (argc) {
00101               efree(arguments);
00102        }
00103        efree(groups);
00104 
00105        if (rc) {
00106               RETURN_FALSE;
00107        }
00108        RETURN_TRUE;
00109 #endif
00110 }
00111 /* }}} */
00112 
00113 /* {{{ proto void mysqli_embedded_server_end(void)
00114 */
00115 PHP_FUNCTION(mysqli_embedded_server_end)
00116 {
00117 #ifdef HAVE_MYSQLI_EMBEDDED
00118        mysql_server_end();
00119 #endif
00120 }
00121 /* }}} */
00122 
00123 /*
00124  * Local variables:
00125  * tab-width: 4
00126  * c-basic-offset: 4
00127  * indent-tabs-mode: t
00128  * End:
00129  * vim600: noet sw=4 ts=4 fdm=marker
00130  * vim<600: noet sw=4 ts=4
00131  */