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

/ext/mysqli/mysqli_api.c

http://github.com/php/php-src
C | 2682 lines | 1980 code | 343 blank | 359 comment | 411 complexity | ddb9c18e27360cd1ae1fc9f624d21b54 MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1

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

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

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