DBIMysqli.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Interface to the improved MySQL extension (MySQLi)
  5. *
  6. * @package PhpMyAdmin-DBI
  7. * @subpackage MySQLi
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. require_once './libraries/logging.lib.php';
  13. require_once './libraries/dbi/DBIExtension.int.php';
  14. /**
  15. * MySQL client API
  16. */
  17. if (!defined('PMA_MYSQL_CLIENT_API')) {
  18. $client_api = explode('.', mysqli_get_client_info());
  19. define(
  20. 'PMA_MYSQL_CLIENT_API',
  21. (int)sprintf(
  22. '%d%02d%02d',
  23. $client_api[0], $client_api[1], intval($client_api[2])
  24. )
  25. );
  26. unset($client_api);
  27. }
  28. /**
  29. * some PHP versions are reporting extra messages like "No index used in query"
  30. */
  31. mysqli_report(MYSQLI_REPORT_OFF);
  32. /**
  33. * some older mysql client libs are missing these constants ...
  34. */
  35. if (! defined('MYSQLI_BINARY_FLAG')) {
  36. define('MYSQLI_BINARY_FLAG', 128);
  37. }
  38. /**
  39. * @see http://bugs.php.net/36007
  40. */
  41. if (! defined('MYSQLI_TYPE_NEWDECIMAL')) {
  42. define('MYSQLI_TYPE_NEWDECIMAL', 246);
  43. }
  44. if (! defined('MYSQLI_TYPE_BIT')) {
  45. define('MYSQLI_TYPE_BIT', 16);
  46. }
  47. // for Drizzle
  48. if (! defined('MYSQLI_TYPE_VARCHAR')) {
  49. define('MYSQLI_TYPE_VARCHAR', 15);
  50. }
  51. /* vim: set expandtab sw=4 ts=4 sts=4: */
  52. /**
  53. * Interface to the improved MySQL extension (MySQLi)
  54. *
  55. * @package PhpMyAdmin-DBI
  56. * @subpackage MySQLi
  57. */
  58. class PMA_DBI_Mysqli implements PMA_DBI_Extension
  59. {
  60. /**
  61. * Helper function for connecting to the database server
  62. *
  63. * @param mysqli $link connection link
  64. * @param string $host mysql hostname
  65. * @param string $user mysql user name
  66. * @param string $password mysql user password
  67. * @param string $dbname database name
  68. * @param int $server_port server port
  69. * @param string $server_socket server socket
  70. * @param int $client_flags client flags of connection
  71. * @param bool $persistent whether to use peristent connection
  72. *
  73. * @return bool
  74. */
  75. private function _realConnect(
  76. $link, $host, $user, $password, $dbname, $server_port,
  77. $server_socket, $client_flags = null, $persistent = false
  78. ) {
  79. global $cfg;
  80. // mysqli persistent connections
  81. if ($cfg['PersistentConnections'] || $persistent) {
  82. $host = 'p:' . $host;
  83. }
  84. if ($client_flags === null) {
  85. return @mysqli_real_connect(
  86. $link,
  87. $host,
  88. $user,
  89. $password,
  90. $dbname,
  91. $server_port,
  92. $server_socket
  93. );
  94. } else {
  95. return @mysqli_real_connect(
  96. $link,
  97. $host,
  98. $user,
  99. $password,
  100. $dbname,
  101. $server_port,
  102. $server_socket,
  103. $client_flags
  104. );
  105. }
  106. }
  107. /**
  108. * connects to the database server
  109. *
  110. * @param string $user mysql user name
  111. * @param string $password mysql user password
  112. * @param bool $is_controluser whether this is a control user connection
  113. * @param array $server host/port/socket/persistent
  114. * @param bool $auxiliary_connection (when true, don't go back to login if
  115. * connection fails)
  116. *
  117. * @return mixed false on error or a mysqli object on success
  118. */
  119. public function connect(
  120. $user, $password, $is_controluser = false, $server = null,
  121. $auxiliary_connection = false
  122. ) {
  123. global $cfg;
  124. if ($server) {
  125. $server_port = (empty($server['port']))
  126. ? null
  127. : (int)$server['port'];
  128. $server_socket = (empty($server['socket']))
  129. ? ''
  130. : $server['socket'];
  131. $server['host'] = (empty($server['host']))
  132. ? 'localhost'
  133. : $server['host'];
  134. } else {
  135. $server_port = (empty($cfg['Server']['port']))
  136. ? null
  137. : (int) $cfg['Server']['port'];
  138. $server_socket = (empty($cfg['Server']['socket']))
  139. ? null
  140. : $cfg['Server']['socket'];
  141. }
  142. // NULL enables connection to the default socket
  143. $link = mysqli_init();
  144. mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
  145. $client_flags = 0;
  146. /* Optionally compress connection */
  147. if ($cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
  148. $client_flags |= MYSQLI_CLIENT_COMPRESS;
  149. }
  150. /* Optionally enable SSL */
  151. if ($cfg['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) {
  152. mysqli_ssl_set(
  153. $link,
  154. $cfg['Server']['ssl_key'],
  155. $cfg['Server']['ssl_cert'],
  156. $cfg['Server']['ssl_ca'],
  157. $cfg['Server']['ssl_ca_path'],
  158. $cfg['Server']['ssl_ciphers']
  159. );
  160. $client_flags |= MYSQLI_CLIENT_SSL;
  161. }
  162. if (! $server) {
  163. $return_value = @$this->_realConnect(
  164. $link,
  165. $cfg['Server']['host'],
  166. $user,
  167. $password,
  168. false,
  169. $server_port,
  170. $server_socket,
  171. $client_flags
  172. );
  173. // Retry with empty password if we're allowed to
  174. if ($return_value == false
  175. && isset($cfg['Server']['nopassword'])
  176. && $cfg['Server']['nopassword']
  177. && ! $is_controluser
  178. ) {
  179. $return_value = @$this->_realConnect(
  180. $link,
  181. $cfg['Server']['host'],
  182. $user,
  183. '',
  184. false,
  185. $server_port,
  186. $server_socket,
  187. $client_flags
  188. );
  189. }
  190. } else {
  191. $return_value = @$this->_realConnect(
  192. $link,
  193. $server['host'],
  194. $user,
  195. $password,
  196. false,
  197. $server_port,
  198. $server_socket
  199. );
  200. }
  201. if ($return_value != false) {
  202. $GLOBALS['dbi']->postConnect($link, $is_controluser);
  203. return $link;
  204. }
  205. if ($is_controluser) {
  206. trigger_error(
  207. __(
  208. 'Connection for controluser as defined in your '
  209. . 'configuration failed.'
  210. ),
  211. E_USER_WARNING
  212. );
  213. return false;
  214. }
  215. // we could be calling $GLOBALS['dbi']->connect() to connect to another
  216. // server, for example in the Synchronize feature, so do not
  217. // go back to main login if it fails
  218. if ($auxiliary_connection) {
  219. return false;
  220. }
  221. PMA_logUser($user, 'mysql-denied');
  222. global $auth_plugin;
  223. $auth_plugin->authFails();
  224. return $link;
  225. }
  226. /**
  227. * selects given database
  228. *
  229. * @param string $dbname database name to select
  230. * @param mysqli $link the mysqli object
  231. *
  232. * @return boolean
  233. */
  234. public function selectDb($dbname, $link = null)
  235. {
  236. if (empty($link)) {
  237. if (isset($GLOBALS['userlink'])) {
  238. $link = $GLOBALS['userlink'];
  239. } else {
  240. return false;
  241. }
  242. }
  243. return mysqli_select_db($link, $dbname);
  244. }
  245. /**
  246. * runs a query and returns the result
  247. *
  248. * @param string $query query to execute
  249. * @param mysqli $link mysqli object
  250. * @param int $options query options
  251. *
  252. * @return mysqli_result|bool
  253. */
  254. public function realQuery($query, $link, $options)
  255. {
  256. if ($options == ($options | PMA_DatabaseInterface::QUERY_STORE)) {
  257. $method = MYSQLI_STORE_RESULT;
  258. } elseif ($options == ($options | PMA_DatabaseInterface::QUERY_UNBUFFERED)) {
  259. $method = MYSQLI_USE_RESULT;
  260. } else {
  261. $method = 0;
  262. }
  263. return mysqli_query($link, $query, $method);
  264. }
  265. /**
  266. * Run the multi query and output the results
  267. *
  268. * @param mysqli $link mysqli object
  269. * @param string $query multi query statement to execute
  270. *
  271. * @return mysqli_result collection | boolean(false)
  272. */
  273. public function realMultiQuery($link, $query)
  274. {
  275. return mysqli_multi_query($link, $query);
  276. }
  277. /**
  278. * returns array of rows with associative and numeric keys from $result
  279. *
  280. * @param mysqli_result $result result set identifier
  281. *
  282. * @return array
  283. */
  284. public function fetchArray($result)
  285. {
  286. return mysqli_fetch_array($result, MYSQLI_BOTH);
  287. }
  288. /**
  289. * returns array of rows with associative keys from $result
  290. *
  291. * @param mysqli_result $result result set identifier
  292. *
  293. * @return array
  294. */
  295. public function fetchAssoc($result)
  296. {
  297. return mysqli_fetch_array($result, MYSQLI_ASSOC);
  298. }
  299. /**
  300. * returns array of rows with numeric keys from $result
  301. *
  302. * @param mysqli_result $result result set identifier
  303. *
  304. * @return array
  305. */
  306. public function fetchRow($result)
  307. {
  308. return mysqli_fetch_array($result, MYSQLI_NUM);
  309. }
  310. /**
  311. * Adjusts the result pointer to an arbitrary row in the result
  312. *
  313. * @param resource $result database result
  314. * @param integer $offset offset to seek
  315. *
  316. * @return bool true on success, false on failure
  317. */
  318. public function dataSeek($result, $offset)
  319. {
  320. return mysqli_data_seek($result, $offset);
  321. }
  322. /**
  323. * Frees memory associated with the result
  324. *
  325. * @param mysqli_result $result database result
  326. *
  327. * @return void
  328. */
  329. public function freeResult($result)
  330. {
  331. if ($result instanceof mysqli_result) {
  332. mysqli_free_result($result);
  333. }
  334. }
  335. /**
  336. * Check if there are any more query results from a multi query
  337. *
  338. * @param mysqli $link the mysqli object
  339. *
  340. * @return bool true or false
  341. */
  342. public function moreResults($link = null)
  343. {
  344. if (empty($link)) {
  345. if (isset($GLOBALS['userlink'])) {
  346. $link = $GLOBALS['userlink'];
  347. } else {
  348. return false;
  349. }
  350. }
  351. return mysqli_more_results($link);
  352. }
  353. /**
  354. * Prepare next result from multi_query
  355. *
  356. * @param mysqli $link the mysqli object
  357. *
  358. * @return bool true or false
  359. */
  360. public function nextResult($link = null)
  361. {
  362. if (empty($link)) {
  363. if (isset($GLOBALS['userlink'])) {
  364. $link = $GLOBALS['userlink'];
  365. } else {
  366. return false;
  367. }
  368. }
  369. return mysqli_next_result($link);
  370. }
  371. /**
  372. * Store the result returned from multi query
  373. *
  374. * @return mixed false when empty results / result set when not empty
  375. */
  376. public function storeResult()
  377. {
  378. if (isset($GLOBALS['userlink'])) {
  379. $link = $GLOBALS['userlink'];
  380. } else {
  381. return false;
  382. }
  383. return mysqli_store_result($link);
  384. }
  385. /**
  386. * Returns a string representing the type of connection used
  387. *
  388. * @param resource $link mysql link
  389. *
  390. * @return string type of connection used
  391. */
  392. public function getHostInfo($link = null)
  393. {
  394. if (null === $link) {
  395. if (isset($GLOBALS['userlink'])) {
  396. $link = $GLOBALS['userlink'];
  397. } else {
  398. return false;
  399. }
  400. }
  401. return mysqli_get_host_info($link);
  402. }
  403. /**
  404. * Returns the version of the MySQL protocol used
  405. *
  406. * @param resource $link mysql link
  407. *
  408. * @return integer version of the MySQL protocol used
  409. */
  410. public function getProtoInfo($link = null)
  411. {
  412. if (null === $link) {
  413. if (isset($GLOBALS['userlink'])) {
  414. $link = $GLOBALS['userlink'];
  415. } else {
  416. return false;
  417. }
  418. }
  419. return mysqli_get_proto_info($link);
  420. }
  421. /**
  422. * returns a string that represents the client library version
  423. *
  424. * @return string MySQL client library version
  425. */
  426. public function getClientInfo()
  427. {
  428. return mysqli_get_client_info();
  429. }
  430. /**
  431. * returns last error message or false if no errors occurred
  432. *
  433. * @param resource $link mysql link
  434. *
  435. * @return string|bool $error or false
  436. */
  437. public function getError($link = null)
  438. {
  439. $GLOBALS['errno'] = 0;
  440. /* Treat false same as null because of controllink */
  441. if ($link === false) {
  442. $link = null;
  443. }
  444. if (null === $link && isset($GLOBALS['userlink'])) {
  445. $link =& $GLOBALS['userlink'];
  446. // Do not stop now. We still can get the error code
  447. // with mysqli_connect_errno()
  448. }
  449. if (null !== $link) {
  450. $error_number = mysqli_errno($link);
  451. $error_message = mysqli_error($link);
  452. } else {
  453. $error_number = mysqli_connect_errno();
  454. $error_message = mysqli_connect_error();
  455. }
  456. if (0 == $error_number) {
  457. return false;
  458. }
  459. // keep the error number for further check after
  460. // the call to getError()
  461. $GLOBALS['errno'] = $error_number;
  462. return $GLOBALS['dbi']->formatError($error_number, $error_message);
  463. }
  464. /**
  465. * returns the number of rows returned by last query
  466. *
  467. * @param mysqli_result $result result set identifier
  468. *
  469. * @return string|int
  470. */
  471. public function numRows($result)
  472. {
  473. // see the note for tryQuery();
  474. if (is_bool($result)) {
  475. return 0;
  476. }
  477. return @mysqli_num_rows($result);
  478. }
  479. /**
  480. * returns last inserted auto_increment id for given $link
  481. * or $GLOBALS['userlink']
  482. *
  483. * @param mysqli $link the mysqli object
  484. *
  485. * @return string|int
  486. */
  487. public function insertId($link = null)
  488. {
  489. if (empty($link)) {
  490. if (isset($GLOBALS['userlink'])) {
  491. $link = $GLOBALS['userlink'];
  492. } else {
  493. return false;
  494. }
  495. }
  496. // When no controluser is defined, using mysqli_insert_id($link)
  497. // does not always return the last insert id due to a mixup with
  498. // the tracking mechanism, but this works:
  499. return $GLOBALS['dbi']->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link);
  500. // Curiously, this problem does not happen with the mysql extension but
  501. // there is another problem with BIGINT primary keys so insertId()
  502. // in the mysql extension also uses this logic.
  503. }
  504. /**
  505. * returns the number of rows affected by last query
  506. *
  507. * @param mysqli $link the mysqli object
  508. * @param bool $get_from_cache whether to retrieve from cache
  509. *
  510. * @return string|int
  511. */
  512. public function affectedRows($link = null, $get_from_cache = true)
  513. {
  514. if (empty($link)) {
  515. if (isset($GLOBALS['userlink'])) {
  516. $link = $GLOBALS['userlink'];
  517. } else {
  518. return false;
  519. }
  520. }
  521. if ($get_from_cache) {
  522. return $GLOBALS['cached_affected_rows'];
  523. } else {
  524. return mysqli_affected_rows($link);
  525. }
  526. }
  527. /**
  528. * returns metainfo for fields in $result
  529. *
  530. * @param mysqli_result $result result set identifier
  531. *
  532. * @return array meta info for fields in $result
  533. */
  534. public function getFieldsMeta($result)
  535. {
  536. // Build an associative array for a type look up
  537. $typeAr = array();
  538. $typeAr[MYSQLI_TYPE_DECIMAL] = 'real';
  539. $typeAr[MYSQLI_TYPE_NEWDECIMAL] = 'real';
  540. $typeAr[MYSQLI_TYPE_BIT] = 'int';
  541. $typeAr[MYSQLI_TYPE_TINY] = 'int';
  542. $typeAr[MYSQLI_TYPE_SHORT] = 'int';
  543. $typeAr[MYSQLI_TYPE_LONG] = 'int';
  544. $typeAr[MYSQLI_TYPE_FLOAT] = 'real';
  545. $typeAr[MYSQLI_TYPE_DOUBLE] = 'real';
  546. $typeAr[MYSQLI_TYPE_NULL] = 'null';
  547. $typeAr[MYSQLI_TYPE_TIMESTAMP] = 'timestamp';
  548. $typeAr[MYSQLI_TYPE_LONGLONG] = 'int';
  549. $typeAr[MYSQLI_TYPE_INT24] = 'int';
  550. $typeAr[MYSQLI_TYPE_DATE] = 'date';
  551. $typeAr[MYSQLI_TYPE_TIME] = 'time';
  552. $typeAr[MYSQLI_TYPE_DATETIME] = 'datetime';
  553. $typeAr[MYSQLI_TYPE_YEAR] = 'year';
  554. $typeAr[MYSQLI_TYPE_NEWDATE] = 'date';
  555. $typeAr[MYSQLI_TYPE_ENUM] = 'unknown';
  556. $typeAr[MYSQLI_TYPE_SET] = 'unknown';
  557. $typeAr[MYSQLI_TYPE_TINY_BLOB] = 'blob';
  558. $typeAr[MYSQLI_TYPE_MEDIUM_BLOB] = 'blob';
  559. $typeAr[MYSQLI_TYPE_LONG_BLOB] = 'blob';
  560. $typeAr[MYSQLI_TYPE_BLOB] = 'blob';
  561. $typeAr[MYSQLI_TYPE_VAR_STRING] = 'string';
  562. $typeAr[MYSQLI_TYPE_STRING] = 'string';
  563. $typeAr[MYSQLI_TYPE_VARCHAR] = 'string'; // for Drizzle
  564. // MySQL returns MYSQLI_TYPE_STRING for CHAR
  565. // and MYSQLI_TYPE_CHAR === MYSQLI_TYPE_TINY
  566. // so this would override TINYINT and mark all TINYINT as string
  567. // https://sourceforge.net/p/phpmyadmin/bugs/2205/
  568. //$typeAr[MYSQLI_TYPE_CHAR] = 'string';
  569. $typeAr[MYSQLI_TYPE_GEOMETRY] = 'geometry';
  570. $typeAr[MYSQLI_TYPE_BIT] = 'bit';
  571. $fields = mysqli_fetch_fields($result);
  572. // this happens sometimes (seen under MySQL 4.0.25)
  573. if (!is_array($fields)) {
  574. return false;
  575. }
  576. foreach ($fields as $k => $field) {
  577. $fields[$k]->_type = $field->type;
  578. $fields[$k]->type = $typeAr[$field->type];
  579. $fields[$k]->_flags = $field->flags;
  580. $fields[$k]->flags = $this->fieldFlags($result, $k);
  581. // Enhance the field objects for mysql-extension compatibilty
  582. //$flags = explode(' ', $fields[$k]->flags);
  583. //array_unshift($flags, 'dummy');
  584. $fields[$k]->multiple_key
  585. = (int) (bool) ($fields[$k]->_flags & MYSQLI_MULTIPLE_KEY_FLAG);
  586. $fields[$k]->primary_key
  587. = (int) (bool) ($fields[$k]->_flags & MYSQLI_PRI_KEY_FLAG);
  588. $fields[$k]->unique_key
  589. = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNIQUE_KEY_FLAG);
  590. $fields[$k]->not_null
  591. = (int) (bool) ($fields[$k]->_flags & MYSQLI_NOT_NULL_FLAG);
  592. $fields[$k]->unsigned
  593. = (int) (bool) ($fields[$k]->_flags & MYSQLI_UNSIGNED_FLAG);
  594. $fields[$k]->zerofill
  595. = (int) (bool) ($fields[$k]->_flags & MYSQLI_ZEROFILL_FLAG);
  596. $fields[$k]->numeric
  597. = (int) (bool) ($fields[$k]->_flags & MYSQLI_NUM_FLAG);
  598. $fields[$k]->blob
  599. = (int) (bool) ($fields[$k]->_flags & MYSQLI_BLOB_FLAG);
  600. }
  601. return $fields;
  602. }
  603. /**
  604. * return number of fields in given $result
  605. *
  606. * @param mysqli_result $result result set identifier
  607. *
  608. * @return int field count
  609. */
  610. public function numFields($result)
  611. {
  612. return mysqli_num_fields($result);
  613. }
  614. /**
  615. * returns the length of the given field $i in $result
  616. *
  617. * @param mysqli_result $result result set identifier
  618. * @param int $i field
  619. *
  620. * @return int length of field
  621. */
  622. public function fieldLen($result, $i)
  623. {
  624. return mysqli_fetch_field_direct($result, $i)->length;
  625. }
  626. /**
  627. * returns name of $i. field in $result
  628. *
  629. * @param mysqli_result $result result set identifier
  630. * @param int $i field
  631. *
  632. * @return string name of $i. field in $result
  633. */
  634. public function fieldName($result, $i)
  635. {
  636. return mysqli_fetch_field_direct($result, $i)->name;
  637. }
  638. /**
  639. * returns concatenated string of human readable field flags
  640. *
  641. * @param mysqli_result $result result set identifier
  642. * @param int $i field
  643. *
  644. * @return string field flags
  645. */
  646. public function fieldFlags($result, $i)
  647. {
  648. $f = mysqli_fetch_field_direct($result, $i);
  649. $type = $f->type;
  650. $charsetnr = $f->charsetnr;
  651. $f = $f->flags;
  652. $flags = '';
  653. if ($f & MYSQLI_UNIQUE_KEY_FLAG) {
  654. $flags .= 'unique ';
  655. }
  656. if ($f & MYSQLI_NUM_FLAG) {
  657. $flags .= 'num ';
  658. }
  659. if ($f & MYSQLI_PART_KEY_FLAG) {
  660. $flags .= 'part_key ';
  661. }
  662. if ($f & MYSQLI_SET_FLAG) {
  663. $flags .= 'set ';
  664. }
  665. if ($f & MYSQLI_TIMESTAMP_FLAG) {
  666. $flags .= 'timestamp ';
  667. }
  668. if ($f & MYSQLI_AUTO_INCREMENT_FLAG) {
  669. $flags .= 'auto_increment ';
  670. }
  671. if ($f & MYSQLI_ENUM_FLAG) {
  672. $flags .= 'enum ';
  673. }
  674. // See http://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html:
  675. // to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG
  676. // but instead the charsetnr member of the MYSQL_FIELD
  677. // structure. Watch out: some types like DATE returns 63 in charsetnr
  678. // so we have to check also the type.
  679. // Unfortunately there is no equivalent in the mysql extension.
  680. if (($type == MYSQLI_TYPE_TINY_BLOB || $type == MYSQLI_TYPE_BLOB
  681. || $type == MYSQLI_TYPE_MEDIUM_BLOB || $type == MYSQLI_TYPE_LONG_BLOB
  682. || $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING)
  683. && 63 == $charsetnr
  684. ) {
  685. $flags .= 'binary ';
  686. }
  687. if ($f & MYSQLI_ZEROFILL_FLAG) {
  688. $flags .= 'zerofill ';
  689. }
  690. if ($f & MYSQLI_UNSIGNED_FLAG) {
  691. $flags .= 'unsigned ';
  692. }
  693. if ($f & MYSQLI_BLOB_FLAG) {
  694. $flags .= 'blob ';
  695. }
  696. if ($f & MYSQLI_MULTIPLE_KEY_FLAG) {
  697. $flags .= 'multiple_key ';
  698. }
  699. if ($f & MYSQLI_UNIQUE_KEY_FLAG) {
  700. $flags .= 'unique_key ';
  701. }
  702. if ($f & MYSQLI_PRI_KEY_FLAG) {
  703. $flags .= 'primary_key ';
  704. }
  705. if ($f & MYSQLI_NOT_NULL_FLAG) {
  706. $flags .= 'not_null ';
  707. }
  708. return trim($flags);
  709. }
  710. }
  711. ?>