mysqli_embedded.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Georg Richter <georg@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <signal.h>
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "ext/standard/info.h"
  25. #include "php_mysqli_structs.h"
  26. /* {{{ proto bool mysqli_embedded_server_start(bool start, array arguments, array groups)
  27. initialize and start embedded server */
  28. PHP_FUNCTION(mysqli_embedded_server_start)
  29. {
  30. #ifdef HAVE_EMBEDDED_MYSQLI
  31. long start;
  32. zval *args;
  33. zval *grps;
  34. int argc = 0;
  35. char **arguments;
  36. char **groups;
  37. HashPosition pos;
  38. int index, rc;
  39. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "laa", &start, &args, &grps) == FAILURE) {
  40. return;
  41. }
  42. if (!start) {
  43. mysql_server_init(-1,NULL, NULL);
  44. RETURN_TRUE;
  45. }
  46. /* get arguments */
  47. if ((argc = zend_hash_num_elements(HASH_OF(args)))) {
  48. arguments = safe_emalloc(sizeof(char *), argc + 1, 0);
  49. arguments[0] = NULL;
  50. zend_hash_internal_pointer_reset_ex(HASH_OF(args), &pos);
  51. for (index = 0;; zend_hash_move_forward_ex(HASH_OF(args), &pos)) {
  52. zval **item;
  53. if (zend_hash_get_current_data_ex(HASH_OF(args), (void **) &item, &pos) == FAILURE) {
  54. break;
  55. }
  56. convert_to_string_ex(item);
  57. arguments[++index] = Z_STRVAL_PP(item);
  58. }
  59. argc++;
  60. }
  61. /* get groups */
  62. if ((zend_hash_num_elements(HASH_OF(grps)))) {
  63. groups = safe_emalloc(sizeof(char *), zend_hash_num_elements(HASH_OF(grps)) + 1, 0);
  64. groups[0] = NULL;
  65. zend_hash_internal_pointer_reset_ex(HASH_OF(grps), &pos);
  66. for (index = 0;; zend_hash_move_forward_ex(HASH_OF(grps), &pos)) {
  67. zval ** item;
  68. if (zend_hash_get_current_data_ex(HASH_OF(grps), (void **) &item, &pos) == FAILURE) {
  69. break;
  70. }
  71. convert_to_string_ex(item);
  72. groups[++index] = Z_STRVAL_PP(item);
  73. }
  74. groups[index] = NULL;
  75. } else {
  76. groups = safe_emalloc(sizeof(char *), 1, 0);
  77. groups[0] = NULL;
  78. }
  79. rc = mysql_server_init(argc, arguments, groups);
  80. if (argc) {
  81. efree(arguments);
  82. }
  83. efree(groups);
  84. if (rc) {
  85. RETURN_FALSE;
  86. }
  87. RETURN_TRUE;
  88. #endif
  89. }
  90. /* }}} */
  91. /* {{{ proto void mysqli_embedded_server_end(void)
  92. */
  93. PHP_FUNCTION(mysqli_embedded_server_end)
  94. {
  95. #ifdef HAVE_MYSQLI_EMBEDDED
  96. mysql_server_end();
  97. #endif
  98. }
  99. /* }}} */
  100. /*
  101. * Local variables:
  102. * tab-width: 4
  103. * c-basic-offset: 4
  104. * indent-tabs-mode: t
  105. * End:
  106. * vim600: noet sw=4 ts=4 fdm=marker
  107. * vim<600: noet sw=4 ts=4
  108. */