PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ext/mysqli/mysqli_api.c

http://github.com/infusion/PHP
C | 2625 lines | 1877 code | 371 blank | 377 comment | 383 complexity | a11b6df8b02c581a0c4b8619f9d75a9e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 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. | Authors: Georg Richter <georg@php.net> |
  16. | Andrey Hristov <andrey@php.net> |
  17. | Ulf Wendel <uw@php.net> |
  18. +----------------------------------------------------------------------+
  19. $Id: mysqli_api.c 307533 2011-01-17 11:20:54Z kalle $
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include <signal.h>
  25. #include "php.h"
  26. #include "php_ini.h"
  27. #include "php_globals.h"
  28. #include "ext/standard/info.h"
  29. #include "php_mysqli_structs.h"
  30. #include "mysqli_priv.h"
  31. /* {{{ proto mixed mysqli_affected_rows(object link)
  32. Get number of affected rows in previous MySQL operation */
  33. PHP_FUNCTION(mysqli_affected_rows)
  34. {
  35. MY_MYSQL *mysql;
  36. zval *mysql_link;
  37. my_ulonglong rc;
  38. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  39. return;
  40. }
  41. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  42. rc = mysql_affected_rows(mysql->mysql);
  43. if (rc == (my_ulonglong) -1) {
  44. RETURN_LONG(-1);
  45. }
  46. MYSQLI_RETURN_LONG_LONG(rc);
  47. }
  48. /* }}} */
  49. /* {{{ proto mixed mysqli_matched_rows(object link)
  50. Get number of matched rows in previous MySQL operation */
  51. PHP_FUNCTION(mysqli_matched_rows)
  52. {
  53. MY_MYSQL *mysql;
  54. zval *mysql_link;
  55. my_ulonglong rc;
  56. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  57. return;
  58. }
  59. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  60. rc = mysql_matched_rows(mysql->mysql);
  61. if (rc == (my_ulonglong) -1) {
  62. RETURN_LONG(-1);
  63. }
  64. MYSQLI_RETURN_LONG_LONG(rc);
  65. }
  66. /* }}} */
  67. /* {{{ proto bool mysqli_autocommit(object link, bool mode)
  68. Turn auto commit on or of */
  69. PHP_FUNCTION(mysqli_autocommit)
  70. {
  71. MY_MYSQL *mysql;
  72. zval *mysql_link;
  73. zend_bool automode;
  74. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &automode) == FAILURE) {
  75. return;
  76. }
  77. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  78. if (mysql_autocommit(mysql->mysql, (my_bool)automode)) {
  79. RETURN_FALSE;
  80. }
  81. RETURN_TRUE;
  82. }
  83. /* }}} */
  84. /* {{{ mysqli_stmt_bind_param_do_bind */
  85. #ifndef MYSQLI_USE_MYSQLND
  86. static
  87. int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
  88. zval ***args, unsigned int start, const char * const types TSRMLS_DC)
  89. {
  90. int i, ofs;
  91. MYSQL_BIND *bind;
  92. unsigned long rc;
  93. /* prevent leak if variables are already bound */
  94. if (stmt->param.var_cnt) {
  95. php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
  96. }
  97. stmt->param.is_null = ecalloc(num_vars, sizeof(char));
  98. bind = (MYSQL_BIND *) ecalloc(num_vars, sizeof(MYSQL_BIND));
  99. ofs = 0;
  100. for (i = start; i < argc; i++) {
  101. /* set specified type */
  102. switch (types[ofs]) {
  103. case 'd': /* Double */
  104. bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
  105. bind[ofs].buffer = &Z_DVAL_PP(args[i]);
  106. bind[ofs].is_null = &stmt->param.is_null[ofs];
  107. break;
  108. case 'i': /* Integer */
  109. #if SIZEOF_LONG==8
  110. bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
  111. #elif SIZEOF_LONG==4
  112. bind[ofs].buffer_type = MYSQL_TYPE_LONG;
  113. #endif
  114. bind[ofs].buffer = &Z_LVAL_PP(args[i]);
  115. bind[ofs].is_null = &stmt->param.is_null[ofs];
  116. break;
  117. case 'b': /* Blob (send data) */
  118. bind[ofs].buffer_type = MYSQL_TYPE_LONG_BLOB;
  119. /* don't initialize is_null and length to 0 because we use ecalloc */
  120. break;
  121. case 's': /* string */
  122. bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
  123. /* don't initialize buffer and buffer_length because we use ecalloc */
  124. bind[ofs].is_null = &stmt->param.is_null[ofs];
  125. break;
  126. default:
  127. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
  128. rc = 1;
  129. goto end_1;
  130. }
  131. ofs++;
  132. }
  133. rc = mysql_stmt_bind_param(stmt->stmt, bind);
  134. end_1:
  135. if (rc) {
  136. efree(stmt->param.is_null);
  137. } else {
  138. stmt->param.var_cnt = num_vars;
  139. stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0);
  140. for (i = 0; i < num_vars; i++) {
  141. if (bind[i].buffer_type != MYSQL_TYPE_LONG_BLOB) {
  142. Z_ADDREF_P(*args[i+start]);
  143. stmt->param.vars[i] = *args[i+start];
  144. } else {
  145. stmt->param.vars[i] = NULL;
  146. }
  147. }
  148. }
  149. efree(bind);
  150. return rc;
  151. }
  152. #else
  153. static
  154. int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
  155. zval ***args, unsigned int start, const char * const types TSRMLS_DC)
  156. {
  157. unsigned int i;
  158. MYSQLND_PARAM_BIND *params;
  159. enum_func_status ret = FAIL;
  160. /* If no params -> skip binding and return directly */
  161. if (argc == start) {
  162. return PASS;
  163. }
  164. params = mysqlnd_stmt_alloc_param_bind(stmt->stmt);
  165. if (!params) {
  166. goto end;
  167. }
  168. for (i = 0; i < (argc - start); i++) {
  169. zend_uchar type;
  170. switch (types[i]) {
  171. case 'd': /* Double */
  172. type = MYSQL_TYPE_DOUBLE;
  173. break;
  174. case 'i': /* Integer */
  175. #if SIZEOF_LONG==8
  176. type = MYSQL_TYPE_LONGLONG;
  177. #elif SIZEOF_LONG==4
  178. type = MYSQL_TYPE_LONG;
  179. #endif
  180. break;
  181. case 'b': /* Blob (send data) */
  182. type = MYSQL_TYPE_LONG_BLOB;
  183. break;
  184. case 's': /* string */
  185. type = MYSQL_TYPE_VAR_STRING;
  186. break;
  187. default:
  188. /* We count parameters from 1 */
  189. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + start + 1);
  190. ret = FAIL;
  191. mysqlnd_stmt_free_param_bind(stmt->stmt, params);
  192. goto end;
  193. }
  194. params[i].zv = *(args[i + start]);
  195. params[i].type = type;
  196. }
  197. ret = mysqlnd_stmt_bind_param(stmt->stmt, params);
  198. end:
  199. return ret;
  200. }
  201. #endif
  202. /* }}} */
  203. /* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....]) U
  204. Bind variables to a prepared statement as parameters */
  205. PHP_FUNCTION(mysqli_stmt_bind_param)
  206. {
  207. zval ***args;
  208. int argc = ZEND_NUM_ARGS();
  209. int num_vars;
  210. int start = 2;
  211. MY_STMT *stmt;
  212. zval *mysql_stmt;
  213. char *types;
  214. int types_len;
  215. unsigned long rc;
  216. /* calculate and check number of parameters */
  217. if (argc < 2) {
  218. /* there has to be at least one pair */
  219. WRONG_PARAM_COUNT;
  220. }
  221. if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry,
  222. &types, &types_len) == FAILURE) {
  223. return;
  224. }
  225. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  226. num_vars = argc - 1;
  227. if (getThis()) {
  228. start = 1;
  229. } else {
  230. /* ignore handle parameter in procedural interface*/
  231. --num_vars;
  232. }
  233. if (!types_len) {
  234. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type or no types specified");
  235. RETURN_FALSE;
  236. }
  237. if (types_len != argc - start) {
  238. /* number of bind variables doesn't match number of elements in type definition string */
  239. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
  240. RETURN_FALSE;
  241. }
  242. if (types_len != mysql_stmt_param_count(stmt->stmt)) {
  243. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
  244. RETURN_FALSE;
  245. }
  246. args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
  247. if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
  248. zend_wrong_param_count(TSRMLS_C);
  249. rc = 1;
  250. } else {
  251. rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types TSRMLS_CC);
  252. MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
  253. }
  254. efree(args);
  255. RETURN_BOOL(!rc);
  256. }
  257. /* }}} */
  258. /* {{{ mysqli_stmt_bind_result_do_bind */
  259. #ifndef MYSQLI_USE_MYSQLND
  260. /* TODO:
  261. do_alloca, free_alloca
  262. */
  263. static int
  264. mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC)
  265. {
  266. MYSQL_BIND *bind;
  267. int i, ofs;
  268. int var_cnt = argc - start;
  269. long col_type;
  270. ulong rc;
  271. /* prevent leak if variables are already bound */
  272. if (stmt->result.var_cnt) {
  273. php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
  274. }
  275. bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND));
  276. {
  277. int size;
  278. char *p= emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER)));
  279. stmt->result.buf = (VAR_BUFFER *) p;
  280. stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER);
  281. memset(p, 0, size);
  282. }
  283. for (i=start; i < var_cnt + start ; i++) {
  284. ofs = i - start;
  285. col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;
  286. switch (col_type) {
  287. case MYSQL_TYPE_DOUBLE:
  288. case MYSQL_TYPE_FLOAT:
  289. convert_to_double_ex(args[i]);
  290. stmt->result.buf[ofs].type = IS_DOUBLE;
  291. stmt->result.buf[ofs].buflen = sizeof(double);
  292. /* allocate buffer for double */
  293. stmt->result.buf[ofs].val = (char *)emalloc(sizeof(double));
  294. bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
  295. bind[ofs].buffer = stmt->result.buf[ofs].val;
  296. bind[ofs].is_null = &stmt->result.is_null[ofs];
  297. break;
  298. case MYSQL_TYPE_NULL:
  299. stmt->result.buf[ofs].type = IS_NULL;
  300. /*
  301. don't initialize to 0 :
  302. 1. stmt->result.buf[ofs].buflen
  303. 2. bind[ofs].buffer
  304. 3. bind[ofs].buffer_length
  305. because memory was allocated with ecalloc
  306. */
  307. bind[ofs].buffer_type = MYSQL_TYPE_NULL;
  308. bind[ofs].is_null = &stmt->result.is_null[ofs];
  309. break;
  310. case MYSQL_TYPE_SHORT:
  311. case MYSQL_TYPE_TINY:
  312. case MYSQL_TYPE_LONG:
  313. case MYSQL_TYPE_INT24:
  314. case MYSQL_TYPE_YEAR:
  315. convert_to_long_ex(args[i]);
  316. stmt->result.buf[ofs].type = IS_LONG;
  317. /* don't set stmt->result.buf[ofs].buflen to 0, we used ecalloc */
  318. stmt->result.buf[ofs].val = (char *)emalloc(sizeof(int));
  319. bind[ofs].buffer_type = MYSQL_TYPE_LONG;
  320. bind[ofs].buffer = stmt->result.buf[ofs].val;
  321. bind[ofs].is_null = &stmt->result.is_null[ofs];
  322. bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
  323. break;
  324. case MYSQL_TYPE_LONGLONG:
  325. #if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
  326. case MYSQL_TYPE_BIT:
  327. #endif
  328. stmt->result.buf[ofs].type = IS_STRING;
  329. stmt->result.buf[ofs].buflen = sizeof(my_ulonglong);
  330. stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
  331. bind[ofs].buffer_type = col_type;
  332. bind[ofs].buffer = stmt->result.buf[ofs].val;
  333. bind[ofs].is_null = &stmt->result.is_null[ofs];
  334. bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
  335. bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
  336. bind[ofs].length = &stmt->result.buf[ofs].output_len;
  337. break;
  338. case MYSQL_TYPE_DATE:
  339. case MYSQL_TYPE_TIME:
  340. case MYSQL_TYPE_DATETIME:
  341. case MYSQL_TYPE_NEWDATE:
  342. case MYSQL_TYPE_VAR_STRING:
  343. case MYSQL_TYPE_STRING:
  344. case MYSQL_TYPE_TINY_BLOB:
  345. case MYSQL_TYPE_BLOB:
  346. case MYSQL_TYPE_MEDIUM_BLOB:
  347. case MYSQL_TYPE_LONG_BLOB:
  348. case MYSQL_TYPE_TIMESTAMP:
  349. case MYSQL_TYPE_DECIMAL:
  350. case MYSQL_TYPE_GEOMETRY:
  351. #ifdef FIELD_TYPE_NEWDECIMAL
  352. case MYSQL_TYPE_NEWDECIMAL:
  353. #endif
  354. {
  355. #if MYSQL_VERSION_ID >= 50107
  356. /* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
  357. my_bool tmp;
  358. #else
  359. uint tmp = 0;
  360. #endif
  361. stmt->result.buf[ofs].type = IS_STRING;
  362. /*
  363. If the user has called $stmt->store_result() then we have asked
  364. max_length to be updated. this is done only for BLOBS because we don't want to allocate
  365. big chunkgs of memory 2^16 or 2^24
  366. */
  367. if (stmt->stmt->fields[ofs].max_length == 0 &&
  368. !mysql_stmt_attr_get(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp) && !tmp)
  369. {
  370. /*
  371. Allocate directly 256 because it's easier to allocate a bit more
  372. than update max length even for text columns. Try SELECT UNION SELECT UNION with
  373. different lengths and you will see that we get different lengths in stmt->stmt->fields[ofs].length
  374. The just take 256 and saves us from realloc-ing.
  375. */
  376. stmt->result.buf[ofs].buflen =
  377. (stmt->stmt->fields) ? (stmt->stmt->fields[ofs].length) ? stmt->stmt->fields[ofs].length + 1: 256: 256;
  378. } else {
  379. /*
  380. the user has called store_result(). if he does not there is no way to determine the
  381. libmysql does not allow us to allocate 0 bytes for a buffer so we try 1
  382. */
  383. if (!(stmt->result.buf[ofs].buflen = stmt->stmt->fields[ofs].max_length))
  384. ++stmt->result.buf[ofs].buflen;
  385. }
  386. stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
  387. bind[ofs].buffer_type = MYSQL_TYPE_STRING;
  388. bind[ofs].buffer = stmt->result.buf[ofs].val;
  389. bind[ofs].is_null = &stmt->result.is_null[ofs];
  390. bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
  391. bind[ofs].length = &stmt->result.buf[ofs].output_len;
  392. break;
  393. }
  394. default:
  395. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server returned unknown type %ld. Probably your client library is incompatible with the server version you use!", col_type);
  396. break;
  397. }
  398. }
  399. rc = mysql_stmt_bind_result(stmt->stmt, bind);
  400. MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
  401. if (rc) {
  402. /* dont close the statement or subsequent usage (for example ->execute()) will lead to crash */
  403. for (i=0; i < var_cnt ; i++) {
  404. if (stmt->result.buf[i].val) {
  405. efree(stmt->result.buf[i].val);
  406. }
  407. }
  408. /* Don't free stmt->result.is_null because is_null & buf are one block of memory */
  409. efree(stmt->result.buf);
  410. } else {
  411. stmt->result.var_cnt = var_cnt;
  412. stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
  413. for (i = start; i < var_cnt+start; i++) {
  414. ofs = i-start;
  415. Z_ADDREF_PP(args[i]);
  416. stmt->result.vars[ofs] = *args[i];
  417. }
  418. }
  419. efree(bind);
  420. return rc;
  421. }
  422. #else
  423. static int
  424. mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC)
  425. {
  426. unsigned int i;
  427. MYSQLND_RESULT_BIND * params = mysqlnd_stmt_alloc_result_bind(stmt->stmt);
  428. if (params) {
  429. for (i = 0; i < (argc - start); i++) {
  430. params[i].zv = *(args[i + start]);
  431. }
  432. return mysqlnd_stmt_bind_result(stmt->stmt, params);
  433. }
  434. return FAIL;
  435. }
  436. #endif
  437. /* }}} */
  438. /* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...]) U
  439. Bind variables to a prepared statement for result storage */
  440. PHP_FUNCTION(mysqli_stmt_bind_result)
  441. {
  442. zval ***args;
  443. int argc = ZEND_NUM_ARGS();
  444. int start = 1;
  445. ulong rc;
  446. MY_STMT *stmt;
  447. zval *mysql_stmt;
  448. if (getThis()) {
  449. start = 0;
  450. }
  451. if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  452. return;
  453. }
  454. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  455. if (argc < (getThis() ? 1 : 2)) {
  456. WRONG_PARAM_COUNT;
  457. }
  458. if ((argc - start) != mysql_stmt_field_count(stmt->stmt)) {
  459. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
  460. RETURN_FALSE;
  461. }
  462. args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
  463. if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
  464. efree(args);
  465. WRONG_PARAM_COUNT;
  466. }
  467. rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, start TSRMLS_CC);
  468. efree(args);
  469. RETURN_BOOL(!rc);
  470. }
  471. /* }}} */
  472. /* {{{ proto bool mysqli_change_user(object link, string user, string password, string database)
  473. Change logged-in user of the active connection */
  474. PHP_FUNCTION(mysqli_change_user)
  475. {
  476. MY_MYSQL *mysql;
  477. zval *mysql_link = NULL;
  478. char *user, *password, *dbname;
  479. int user_len, password_len, dbname_len;
  480. ulong rc;
  481. #if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
  482. const CHARSET_INFO * old_charset;
  483. #endif
  484. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) {
  485. return;
  486. }
  487. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  488. #if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
  489. old_charset = mysql->mysql->charset;
  490. #endif
  491. rc = mysql_change_user(mysql->mysql, user, password, dbname);
  492. MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
  493. if (rc) {
  494. RETURN_FALSE;
  495. }
  496. #if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
  497. if (mysql_get_server_version(mysql->mysql) < 501023L) {
  498. /*
  499. Request the current charset, or it will be reset to the system one.
  500. 5.0 doesn't support it. Support added in 5.1.23 by fixing the following bug :
  501. Bug #30472 libmysql doesn't reset charset, insert_id after succ. mysql_change_user() call
  502. */
  503. rc = mysql_set_character_set(mysql->mysql, old_charset->csname);
  504. }
  505. #endif
  506. RETURN_TRUE;
  507. }
  508. /* }}} */
  509. /* {{{ proto string mysqli_character_set_name(object link)
  510. Returns the name of the character set used for this connection */
  511. PHP_FUNCTION(mysqli_character_set_name)
  512. {
  513. MY_MYSQL *mysql;
  514. zval *mysql_link;
  515. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  516. return;
  517. }
  518. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  519. RETURN_STRING((char *)mysql_character_set_name(mysql->mysql), 1);
  520. }
  521. /* }}} */
  522. /* {{{ php_mysqli_close */
  523. void php_mysqli_close(MY_MYSQL * mysql, int close_type, int resource_status TSRMLS_DC)
  524. {
  525. if (resource_status > MYSQLI_STATUS_INITIALIZED) {
  526. MyG(num_links)--;
  527. }
  528. if (!mysql->persistent) {
  529. mysqli_close(mysql->mysql, close_type);
  530. } else {
  531. zend_rsrc_list_entry *le;
  532. if (zend_hash_find(&EG(persistent_list), mysql->hash_key, strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
  533. if (Z_TYPE_P(le) == php_le_pmysqli()) {
  534. mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
  535. #if defined(MYSQLI_USE_MYSQLND)
  536. mysqlnd_end_psession(mysql->mysql);
  537. #endif
  538. zend_ptr_stack_push(&plist->free_links, mysql->mysql);
  539. MyG(num_active_persistent)--;
  540. MyG(num_inactive_persistent)++;
  541. }
  542. }
  543. mysql->persistent = FALSE;
  544. }
  545. mysql->mysql = NULL;
  546. php_clear_mysql(mysql);
  547. }
  548. /* }}} */
  549. /* {{{ proto bool mysqli_close(object link)
  550. Close connection */
  551. PHP_FUNCTION(mysqli_close)
  552. {
  553. zval *mysql_link;
  554. MY_MYSQL *mysql;
  555. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  556. return;
  557. }
  558. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_INITIALIZED);
  559. php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, ((MYSQLI_RESOURCE *)((mysqli_object *)zend_object_store_get_object(mysql_link TSRMLS_CC))->ptr)->status TSRMLS_CC);
  560. ((MYSQLI_RESOURCE *)((mysqli_object *)zend_object_store_get_object(mysql_link TSRMLS_CC))->ptr)->status = MYSQLI_STATUS_UNKNOWN;
  561. MYSQLI_CLEAR_RESOURCE(&mysql_link);
  562. efree(mysql);
  563. RETURN_TRUE;
  564. }
  565. /* }}} */
  566. /* {{{ proto bool mysqli_commit(object link)
  567. Commit outstanding actions and close transaction */
  568. PHP_FUNCTION(mysqli_commit)
  569. {
  570. MY_MYSQL *mysql;
  571. zval *mysql_link;
  572. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  573. return;
  574. }
  575. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  576. if (mysql_commit(mysql->mysql)) {
  577. RETURN_FALSE;
  578. }
  579. RETURN_TRUE;
  580. }
  581. /* }}} */
  582. /* {{{ proto bool mysqli_data_seek(object result, int offset)
  583. Move internal result pointer */
  584. PHP_FUNCTION(mysqli_data_seek)
  585. {
  586. MYSQL_RES *result;
  587. zval *mysql_result;
  588. long offset;
  589. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
  590. return;
  591. }
  592. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  593. if (mysqli_result_is_unbuffered(result)) {
  594. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
  595. RETURN_FALSE;
  596. }
  597. if (offset < 0 || offset >= mysql_num_rows(result)) {
  598. RETURN_FALSE;
  599. }
  600. mysql_data_seek(result, offset);
  601. RETURN_TRUE;
  602. }
  603. /* }}} */
  604. /* {{{ proto void mysqli_debug(string debug) U
  605. */
  606. PHP_FUNCTION(mysqli_debug)
  607. {
  608. char *debug;
  609. int debug_len;
  610. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &debug, &debug_len) == FAILURE) {
  611. return;
  612. }
  613. mysql_debug(debug);
  614. RETURN_TRUE;
  615. }
  616. /* }}} */
  617. /* {{{ proto bool mysqli_dump_debug_info(object link)
  618. */
  619. PHP_FUNCTION(mysqli_dump_debug_info)
  620. {
  621. MY_MYSQL *mysql;
  622. zval *mysql_link;
  623. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  624. return;
  625. }
  626. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  627. RETURN_BOOL(!mysql_dump_debug_info(mysql->mysql))
  628. }
  629. /* }}} */
  630. /* {{{ proto int mysqli_errno(object link)
  631. Returns the numerical value of the error message from previous MySQL operation */
  632. PHP_FUNCTION(mysqli_errno)
  633. {
  634. MY_MYSQL *mysql;
  635. zval *mysql_link;
  636. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  637. return;
  638. }
  639. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  640. RETURN_LONG(mysql_errno(mysql->mysql));
  641. }
  642. /* }}} */
  643. /* {{{ proto string mysqli_error(object link)
  644. Returns the text of the error message from previous MySQL operation */
  645. PHP_FUNCTION(mysqli_error)
  646. {
  647. MY_MYSQL *mysql;
  648. zval *mysql_link;
  649. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  650. return;
  651. }
  652. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  653. RETURN_STRING((char *)mysql_error(mysql->mysql),1);
  654. }
  655. /* }}} */
  656. #ifndef MYSQLI_USE_MYSQLND
  657. /* {{{ php_mysqli_stmt_copy_it */
  658. static void
  659. php_mysqli_stmt_copy_it(zval *** copies, zval *original, uint param_count, uint current)
  660. {
  661. if (!*copies) {
  662. *copies = ecalloc(param_count, sizeof(zval *));
  663. }
  664. MAKE_STD_ZVAL((*copies)[current]);
  665. *(*copies)[current] = *original;
  666. Z_SET_REFCOUNT_P((*copies)[current], 1);
  667. zval_copy_ctor((*copies)[current]);
  668. }
  669. /* }}} */
  670. #endif
  671. /* {{{ proto bool mysqli_stmt_execute(object stmt)
  672. Execute a prepared statement */
  673. PHP_FUNCTION(mysqli_stmt_execute)
  674. {
  675. MY_STMT *stmt;
  676. zval *mysql_stmt;
  677. #ifndef MYSQLI_USE_MYSQLND
  678. unsigned int i;
  679. zval **copies = NULL;
  680. #endif
  681. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  682. return;
  683. }
  684. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  685. #ifndef MYSQLI_USE_MYSQLND
  686. if (stmt->param.var_cnt) {
  687. int j;
  688. for (i = 0; i < stmt->param.var_cnt; i++) {
  689. for (j = i + 1; j < stmt->param.var_cnt; j++) {
  690. /* Oops, someone binding the same variable - clone */
  691. if (stmt->param.vars[j] == stmt->param.vars[i] && stmt->param.vars[i]) {
  692. php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
  693. break;
  694. }
  695. }
  696. }
  697. }
  698. for (i = 0; i < stmt->param.var_cnt; i++) {
  699. if (stmt->param.vars[i]) {
  700. if ( !(stmt->param.is_null[i] = (stmt->param.vars[i]->type == IS_NULL)) ) {
  701. zval *the_var = copies && copies[i]? copies[i]:stmt->param.vars[i];
  702. switch (stmt->stmt->params[i].buffer_type) {
  703. case MYSQL_TYPE_VAR_STRING:
  704. if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_STRING) {
  705. php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
  706. the_var = copies[i];
  707. }
  708. convert_to_string_ex(&the_var);
  709. stmt->stmt->params[i].buffer = Z_STRVAL_P(the_var);
  710. stmt->stmt->params[i].buffer_length = Z_STRLEN_P(the_var);
  711. break;
  712. case MYSQL_TYPE_DOUBLE:
  713. if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_DOUBLE) {
  714. php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
  715. the_var = copies[i];
  716. }
  717. convert_to_double_ex(&the_var);
  718. stmt->stmt->params[i].buffer = &Z_DVAL_P(the_var);
  719. break;
  720. case MYSQL_TYPE_LONGLONG:
  721. case MYSQL_TYPE_LONG:
  722. if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_LONG) {
  723. php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
  724. the_var = copies[i];
  725. }
  726. convert_to_long_ex(&the_var);
  727. stmt->stmt->params[i].buffer = &Z_LVAL_P(the_var);
  728. break;
  729. default:
  730. break;
  731. }
  732. }
  733. }
  734. }
  735. #endif
  736. if (mysql_stmt_execute(stmt->stmt)) {
  737. MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
  738. RETVAL_FALSE;
  739. } else {
  740. RETVAL_TRUE;
  741. }
  742. #ifndef MYSQLI_USE_MYSQLND
  743. if (copies) {
  744. for (i = 0; i < stmt->param.var_cnt; i++) {
  745. if (copies[i]) {
  746. zval_ptr_dtor(&copies[i]);
  747. }
  748. }
  749. efree(copies);
  750. }
  751. #endif
  752. if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
  753. php_mysqli_report_index(stmt->query, mysqli_stmt_server_status(stmt->stmt) TSRMLS_CC);
  754. }
  755. }
  756. /* }}} */
  757. #ifndef MYSQLI_USE_MYSQLND
  758. /* {{{ void mysqli_stmt_fetch_libmysql
  759. Fetch results from a prepared statement into the bound variables */
  760. void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
  761. {
  762. MY_STMT *stmt;
  763. zval *mysql_stmt;
  764. unsigned int i;
  765. ulong ret;
  766. unsigned int uval;
  767. my_ulonglong llval;
  768. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  769. return;
  770. }
  771. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  772. /* reset buffers */
  773. for (i = 0; i < stmt->result.var_cnt; i++) {
  774. if (stmt->result.buf[i].type == IS_STRING) {
  775. memset(stmt->result.buf[i].val, 0, stmt->result.buf[i].buflen);
  776. }
  777. }
  778. ret = mysql_stmt_fetch(stmt->stmt);
  779. #ifdef MYSQL_DATA_TRUNCATED
  780. if (!ret || ret == MYSQL_DATA_TRUNCATED) {
  781. #else
  782. if (!ret) {
  783. #endif
  784. for (i = 0; i < stmt->result.var_cnt; i++) {
  785. /*
  786. QQ: Isn't it quite better to call zval_dtor(). What if the user has
  787. assigned a resource, or an array to the bound variable? We are going
  788. to leak probably. zval_dtor() will handle also Unicode/Non-unicode mode.
  789. */
  790. /* Even if the string is of length zero there is one byte alloced so efree() in all cases */
  791. if (Z_TYPE_P(stmt->result.vars[i]) == IS_STRING) {
  792. efree(stmt->result.vars[i]->value.str.val);
  793. }
  794. if (!stmt->result.is_null[i]) {
  795. switch (stmt->result.buf[i].type) {
  796. case IS_LONG:
  797. if ((stmt->stmt->fields[i].type == MYSQL_TYPE_LONG)
  798. && (stmt->stmt->fields[i].flags & UNSIGNED_FLAG))
  799. {
  800. /* unsigned int (11) */
  801. uval= *(unsigned int *) stmt->result.buf[i].val;
  802. #if SIZEOF_LONG==4
  803. if (uval > INT_MAX) {
  804. char *tmp, *p;
  805. int j=10;
  806. tmp= emalloc(11);
  807. p= &tmp[9];
  808. do {
  809. *p-- = (uval % 10) + 48;
  810. uval = uval / 10;
  811. } while (--j > 0);
  812. tmp[10]= '\0';
  813. /* unsigned int > INT_MAX is 10 digits - ALWAYS */
  814. ZVAL_STRINGL(stmt->result.vars[i], tmp, 10, 0);
  815. break;
  816. }
  817. #endif
  818. }
  819. if (stmt->stmt->fields[i].flags & UNSIGNED_FLAG) {
  820. ZVAL_LONG(stmt->result.vars[i], *(unsigned int *)stmt->result.buf[i].val);
  821. } else {
  822. ZVAL_LONG(stmt->result.vars[i], *(int *)stmt->result.buf[i].val);
  823. }
  824. break;
  825. case IS_DOUBLE:
  826. ZVAL_DOUBLE(stmt->result.vars[i], *(double *)stmt->result.buf[i].val);
  827. break;
  828. case IS_STRING:
  829. if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG
  830. #if MYSQL_VERSION_ID > 50002
  831. || stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT
  832. #endif
  833. ) {
  834. my_bool uns= (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? 1:0;
  835. #if MYSQL_VERSION_ID > 50002
  836. if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) {
  837. switch (stmt->result.buf[i].output_len) {
  838. case 8:llval = (my_ulonglong) bit_uint8korr(stmt->result.buf[i].val);break;
  839. case 7:llval = (my_ulonglong) bit_uint7korr(stmt->result.buf[i].val);break;
  840. case 6:llval = (my_ulonglong) bit_uint6korr(stmt->result.buf[i].val);break;
  841. case 5:llval = (my_ulonglong) bit_uint5korr(stmt->result.buf[i].val);break;
  842. case 4:llval = (my_ulonglong) bit_uint4korr(stmt->result.buf[i].val);break;
  843. case 3:llval = (my_ulonglong) bit_uint3korr(stmt->result.buf[i].val);break;
  844. case 2:llval = (my_ulonglong) bit_uint2korr(stmt->result.buf[i].val);break;
  845. case 1:llval = (my_ulonglong) uint1korr(stmt->result.buf[i].val);break;
  846. }
  847. } else
  848. #endif
  849. {
  850. llval= *(my_ulonglong *) stmt->result.buf[i].val;
  851. }
  852. #if SIZEOF_LONG==8
  853. if (uns && llval > 9223372036854775807L) {
  854. #elif SIZEOF_LONG==4
  855. if ((uns && llval > L64(2147483647)) ||
  856. (!uns && (( L64(2147483647) < (my_longlong) llval) ||
  857. (L64(-2147483648) > (my_longlong) llval))))
  858. {
  859. #endif
  860. char tmp[22];
  861. /* even though lval is declared as unsigned, the value
  862. * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must
  863. * use MYSQLI_LL_SPEC.
  864. */
  865. snprintf(tmp, sizeof(tmp), (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
  866. ZVAL_STRING(stmt->result.vars[i], tmp, 1);
  867. } else {
  868. ZVAL_LONG(stmt->result.vars[i], llval);
  869. }
  870. } else {
  871. #if defined(MYSQL_DATA_TRUNCATED) && MYSQL_VERSION_ID > 50002
  872. if (ret == MYSQL_DATA_TRUNCATED && *(stmt->stmt->bind[i].error) != 0) {
  873. /* result was truncated */
  874. ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
  875. stmt->stmt->bind[i].buffer_length, 1);
  876. } else {
  877. #else
  878. {
  879. #endif
  880. ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
  881. stmt->result.buf[i].output_len, 1);
  882. }
  883. }
  884. break;
  885. default:
  886. break;
  887. }
  888. } else {
  889. ZVAL_NULL(stmt->result.vars[i]);
  890. }
  891. }
  892. } else {
  893. MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
  894. }
  895. switch (ret) {
  896. case 0:
  897. #ifdef MYSQL_DATA_TRUNCATED
  898. /* according to SQL standard truncation (e.g. loss of precision is
  899. not an error) - for detecting possible truncation you have to
  900. check mysqli_stmt_warning
  901. */
  902. case MYSQL_DATA_TRUNCATED:
  903. #endif
  904. RETURN_TRUE;
  905. break;
  906. case 1:
  907. RETURN_FALSE;
  908. break;
  909. default:
  910. RETURN_NULL();
  911. break;
  912. }
  913. }
  914. /* }}} */
  915. #else
  916. /* {{{ mixed mysqli_stmt_fetch_mysqlnd */
  917. void mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAMETERS)
  918. {
  919. MY_STMT *stmt;
  920. zval *mysql_stmt;
  921. zend_bool fetched_anything;
  922. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  923. return;
  924. }
  925. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  926. if (FAIL == mysqlnd_stmt_fetch(stmt->stmt, &fetched_anything)) {
  927. RETURN_BOOL(FALSE);
  928. } else if (fetched_anything == TRUE) {
  929. RETURN_BOOL(TRUE);
  930. } else {
  931. RETURN_NULL();
  932. }
  933. }
  934. #endif
  935. /* }}} */
  936. /* {{{ proto mixed mysqli_stmt_fetch(object stmt) U
  937. Fetch results from a prepared statement into the bound variables */
  938. PHP_FUNCTION(mysqli_stmt_fetch)
  939. {
  940. #if !defined(MYSQLI_USE_MYSQLND)
  941. mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  942. #else
  943. mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  944. #endif
  945. }
  946. /* }}} */
  947. /* {{{ php_add_field_properties */
  948. static void php_add_field_properties(zval *value, const MYSQL_FIELD *field TSRMLS_DC)
  949. {
  950. add_property_string(value, "name", (char *) (field->name ? field->name : ""), 1);
  951. add_property_string(value, "orgname", (char *) (field->org_name ? field->org_name : ""), 1);
  952. add_property_string(value, "table", (char *) (field->table ? field->table : ""), 1);
  953. add_property_string(value, "orgtable", (char *) (field->org_table ? field->org_table : ""), 1);
  954. add_property_string(value, "def", (field->def ? field->def : ""), 1);
  955. add_property_string(value, "db", (field->db ? field->db : ""), 1);
  956. add_property_string(value, "catalog", (field->catalog ? field->catalog : ""), 1);
  957. add_property_long(value, "max_length", field->max_length);
  958. add_property_long(value, "length", field->length);
  959. add_property_long(value, "charsetnr", field->charsetnr);
  960. add_property_long(value, "flags", field->flags);
  961. add_property_long(value, "type", field->type);
  962. add_property_long(value, "decimals", field->decimals);
  963. }
  964. /* }}} */
  965. /* {{{ proto mixed mysqli_fetch_field (object result)
  966. Get column information from a result and return as an object */
  967. PHP_FUNCTION(mysqli_fetch_field)
  968. {
  969. MYSQL_RES *result;
  970. zval *mysql_result;
  971. const MYSQL_FIELD *field;
  972. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  973. return;
  974. }
  975. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  976. if (!(field = mysql_fetch_field(result))) {
  977. RETURN_FALSE;
  978. }
  979. object_init(return_value);
  980. php_add_field_properties(return_value, field TSRMLS_CC);
  981. }
  982. /* }}} */
  983. /* {{{ proto mixed mysqli_fetch_fields (object result)
  984. Return array of objects containing field meta-data */
  985. PHP_FUNCTION(mysqli_fetch_fields)
  986. {
  987. MYSQL_RES *result;
  988. zval *mysql_result;
  989. zval *obj;
  990. unsigned int i;
  991. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  992. return;
  993. }
  994. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  995. array_init(return_value);
  996. for (i = 0; i < mysql_num_fields(result); i++) {
  997. const MYSQL_FIELD *field = mysql_fetch_field_direct(result, i);
  998. MAKE_STD_ZVAL(obj);
  999. object_init(obj);
  1000. php_add_field_properties(obj, field TSRMLS_CC);
  1001. add_index_zval(return_value, i, obj);
  1002. }
  1003. }
  1004. /* }}} */
  1005. /* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset)
  1006. Fetch meta-data for a single field */
  1007. PHP_FUNCTION(mysqli_fetch_field_direct)
  1008. {
  1009. MYSQL_RES *result;
  1010. zval *mysql_result;
  1011. const MYSQL_FIELD *field;
  1012. long offset;
  1013. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
  1014. return;
  1015. }
  1016. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1017. if (offset < 0 || offset >= (long) mysql_num_fields(result)) {
  1018. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field offset is invalid for resultset");
  1019. RETURN_FALSE;
  1020. }
  1021. if (!(field = mysql_fetch_field_direct(result,offset))) {
  1022. RETURN_FALSE;
  1023. }
  1024. object_init(return_value);
  1025. php_add_field_properties(return_value, field TSRMLS_CC);
  1026. }
  1027. /* }}} */
  1028. /* {{{ proto mixed mysqli_fetch_lengths (object result)
  1029. Get the length of each output in a result */
  1030. PHP_FUNCTION(mysqli_fetch_lengths)
  1031. {
  1032. MYSQL_RES *result;
  1033. zval *mysql_result;
  1034. unsigned int i;
  1035. unsigned long *ret;
  1036. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  1037. return;
  1038. }
  1039. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1040. if (!(ret = mysql_fetch_lengths(result))) {
  1041. RETURN_FALSE;
  1042. }
  1043. array_init(return_value);
  1044. for (i = 0; i < mysql_num_fields(result); i++) {
  1045. add_index_long(return_value, i, ret[i]);
  1046. }
  1047. }
  1048. /* }}} */
  1049. /* {{{ proto array mysqli_fetch_row (object result)
  1050. Get a result row as an enumerated array */
  1051. PHP_FUNCTION(mysqli_fetch_row)
  1052. {
  1053. php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM, 0);
  1054. }
  1055. /* }}} */
  1056. /* {{{ proto int mysqli_field_count(object link)
  1057. Fetch the number of fields returned by the last query for the given link
  1058. */
  1059. PHP_FUNCTION(mysqli_field_count)
  1060. {
  1061. MY_MYSQL *mysql;
  1062. zval *mysql_link;
  1063. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1064. return;
  1065. }
  1066. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1067. RETURN_LONG(mysql_field_count(mysql->mysql));
  1068. }
  1069. /* }}} */
  1070. /* {{{ proto int mysqli_field_seek(object result, int fieldnr)
  1071. Set result pointer to a specified field offset
  1072. */
  1073. PHP_FUNCTION(mysqli_field_seek)
  1074. {
  1075. MYSQL_RES *result;
  1076. zval *mysql_result;
  1077. unsigned long fieldnr;
  1078. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &fieldnr) == FAILURE) {
  1079. return;
  1080. }
  1081. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1082. if (fieldnr < 0 || fieldnr >= mysql_num_fields(result)) {
  1083. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid field offset");
  1084. RETURN_FALSE;
  1085. }
  1086. mysql_field_seek(result, fieldnr);
  1087. RETURN_TRUE;
  1088. }
  1089. /* }}} */
  1090. /* {{{ proto int mysqli_field_tell(object result)
  1091. Get current field offset of result pointer */
  1092. PHP_FUNCTION(mysqli_field_tell)
  1093. {
  1094. MYSQL_RES *result;
  1095. zval *mysql_result;
  1096. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  1097. return;
  1098. }
  1099. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1100. RETURN_LONG(mysql_field_tell(result));
  1101. }
  1102. /* }}} */
  1103. /* {{{ proto void mysqli_free_result(object result)
  1104. Free query result memory for the given result handle */
  1105. PHP_FUNCTION(mysqli_free_result)
  1106. {
  1107. MYSQL_RES *result;
  1108. zval *mysql_result;
  1109. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  1110. return;
  1111. }
  1112. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1113. mysqli_free_result(result, FALSE);
  1114. MYSQLI_CLEAR_RESOURCE(&mysql_result);
  1115. }
  1116. /* }}} */
  1117. /* {{{ proto string mysqli_get_client_info(void)
  1118. Get MySQL client info */
  1119. PHP_FUNCTION(mysqli_get_client_info)
  1120. {
  1121. RETURN_STRING((char *)mysql_get_client_info(), 1);
  1122. }
  1123. /* }}} */
  1124. /* {{{ proto int mysqli_get_client_version(void)
  1125. Get MySQL client info */
  1126. PHP_FUNCTION(mysqli_get_client_version)
  1127. {
  1128. RETURN_LONG((long)mysql_get_client_version());
  1129. }
  1130. /* }}} */
  1131. /* {{{ proto string mysqli_get_host_info (object link)
  1132. Get MySQL host info */
  1133. PHP_FUNCTION(mysqli_get_host_info)
  1134. {
  1135. MY_MYSQL *mysql;
  1136. zval *mysql_link = NULL;
  1137. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1138. return;
  1139. }
  1140. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1141. RETURN_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "", 1);
  1142. }
  1143. /* }}} */
  1144. /* {{{ proto int mysqli_get_proto_info(object link)
  1145. Get MySQL protocol information */
  1146. PHP_FUNCTION(mysqli_get_proto_info)
  1147. {
  1148. MY_MYSQL *mysql;
  1149. zval *mysql_link = NULL;
  1150. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1151. return;
  1152. }
  1153. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1154. RETURN_LONG(mysql_get_proto_info(mysql->mysql));
  1155. }
  1156. /* }}} */
  1157. /* {{{ proto string mysqli_get_server_info(object link)
  1158. Get MySQL server info */
  1159. PHP_FUNCTION(mysqli_get_server_info)
  1160. {
  1161. MY_MYSQL *mysql;
  1162. zval *mysql_link = NULL;
  1163. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1164. return;
  1165. }
  1166. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1167. RETURN_STRING((char *)mysql_get_server_info(mysql->mysql), 1);
  1168. }
  1169. /* }}} */
  1170. /* {{{ proto int mysqli_get_server_version(object link)
  1171. Return the MySQL version for the server referenced by the given link */
  1172. PHP_FUNCTION(mysqli_get_server_version)
  1173. {
  1174. MY_MYSQL *mysql;
  1175. zval *mysql_link = NULL;
  1176. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1177. return;
  1178. }
  1179. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1180. RETURN_LONG(mysql_get_server_version(mysql->mysql));
  1181. }
  1182. /* }}} */
  1183. /* {{{ proto string mysqli_info(object link)
  1184. Get information about the most recent query */
  1185. PHP_FUNCTION(mysqli_info)
  1186. {
  1187. MY_MYSQL *mysql;
  1188. zval *mysql_link = NULL;
  1189. const char *info;
  1190. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1191. return;
  1192. }
  1193. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1194. info = mysql_info(mysql->mysql);
  1195. RETURN_STRING((info) ? (char *)info : "", 1);
  1196. }
  1197. /* }}} */
  1198. /* {{{ php_mysqli_init() */
  1199. void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS)
  1200. {
  1201. MYSQLI_RESOURCE *mysqli_resource;
  1202. MY_MYSQL *mysql;
  1203. if (getThis() && ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr) {
  1204. return;
  1205. }
  1206. mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL));
  1207. #if !defined(MYSQLI_USE_MYSQLND)
  1208. if (!(mysql->mysql = mysql_init(NULL)))
  1209. #else
  1210. /*
  1211. We create always persistent, as if the user want to connecto
  1212. to p:somehost, we can't convert the handle then
  1213. */
  1214. if (!(mysql->mysql = mysql_init(TRUE)))
  1215. #endif
  1216. {
  1217. efree(mysql);
  1218. RETURN_FALSE;
  1219. }
  1220. mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
  1221. mysqli_resource->ptr = (void *)mysql;
  1222. mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
  1223. if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_link_class_entry TSRMLS_CC)) {
  1224. MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
  1225. } else {
  1226. ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
  1227. }
  1228. }
  1229. /* }}} */
  1230. /* {{{ proto resource mysqli_init(void)
  1231. Initialize mysqli and return a resource for use with mysql_real_connect */
  1232. PHP_FUNCTION(mysqli_init)
  1233. {
  1234. php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
  1235. }
  1236. /* }}} */
  1237. /* {{{ proto mixed mysqli_insert_id(object link)
  1238. Get the ID generated from the previous INSERT operation */
  1239. PHP_FUNCTION(mysqli_insert_id)
  1240. {
  1241. MY_MYSQL *mysql;
  1242. my_ulonglong rc;
  1243. zval *mysql_link;
  1244. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1245. return;
  1246. }
  1247. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1248. rc = mysql_insert_id(mysql->mysql);
  1249. MYSQLI_RETURN_LONG_LONG(rc)
  1250. }
  1251. /* }}} */
  1252. /* {{{ proto bool mysqli_kill(object link, int processid)
  1253. Kill a mysql process on the server */
  1254. PHP_FUNCTION(mysqli_kill)
  1255. {
  1256. MY_MYSQL *mysql;
  1257. zval *mysql_link;
  1258. long processid;
  1259. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &processid) == FAILURE) {
  1260. return;
  1261. }
  1262. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1263. if (processid <= 0) {
  1264. php_error_docref(NULL TSRMLS_CC, E_WARNING, "processid should have positive value");
  1265. RETURN_FALSE;
  1266. }
  1267. if (mysql_kill(mysql->mysql, processid)) {
  1268. MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
  1269. RETURN_FALSE;
  1270. }
  1271. RETURN_TRUE;
  1272. }
  1273. /* }}} */
  1274. /* {{{ proto void mysqli_set_local_infile_default(object link)
  1275. unsets user defined handler for load local infile command */
  1276. #if !defined(MYSQLI_USE_MYSQLND)
  1277. PHP_FUNCTION(mysqli_set_local_infile_default)
  1278. {
  1279. MY_MYSQL *mysql;
  1280. zval *mysql_link;
  1281. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1282. return;
  1283. }
  1284. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1285. if (mysql->li_read) {
  1286. zval_ptr_dtor(&(mysql->li_read));
  1287. mysql->li_read = NULL;
  1288. }
  1289. }
  1290. /* }}} */
  1291. /* {{{ proto bool mysqli_set_local_infile_handler(object link, callback read_func)
  1292. Set callback functions for LOAD DATA LOCAL INFILE */
  1293. PHP_FUNCTION(mysqli_set_local_infile_handler)
  1294. {
  1295. MY_MYSQL *mysql;
  1296. zval *mysql_link;
  1297. char *callback_name;
  1298. zval *callback_func;
  1299. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &mysql_link, mysqli_link_class_entry,
  1300. &callback_func) == FAILURE) {
  1301. return;
  1302. }
  1303. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1304. /* check callback function */
  1305. if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
  1306. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a valid callback function %s", callback_name);
  1307. efree(callback_name);
  1308. RETURN_FALSE;
  1309. }
  1310. efree(callback_name);
  1311. /* save callback function */
  1312. if (!mysql->li_read) {
  1313. MAKE_STD_ZVAL(mysql->li_read);
  1314. } else {
  1315. zval_dtor(mysql->li_read);
  1316. }
  1317. ZVAL_ZVAL(mysql->li_read, callback_func, 1, 0);
  1318. RETURN_TRUE;
  1319. }
  1320. #endif
  1321. /* }}} */
  1322. /* {{{ proto bool mysqli_more_results(object link)
  1323. check if there any more query results from a multi query */
  1324. PHP_FUNCTION(mysqli_more_results)
  1325. {
  1326. MY_MYSQL *mysql;
  1327. zval *mysql_link;
  1328. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1329. return;
  1330. }
  1331. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1332. RETURN_BOOL(mysql_more_results(mysql->mysql));
  1333. }
  1334. /* }}} */
  1335. /* {{{ proto bool mysqli_next_result(object link)
  1336. read next result from multi_query */
  1337. PHP_FUNCTION(mysqli_next_result) {
  1338. MY_MYSQL *mysql;
  1339. zval *mysql_link;
  1340. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
  1341. return;
  1342. }
  1343. MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
  1344. if (!mysql_more_results(mysql->mysql)) {
  1345. php_error_docref(NULL TSRMLS_CC, E_STRICT, "There is no next result set. "
  1346. "Please, call mysqli_more_results()/mysqli::more_results() to check "
  1347. "whether to call this function/method");
  1348. }
  1349. RETURN_BOOL(!mysql_next_result(mysql->mysql));
  1350. }
  1351. /* }}} */
  1352. #if defined(HAVE_STMT_NEXT_RESULT) && defined(MYSQLI_USE_MYSQLND)
  1353. /* {{{ proto bool mysqli_stmt_next_result(object link)
  1354. check if there any more query results from a multi query */
  1355. PHP_FUNCTION(mysqli_stmt_more_results)
  1356. {
  1357. MY_STMT *stmt;
  1358. zval *mysql_stmt;
  1359. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  1360. return;
  1361. }
  1362. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  1363. RETURN_BOOL(mysqlnd_stmt_more_results(stmt->stmt));
  1364. }
  1365. /* }}} */
  1366. /* {{{ proto bool mysqli_stmt_next_result(object link)
  1367. read next result from multi_query */
  1368. PHP_FUNCTION(mysqli_stmt_next_result) {
  1369. MY_STMT *stmt;
  1370. zval *mysql_stmt;
  1371. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
  1372. return;
  1373. }
  1374. MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
  1375. if (!mysqlnd_stmt_more_results(stmt->stmt)) {
  1376. php_error_docref(NULL TSRMLS_CC, E_STRICT, "There is no next result set. "
  1377. "Please, call mysqli_stmt_more_results()/mysqli_stmt::more_results() to check "
  1378. "whether to call this function/method");
  1379. }
  1380. RETURN_BOOL(!mysql_stmt_next_result(stmt->stmt));
  1381. }
  1382. /* }}} */
  1383. #endif
  1384. /* {{{ proto int mysqli_num_fields(object result)
  1385. Get number of fields in result */
  1386. PHP_FUNCTION(mysqli_num_fields)
  1387. {
  1388. MYSQL_RES *result;
  1389. zval *mysql_result;
  1390. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  1391. return;
  1392. }
  1393. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1394. RETURN_LONG(mysql_num_fields(result));
  1395. }
  1396. /* }}} */
  1397. /* {{{ proto mixed mysqli_num_rows(object result)
  1398. Get number of rows in result */
  1399. PHP_FUNCTION(mysqli_num_rows)
  1400. {
  1401. MYSQL_RES *result;
  1402. zval *mysql_result;
  1403. if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
  1404. return;
  1405. }
  1406. MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
  1407. if (mysqli_result_is_unbuffered(result)) {
  1408. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
  1409. RETURN_LONG(0);
  1410. }
  1411. MYSQLI_RETURN_LONG_LONG(mysql_num_rows(result));
  1412. }
  1413. /* }}} */
  1414. /* {{{ mysqli_options_get_option_zval_type */
  1415. static int mysqli_options_get_option_zval_type(int option)
  1416. {
  1417. switch (option) {
  1418. #ifdef MYSQLI_USE_MYSQLND
  1419. #if PHP_MAJOR_VERSION >= 6
  1420. case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE:
  1421. #endif
  1422. case MYSQLND_OPT_NET_CMD_BUFFER_SIZE:
  1423. case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
  1424. #ifdef MYSQLND_STRING_TO_INT_CONVERSION
  1425. case MYSQLND_OPT_INT_AND_FLOAT_NATIVE:
  1426. #endif
  1427. #endif /* MYSQLI_USE_MYSQLND */
  1428. case MYSQL_OPT_CONNECT_TIMEOUT:
  1429. #ifdef MYSQL_REPORT_DATA_TRUNCATION
  1430. case MYSQL_REPORT_DATA_TRUNCATION:
  1431. #endif
  1432. case MYSQL_OPT_LOCAL_INFILE:
  1433. case MYSQL_OPT_NAMED_PIPE:
  1434. #ifdef MYSQL_OPT_PROTOCOL
  1435. case MYSQL_OPT_PROTOCOL:
  1436. #endif /* MySQL 4.1.0 */
  1437. #ifdef MYSQL_OPT_READ_TIMEOUT
  1438. case MYSQL_OPT_READ_TIMEOUT:
  1439. case MYSQL_OPT_WRITE_TIMEOUT:
  1440. case MYSQL_OPT_GUESS_CONNECTION:
  1441. case MYSQL_OPT_USE_EMBEDDED_CONNECTION:
  1442. case MYSQL_OPT_USE_REMOTE_CONNECTION:
  1443. case MYSQL_SECURE_AUTH:
  1444. #endif /* MySQL 4.1.1 */
  1445. #ifdef MYSQL_OPT_RECONNECT
  1446. case MYSQL_OPT_RECONNECT:
  1447. #endif /* MySQL 5.0.13 */
  1448. #ifdef MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  1449. case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
  1450. #endif /* MySQL 5.0.23 */
  1451. #ifdef MYSQL_OPT_COMPRESS
  1452. case MYSQL_OPT_COMPRESS:
  1453. #endif /* mysqlnd @ PHP 5.3.2 */
  1454. #ifdef MYSQL_OPT_SSL_VERIFY_SERVER_CERT
  1455. REGISTER_LONG_CONSTANT("MYSQLI_OPT_SSL_VERIFY_SERVER_CERT", MYSQL_OPT_SSL_VERIFY_SERVER_CERT, CONST_CS | CONST_PERSISTENT);
  1456. #endif /* MySQL 5.1.1., mysqlnd @ PHP 5.3.3 */
  1457. return IS_LONG;
  1458. #ifdef MYSQL_SHARED_MEMORY_BASE_NAME
  1459. case MYSQL_SHARED_MEMORY_BASE_NAME:
  1460. #endif /* MySQL 4.1.0 */
  1461. #ifdef MYSQL_SET_

Large files files are truncated, but you can click here to view the full file