PageRenderTime 67ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext/mysql/ext_mysqli.php

http://github.com/facebook/hiphop-php
PHP | 2995 lines | 873 code | 255 blank | 1867 comment | 75 complexity | 826e6904e44a38d0feaecb1fe29b8b41 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0

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

  1. <?hh
  2. /**
  3. * Represents a connection between PHP and a MySQL database.
  4. */
  5. class mysqli {
  6. public static int $__connection_errno = 0;
  7. public static ?string $__connection_error = null;
  8. private ?resource $__connection = null;
  9. <<__Native>>
  10. private function hh_get_connection(int $state = 0): ?resource;
  11. /**
  12. * Open a new connection to the MySQL server
  13. *
  14. * @param string $host - Can be either a host name or an IP address.
  15. * Passing the NULL value or the string "localhost" to this parameter,
  16. * the local host is assumed. When possible, pipes will be used instead
  17. * of the TCP/IP protocol. Prepending host by p: opens a persistent
  18. * connection. mysqli_change_user() is automatically called on
  19. * connections opened from the connection pool.
  20. * @param string $username - The MySQL user name.
  21. * @param string $passwd - If not provided or NULL, the MySQL server will
  22. * attempt to authenticate the user against those user records which have
  23. * no password only. This allows one username to be used with different
  24. * permissions (depending on if a password as provided or not).
  25. * @param string $dbname - If provided will specify the default database
  26. * to be used when performing queries.
  27. * @param mixed $port - Specifies the port number to attempt to connect to
  28. * the MySQL server.
  29. * @param string $socket - Specifies the socket or named pipe that should
  30. * be used. Specifying the socket parameter will not explicitly
  31. * determine the type of connection to be used when connecting to the
  32. * MySQL server. How the connection is made to the MySQL database is
  33. * determined by the host parameter.
  34. */
  35. public function __construct(?string $host = null,
  36. ?string $username = null,
  37. ?string $passwd = null,
  38. ?string $dbname = null,
  39. mixed $port = null,
  40. ?string $socket = null): void {
  41. $this->hh_init();
  42. if (func_num_args() == 0) {
  43. return;
  44. }
  45. // If any of the necessary mysqli properties come in as null, then we can
  46. // use our default ini options.
  47. $host = $this->get_ini_default_if_null($host, "host");
  48. $username = $this->get_ini_default_if_null($username, "user");
  49. $passwd = $this->get_ini_default_if_null($passwd, "pw");
  50. $port = $this->get_ini_default_if_null($port, "port");
  51. $socket = $this->get_ini_default_if_null($socket, "socket");
  52. // Connect
  53. $this->real_connect($host, $username, $passwd, $dbname, $port, $socket);
  54. }
  55. private function get_ini_default_if_null(mixed $connect_option,
  56. string $name) {
  57. if ($connect_option === null) {
  58. $connect_option = ini_get("mysqli.default_" . $name);
  59. }
  60. return $connect_option;
  61. }
  62. public function __clone(): void {
  63. hphp_throw_fatal_error(
  64. 'Trying to clone an uncloneable object of class mysqli_result'
  65. );
  66. }
  67. /**
  68. * Alias for __construct
  69. */
  70. public function connect(?string $host = null,
  71. ?string $username = null,
  72. ?string $passwd = null,
  73. ?string $dbname = null,
  74. mixed $port = null,
  75. ?string $socket = null): void {
  76. $this->hh_init();
  77. if (func_num_args() == 0) {
  78. return;
  79. }
  80. // Connect
  81. $this->real_connect($host, $username, $passwd, $dbname, $port, $socket);
  82. }
  83. <<__Native>>
  84. private function hh_init(): void;
  85. /**
  86. * Turns on or off auto-committing database modifications
  87. *
  88. * @param bool $mode - Whether to turn on auto-commit or not.
  89. *
  90. * @return bool -
  91. */
  92. <<__Native>>
  93. public function autocommit(bool $mode): mixed;
  94. /**
  95. * Starts a transaction
  96. *
  97. * @param ?int $flags -
  98. * @param ?string $name -
  99. *
  100. * @return bool -
  101. */
  102. public function begin_transaction(?int $flags = null,
  103. ?string $name = null): bool {
  104. $query = 'START TRANSACTION';
  105. if ($name) {
  106. $query .= '/*'. $name .'*/';
  107. }
  108. if ($flags) {
  109. $option_strings = Map {
  110. MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT =>
  111. 'WITH CONSISTENT SNAPSHOT',
  112. MYSQLI_TRANS_START_READ_WRITE => 'READ WRITE',
  113. MYSQLI_TRANS_START_READ_ONLY => 'READ ONLY',
  114. };
  115. $options = array();
  116. foreach ($option_strings as $bit => $str) {
  117. if ($flags & $bit) {
  118. $options[] = $str;
  119. }
  120. }
  121. if ($options) {
  122. $query .= ' '. join(', ', $options);
  123. }
  124. }
  125. return $this->real_query($query);
  126. }
  127. /**
  128. * Changes the user of the specified database connection
  129. *
  130. * @param string $user - The MySQL user name.
  131. * @param string $password - The MySQL password.
  132. * @param string $database - The database to change to. If desired,
  133. * the NULL value may be passed resulting in only changing the user and
  134. * not selecting a database. To select a database in this case use the
  135. * mysqli_select_db() function.
  136. *
  137. * @return bool -
  138. */
  139. <<__Native>>
  140. public function change_user(string $user, string $password,
  141. string $database): mixed;
  142. /**
  143. * Returns the default character set for the database connection
  144. *
  145. * @return string - The default character set for the current
  146. * connection
  147. */
  148. <<__Native>>
  149. public function character_set_name(): mixed;
  150. /**
  151. * Closes a previously opened database connection
  152. *
  153. * @return bool -
  154. */
  155. public function close(): bool {
  156. $conn = $this->__connection;
  157. if ($conn) {
  158. return mysql_close($conn);
  159. }
  160. return true;
  161. }
  162. private function __end_transaction(bool $commit, int $flags = 0,
  163. ?string $name = null): ?bool {
  164. $query = ($commit) ? 'COMMIT' : 'ROLLBACK';
  165. if ($name) {
  166. $query .= '/*'. $name .'*/';
  167. }
  168. if ($flags) {
  169. switch ($flags & (MYSQLI_TRANS_COR_AND_CHAIN |
  170. MYSQLI_TRANS_COR_AND_NO_CHAIN)) {
  171. case MYSQLI_TRANS_COR_AND_CHAIN:
  172. $query .= ' AND CHAIN';
  173. case MYSQLI_TRANS_COR_AND_NO_CHAIN:
  174. $query .= ' AND NO CHAIN';
  175. default:
  176. // Do nothing to mimic Zend
  177. break;
  178. }
  179. switch ($flags & (MYSQLI_TRANS_COR_RELEASE |
  180. MYSQLI_TRANS_COR_NO_RELEASE)) {
  181. case MYSQLI_TRANS_COR_RELEASE:
  182. $query .= ' RELEASE';
  183. case MYSQLI_TRANS_COR_NO_RELEASE:
  184. $query .= ' AND NO RELEASE';
  185. default:
  186. // Do nothing to mimic Zend
  187. break;
  188. }
  189. }
  190. return $this->real_query($query);
  191. }
  192. /**
  193. * Commits the current transaction
  194. *
  195. * @param int $flags - A bitmask of MYSQLI_TRANS_COR_* constants.
  196. * @param string $name - If provided then COMMIT{name} is executed.
  197. *
  198. * @return bool -
  199. */
  200. public function commit(int $flags = 0, ?string $name = null): bool {
  201. return $this->__end_transaction(true, $flags, $name);
  202. }
  203. /**
  204. * Performs debugging operations
  205. *
  206. * @param string $message - A string representing the debugging
  207. * operation to perform
  208. *
  209. * @return bool - Returns TRUE.
  210. */
  211. //public function debug(string $message): bool {
  212. // return mysqli_debug($message);
  213. //}
  214. /**
  215. * Dump debugging information into the log
  216. *
  217. * @return bool -
  218. */
  219. <<__Native>>
  220. public function dump_debug_info(): mixed;
  221. /**
  222. * Alias for real_escape_string
  223. */
  224. public function escape_string($escapestr): ?string {
  225. return $this->real_escape_string($escapestr);
  226. }
  227. /**
  228. * Returns a character set object
  229. *
  230. * @return object - The function returns a character set object with the
  231. * following properties:
  232. * - charset Character set name
  233. * - collation Collation name
  234. * - dir Directory the charset description was fetched from (?) or "" for
  235. * built-in character sets
  236. * - min_length Minimum character length in bytes
  237. * - max_length Maximum character length in bytes
  238. * - number Internal character set number
  239. * - state Character set status (?)
  240. */
  241. <<__Native>>
  242. public function get_charset(): mixed;
  243. /**
  244. * Get MySQL client info
  245. *
  246. * @return string - A string that represents the MySQL client library
  247. * version
  248. */
  249. public function get_client_info(): string {
  250. return mysqli_get_client_info();
  251. }
  252. /**
  253. * Returns statistics about the client connection
  254. *
  255. * @return bool - Returns an array with connection stats if success,
  256. * FALSE otherwise.
  257. */
  258. //<<__Native>>
  259. //public function get_connection_stats(): mixed;
  260. /**
  261. * Get result of SHOW WARNINGS
  262. *
  263. * @return mysqli_warning -
  264. */
  265. public function get_warnings(): mixed {
  266. if (!$this->warning_count) {
  267. return false;
  268. }
  269. $res = $this->query('SHOW WARNINGS');
  270. if (!$res) {
  271. return false;
  272. }
  273. $warnings = $res->fetch_all(MYSQLI_ASSOC);
  274. if (!$warnings) {
  275. return false;
  276. }
  277. return new mysqli_warning($warnings);
  278. }
  279. /**
  280. * Initializes MySQLi and returns a resource for use with
  281. * mysqli_real_connect()
  282. *
  283. * @return mysqli - Returns an object.
  284. */
  285. public function init(): mysqli {
  286. $this->hh_init();
  287. return $this;
  288. }
  289. /**
  290. * Asks the server to kill a MySQL thread
  291. *
  292. * @param int $processid -
  293. *
  294. * @return bool -
  295. */
  296. <<__Native>>
  297. public function kill(int $processid): mixed;
  298. /**
  299. * Check if there are any more query results from a multi query
  300. *
  301. * @return bool - Returns TRUE if one or more result sets are available
  302. * from a previous call to mysqli_multi_query(), otherwise FALSE.
  303. */
  304. public function more_results(): mixed {
  305. $conn = $this->hh_get_connection(2);
  306. if (!$conn) {
  307. return null;
  308. }
  309. return mysql_more_results($conn);
  310. }
  311. /**
  312. * Performs a query on the database
  313. *
  314. * @param string $query - The query, as a string. Data inside the
  315. * query should be properly escaped.
  316. *
  317. * @return bool - Returns FALSE if the first statement failed. To
  318. * retrieve subsequent errors from other statements you have to call
  319. * mysqli_next_result() first.
  320. */
  321. public function multi_query(string $query): ?bool {
  322. $conn = $this->hh_get_connection(2);
  323. if (!$conn) {
  324. return null;
  325. }
  326. return mysql_multi_query($query, $conn);
  327. }
  328. /**
  329. * Prepare next result from multi_query
  330. *
  331. * @return bool -
  332. */
  333. public function next_result(): ?bool {
  334. $conn = $this->hh_get_connection(2);
  335. if (!$conn) {
  336. return null;
  337. }
  338. return !mysql_next_result($conn);
  339. }
  340. /**
  341. * Set options
  342. *
  343. * @param int $option - The option that you want to set. It can be one
  344. * of the following values: Valid options Name Description
  345. * MYSQLI_OPT_CONNECT_TIMEOUT connection timeout in seconds (supported
  346. * on Windows with TCP/IP since PHP 5.3.1) MYSQLI_OPT_LOCAL_INFILE
  347. * enable/disable use of LOAD LOCAL INFILE MYSQLI_INIT_COMMAND
  348. * command to execute after when connecting to MySQL server
  349. * MYSQLI_READ_DEFAULT_FILE Read options from named option file
  350. * instead of my.cnf MYSQLI_READ_DEFAULT_GROUP Read options from
  351. * the named group from my.cnf or the file specified with
  352. * MYSQL_READ_DEFAULT_FILE. MYSQLI_SERVER_PUBLIC_KEY RSA public key
  353. * file used with the SHA-256 based authentication.
  354. * @param mixed $value - The value for the option.
  355. *
  356. * @return bool -
  357. */
  358. <<__Native>>
  359. public function options(int $option, mixed $value): mixed;
  360. /**
  361. * Pings a server connection, or tries to reconnect if the connection has
  362. * gone down
  363. *
  364. * @return bool -
  365. */
  366. public function ping(): ?bool {
  367. $conn = $this->hh_get_connection(2);
  368. if (!$conn) {
  369. return null;
  370. }
  371. return mysql_ping($conn);
  372. }
  373. /**
  374. * Poll connections
  375. *
  376. * @param array $read - List of connections to check for outstanding
  377. * results that can be read.
  378. * @param array $error - List of connections on which an error occurred,
  379. * for example, query failure or lost connection.
  380. * @param array $reject - List of connections rejected because no
  381. * asynchronous query has been run on for which the function could poll
  382. * results.
  383. * @param int $sec - Number of seconds to wait, must be non-negative.
  384. * @param int $usec - Number of microseconds to wait, must be
  385. * non-negative.
  386. *
  387. * @return int - Returns number of ready connections upon success,
  388. * FALSE otherwise.
  389. */
  390. //<<__Native>>
  391. //public static function poll(array &$read,
  392. // array &$error,
  393. // array &$reject,
  394. // int $sec,
  395. // int $usec): int;
  396. /**
  397. * Prepare an SQL statement for execution
  398. *
  399. * @param string $query - The query, as a string. You should not add
  400. * a terminating semicolon or \g to the statement. This parameter
  401. * can include one or more parameter markers in the SQL statement by
  402. * embedding question mark (?) characters at the appropriate positions.
  403. * The markers are legal only in certain places in SQL statements.
  404. * For example, they are allowed in the VALUES() list of an INSERT
  405. * statement (to specify column values for a row), or in a comparison
  406. * with a column in a WHERE clause to specify a comparison value.
  407. * However, they are not allowed for identifiers (such as table or
  408. * column names), in the select list that names the columns to be
  409. * returned by a SELECT statement, or to specify both operands of a
  410. * binary operator such as the = equal sign. The latter restriction is
  411. * necessary because it would be impossible to determine the parameter
  412. * type. It's not allowed to compare marker with NULL by ? IS NULL too.
  413. * In general, parameters are legal only in Data Manipulation Language
  414. * (DML) statements, and not in Data Definition Language (DDL)
  415. * statements.
  416. *
  417. * @return mysqli_stmt - mysqli_prepare() returns a statement object or
  418. * FALSE if an error occurred.
  419. */
  420. public function prepare(string $query): mixed {
  421. $stmt = new mysqli_stmt($this);
  422. $prepared = $stmt->prepare($query);
  423. if (!$prepared) {
  424. // If we failed to prepare we need to move the error messages that are on
  425. // the mysqli_stmt object to the mysqli object otherwise the user will
  426. // never be able to get them.
  427. $this->hh_update_last_error($stmt);
  428. return false;
  429. }
  430. return $stmt;
  431. }
  432. <<__Native>>
  433. private function hh_update_last_error(mysqli_stmt $stmt): void;
  434. /**
  435. * Performs a query on the database
  436. *
  437. * @param string $query - The query string. Data inside the query
  438. * should be properly escaped.
  439. * @param int $resultmode - Either the constant MYSQLI_USE_RESULT or
  440. * MYSQLI_STORE_RESULT depending on the desired behavior. By default,
  441. * MYSQLI_STORE_RESULT is used. If you use MYSQLI_USE_RESULT all
  442. * subsequent calls will return error Commands out of sync unless you
  443. * call mysqli_free_result() With MYSQLI_ASYNC (available with
  444. * mysqlnd), it is possible to perform query asynchronously.
  445. * mysqli_poll() is then used to get results from such queries.
  446. *
  447. * @return mixed - Returns FALSE on failure. For successful SELECT,
  448. * SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a
  449. * mysqli_result object. For other successful queries mysqli_query()
  450. * will return TRUE.
  451. */
  452. public function query(string $query,
  453. int $resultmode = MYSQLI_STORE_RESULT): ?mixed {
  454. if ($resultmode !== MYSQLI_STORE_RESULT &&
  455. $resultmode !== MYSQLI_USE_RESULT) {
  456. trigger_error("Invalid value for resultmode", E_WARNING);
  457. return false;
  458. }
  459. $result = $this->hh_real_query($query);
  460. if ($result === null) {
  461. return null;
  462. }
  463. if ($result == 2) {
  464. if ($resultmode == MYSQLI_STORE_RESULT) {
  465. return $this->store_result();
  466. } else {
  467. return $this->use_result();
  468. }
  469. }
  470. return $result !== 0;
  471. }
  472. /**
  473. * Opens a connection to a mysql server
  474. *
  475. * @param string $host - Can be either a host name or an IP address.
  476. * Passing the NULL value or the string "localhost" to this parameter,
  477. * the local host is assumed. When possible, pipes will be used instead
  478. * of the TCP/IP protocol.
  479. * @param string $username - The MySQL user name.
  480. * @param string $passwd - If provided or NULL, the MySQL server will
  481. * attempt to authenticate the user against those user records which
  482. * have no password only. This allows one username to be used with
  483. * different permissions (depending on if a password as provided or
  484. * not).
  485. * @param string $dbname - If provided will specify the default
  486. * database to be used when performing queries.
  487. * @param mixed $port - Specifies the port number to attempt to connect
  488. * to the MySQL server.
  489. * @param string $socket - Specifies the socket or named pipe that
  490. * should be used. Specifying the socket parameter will not
  491. * explicitly determine the type of connection to be used when
  492. * connecting to the MySQL server. How the connection is made to the
  493. * MySQL database is determined by the host parameter.
  494. * @param int $flags - With the parameter flags you can set different
  495. * connection options: Supported flags Name Description
  496. * MYSQLI_CLIENT_COMPRESS Use compression protocol
  497. * MYSQLI_CLIENT_FOUND_ROWS return number of matched rows, not the
  498. * number of affected rows MYSQLI_CLIENT_IGNORE_SPACE Allow spaces
  499. * after function names. Makes all function names reserved words.
  500. * MYSQLI_CLIENT_INTERACTIVE Allow interactive_timeout seconds
  501. * (instead of wait_timeout seconds) of inactivity before closing the
  502. * connection MYSQLI_CLIENT_SSL Use SSL (encryption) For
  503. * security reasons the MULTI_STATEMENT flag is not supported in PHP.
  504. * If you want to execute multiple queries use the mysqli_multi_query()
  505. * function.
  506. *
  507. * @return bool -
  508. */
  509. public function real_connect(?string $host = null,
  510. ?string $username = null,
  511. ?string $passwd = null,
  512. ?string $dbname = null,
  513. mixed $port = null,
  514. ?string $socket = null,
  515. ?int $flags = 0): bool {
  516. // TODO: Fix this to use ZendParamMode when it is available
  517. // See D1359972 for context
  518. if (is_string($port)) {
  519. if (!ctype_digit($port)) {
  520. throw new Exception('Port is not numeric');
  521. };
  522. $port = (int) $port;
  523. }
  524. if ($port !== null && !is_int($port)) {
  525. throw new Exception('Port is not numeric');
  526. }
  527. $server = null;
  528. if ($host) {
  529. $server = $host;
  530. if ($port) {
  531. $server .= ':'. $port;
  532. }
  533. } else if ($socket) {
  534. $server = ':'. $socket;
  535. }
  536. $ret = $this->hh_real_connect($server, $username, $passwd, $dbname, $flags);
  537. if (!$ret) {
  538. self::$__connection_errno = mysql_errno();
  539. self::$__connection_error = mysql_error();
  540. return false;
  541. }
  542. self::$__connection_errno = 0;
  543. self::$__connection_error = null;
  544. return true;
  545. }
  546. <<__Native>>
  547. private function hh_real_connect(?string $server,
  548. ?string $username,
  549. ?string $passwd,
  550. ?string $dbname,
  551. ?int $flags): bool;
  552. /**
  553. * Escapes special characters in a string for use in an SQL statement,
  554. * taking into account the current charset of the connection
  555. *
  556. * @param string $escapestr - The string to be escaped. Characters
  557. * encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
  558. *
  559. * @return string - Returns an escaped string.
  560. */
  561. public function real_escape_string($escapestr): ?string {
  562. $conn = $this->hh_get_connection(2);
  563. if (!$conn) {
  564. return null;
  565. }
  566. return mysql_real_escape_string($escapestr, $conn);
  567. }
  568. /**
  569. * Execute an SQL query
  570. *
  571. * @param string $query - The query, as a string. Data inside the
  572. * query should be properly escaped.
  573. *
  574. * @return bool -
  575. */
  576. public function real_query(string $query): ?bool {
  577. $result = $this->hh_real_query($query);
  578. if ($result === null) {
  579. return null;
  580. }
  581. return $result !== 0;
  582. }
  583. <<__Native>>
  584. private function hh_real_query(string $query): ?int;
  585. /**
  586. * Get result from async query
  587. *
  588. * @return mysqli_result - Returns mysqli_result in success, FALSE
  589. * otherwise.
  590. */
  591. //<<__Native>>
  592. //public function reap_async_query(): mysqli_result;
  593. /**
  594. * Refreshes
  595. *
  596. * @param int $options - The options to refresh, using the
  597. * MYSQLI_REFRESH_* constants as documented within the MySQLi constants
  598. * documentation. See also the official MySQL Refresh documentation.
  599. *
  600. * @return bool - TRUE if the refresh was a success, otherwise FALSE
  601. */
  602. <<__Native>>
  603. public function refresh(int $options): mixed;
  604. /**
  605. * Rolls back a transaction to the named savepoint
  606. *
  607. * @param string $name -
  608. *
  609. * @return bool -
  610. */
  611. public function release_savepoint(string $name): ?bool {
  612. return $this->real_query('RELEASE SAVEPOINT `'. $name .'`');
  613. }
  614. /**
  615. * Rolls back current transaction
  616. *
  617. * @param int $flags - A bitmask of MYSQLI_TRANS_COR_* constants.
  618. * @param string $name - If provided then ROLLBACK{name} is executed.
  619. *
  620. * @return bool -
  621. */
  622. public function rollback(int $flags = 0, ?string $name = null): ?bool {
  623. return $this->__end_transaction(false, $flags, $name);
  624. }
  625. /**
  626. * Set a named transaction savepoint
  627. *
  628. * @param string $name -
  629. *
  630. * @return bool -
  631. */
  632. public function savepoint(string $name): ?bool {
  633. return $this->real_query('SAVEPOINT `'. $name .'`');
  634. }
  635. /**
  636. * Selects the default database for database queries
  637. *
  638. * @param string $dbname - The database name.
  639. *
  640. * @return bool -
  641. */
  642. public function select_db(string $dbname): ?bool {
  643. $conn = $this->hh_get_connection(2);
  644. if (!$conn) {
  645. return null;
  646. }
  647. return mysql_select_db($dbname, $conn);
  648. }
  649. /**
  650. * Sets the default client character set
  651. *
  652. * @param string $charset - The charset to be set as default.
  653. *
  654. * @return bool -
  655. */
  656. public function set_charset(string $charset) {
  657. $conn = $this->hh_get_connection(2);
  658. if (!$conn) {
  659. return null;
  660. }
  661. return mysql_set_charset($charset, $conn);
  662. }
  663. /**
  664. * Set callback function for LOAD DATA LOCAL INFILE command
  665. *
  666. * @param callable $read_func - A callback function or object method
  667. * taking the following parameters: stream A PHP stream associated
  668. * with the SQL commands INFILE buffer A string buffer to store the
  669. * rewritten input into buflen The maximum number of characters to be
  670. * stored in the buffer errormsg If an error occurs you can store an
  671. * error message in here
  672. *
  673. * @return bool -
  674. */
  675. //<<__Native>>
  676. //public function set_local_infile_handler(callable $read_func): bool;
  677. /**
  678. * Alias of options()
  679. */
  680. public function set_opt(int $option, mixed $value): mixed {
  681. return $this->options($option, $value);
  682. }
  683. /**
  684. * Used for establishing secure connections using SSL
  685. *
  686. * @param string $key - The path name to the key file.
  687. * @param string $cert - The path name to the certificate file.
  688. * @param string $ca - The path name to the certificate authority file.
  689. * @param string $capath - The pathname to a directory that contains
  690. * trusted SSL CA certificates in PEM format.
  691. * @param string $cipher - A list of allowable ciphers to use for SSL
  692. * encryption.
  693. *
  694. * @return bool - This function always returns TRUE value. If SSL setup
  695. * is incorrect mysqli_real_connect() will return an error when you
  696. * attempt to connect.
  697. */
  698. <<__Native>>
  699. public function ssl_set(?string $key,
  700. ?string $cert,
  701. ?string $ca,
  702. ?string $capath,
  703. ?string $cipher): mixed;
  704. /**
  705. * Gets the current system status
  706. *
  707. * @return string - A string describing the server status. FALSE if an
  708. * error occurred.
  709. */
  710. public function stat(): ?string {
  711. $conn = $this->hh_get_connection(2);
  712. if (!$conn) {
  713. return null;
  714. }
  715. return mysql_stat($conn);
  716. }
  717. /**
  718. * Initializes a statement and returns an object for use with
  719. * mysqli_stmt_prepare
  720. *
  721. * @return mysqli_stmt - Returns an object.
  722. */
  723. public function stmt_init(): mysqli_stmt {
  724. return new mysqli_stmt($this);
  725. }
  726. <<__Native>>
  727. private function hh_get_result(bool $use_store): ?mixed;
  728. /**
  729. * Transfers a result set from the last query
  730. *
  731. * @return mysqli_result - Returns a buffered result object or FALSE if
  732. * an error occurred. mysqli_store_result() returns FALSE in case
  733. * the query didn't return a result set (if the query was, for example
  734. * an INSERT statement). This function also returns FALSE if the
  735. * reading of the result set failed. You can check if you have got an
  736. * error by checking if mysqli_error() doesn't return an empty string,
  737. * if mysqli_errno() returns a non zero value, or if
  738. * mysqli_field_count() returns a non zero value. Also possible reason
  739. * for this function returning FALSE after successful call to
  740. * mysqli_query() can be too large result set (memory for it cannot be
  741. * allocated). If mysqli_field_count() returns a non-zero value, the
  742. * statement should have produced a non-empty result set.
  743. */
  744. public function store_result(): ?mixed {
  745. $result = $this->hh_get_result(true);
  746. if ($result === null) {
  747. return null;
  748. }
  749. if (is_bool($result)) {
  750. return false;
  751. }
  752. return new mysqli_result($result, MYSQLI_STORE_RESULT);
  753. }
  754. /**
  755. * Initiate a result set retrieval
  756. *
  757. * @return mysqli_result - Returns an unbuffered result object or FALSE
  758. * if an error occurred.
  759. */
  760. public function use_result(): ?mixed {
  761. $result = $this->hh_get_result(false);
  762. if ($result === null) {
  763. return null;
  764. }
  765. if (is_bool($result)) {
  766. return $result;
  767. }
  768. return new mysqli_result($result, MYSQLI_USE_RESULT);
  769. }
  770. }
  771. /**
  772. * The mysqli exception handling class.
  773. */
  774. //class mysqli_sql_exception {
  775. //}
  776. /**
  777. * MySQLi Driver.
  778. */
  779. class mysqli_driver {
  780. private bool $__reconnect = false;
  781. private int $__report_mode = 0;
  782. public function __construct() {
  783. $this->__reconnect = ini_get("mysqli.reconnect") === "1" ? true : false;
  784. }
  785. public function __clone(): void {
  786. hphp_throw_fatal_error(
  787. 'Trying to clone an uncloneable object of class mysqli_result'
  788. );
  789. }
  790. }
  791. /**
  792. * Represents the result set obtained from a query against the database.
  793. * 5.4.0 Iterator support was added, as mysqli_result now implements
  794. * Traversable.
  795. */
  796. class mysqli_result {
  797. // Not typing this since we are setting it as a mixed to comply with
  798. // GitHub issue 2082. As it is, even with invariants and various ifs
  799. // to guarantee the type, HHHBC is not able to infer the property type.
  800. // Anyway, the typehint is currently only for optimization purposes at this
  801. // point in time. See D1663326
  802. private $__result = null;
  803. private ?int $__resulttype = null;
  804. private bool $__done = false;
  805. <<__Native>>
  806. private function get_mysqli_conn_resource(mysqli $connection): ?resource;
  807. public function __construct(mixed $result,
  808. int $resulttype = MYSQLI_STORE_RESULT) {
  809. if (!is_resource($result) && !($result instanceof mysqli)) {
  810. $msg = "Argument to mysqli_result::__construct must be of type "
  811. . "resource or mysqli";
  812. throw new Exception($msg);
  813. }
  814. if ($result instanceof mysqli) {
  815. $this->__result = $this->get_mysqli_conn_resource($result);
  816. } else {
  817. $this->__result = is_resource($result) ? $result : null;
  818. }
  819. $this->__resulttype = $resulttype;
  820. }
  821. public function __clone(): void {
  822. hphp_throw_fatal_error(
  823. 'Trying to clone an uncloneable object of class mysqli_result'
  824. );
  825. }
  826. private function __checkRow(mixed $row) {
  827. if ($row == false) {
  828. $this->__done = true;
  829. return null;
  830. }
  831. return $row;
  832. }
  833. private function __mysqli_to_mysql_resulttype(int $resulttype): mixed {
  834. switch ($resulttype) {
  835. case MYSQLI_NUM:
  836. return MYSQL_NUM;
  837. case MYSQLI_ASSOC:
  838. return MYSQL_ASSOC;
  839. case MYSQLI_BOTH:
  840. return MYSQL_BOTH;
  841. }
  842. trigger_error('Mode can be only MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH',
  843. E_WARNING);
  844. return null;
  845. }
  846. /**
  847. * Frees the memory associated with a result
  848. *
  849. * @return void -
  850. */
  851. public function close(): void {
  852. $this->free();
  853. }
  854. /**
  855. * Adjusts the result pointer to an arbitrary row in the result
  856. *
  857. * @param int $offset - The field offset. Must be between zero and the
  858. * total number of rows minus one (0..mysqli_num_rows() - 1).
  859. *
  860. * @return bool -
  861. */
  862. public function data_seek(int $offset): mixed {
  863. if ($this->__result === null) {
  864. return null;
  865. }
  866. if ($this->__resulttype == MYSQLI_USE_RESULT) {
  867. return false;
  868. }
  869. return mysql_data_seek($this->__result, $offset);
  870. }
  871. /**
  872. * Fetches all result rows as an associative array, a numeric array, or
  873. * both
  874. *
  875. * @param int $resulttype - This optional parameter is a constant
  876. * indicating what type of array should be produced from the current
  877. * row data. The possible values for this parameter are the constants
  878. * MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.
  879. *
  880. * @return mixed - Returns an array of associative or numeric arrays
  881. * holding result rows.
  882. */
  883. public function fetch_all(int $resulttype = MYSQLI_NUM): mixed {
  884. $result = array();
  885. while (($row = $this->fetch_array($resulttype)) !== null) {
  886. $result[] = $row;
  887. }
  888. return $result;
  889. }
  890. /**
  891. * Fetch a result row as an associative, a numeric array, or both
  892. *
  893. * @param int $resulttype - This optional parameter is a constant
  894. * indicating what type of array should be produced from the current
  895. * row data. The possible values for this parameter are the constants
  896. * MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By using the
  897. * MYSQLI_ASSOC constant this function will behave identically to the
  898. * mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to
  899. * the mysqli_fetch_row() function. The final option MYSQLI_BOTH will
  900. * create a single array with the attributes of both.
  901. *
  902. * @return mixed - Returns an array of strings that corresponds to the
  903. * fetched row or NULL if there are no more rows in resultset.
  904. */
  905. public function fetch_array(int $resulttype = MYSQLI_BOTH): mixed {
  906. return $this->__checkRow(
  907. mysql_fetch_array(
  908. $this->__result,
  909. $this->__mysqli_to_mysql_resulttype($resulttype),
  910. )
  911. );
  912. }
  913. /**
  914. * Fetch a result row as an associative array
  915. *
  916. * @return array - Returns an associative array of strings representing
  917. * the fetched row in the result set, where each key in the array
  918. * represents the name of one of the result set's columns or NULL if
  919. * there are no more rows in resultset. If two or more columns of the
  920. * result have the same field names, the last column will take
  921. * precedence. To access the other column(s) of the same name, you
  922. * either need to access the result with numeric indices by using
  923. * mysqli_fetch_row() or add alias names.
  924. */
  925. public function fetch_assoc(): mixed {
  926. return $this->fetch_array(MYSQLI_ASSOC);
  927. }
  928. /**
  929. * Fetch meta-data for a single field
  930. *
  931. * @param int $fieldnr - The field number. This value must be in the
  932. * range from 0 to number of fields - 1.
  933. *
  934. * @return object - Returns an object which contains field definition
  935. * information or FALSE if no field information for specified fieldnr
  936. * is available. Object attributes Attribute Description name
  937. * The name of the column orgname Original column name if an alias
  938. * was specified table The name of the table this field belongs to
  939. * (if not calculated) orgtable Original table name if an alias was
  940. * specified def The default value for this field, represented as a
  941. * string max_length The maximum width of the field for the result
  942. * set. length The width of the field, as specified in the table
  943. * definition. charsetnr The character set number for the field.
  944. * flags An integer representing the bit-flags for the field. type
  945. * The data type used for this field decimals The number of decimals
  946. * used (for integer fields)
  947. */
  948. public function fetch_field_direct(int $fieldnr): mixed {
  949. $this->field_seek($fieldnr);
  950. return $this->fetch_field();
  951. }
  952. /**
  953. * Returns the next field in the result set
  954. *
  955. * @return object - Returns an object which contains field definition
  956. * information or FALSE if no field information is available. Object
  957. * properties Property Description name The name of the column
  958. * orgname Original column name if an alias was specified table The
  959. * name of the table this field belongs to (if not calculated)
  960. * orgtable Original table name if an alias was specified def
  961. * Reserved for default value, currently always "" db Database (since
  962. * PHP 5.3.6) catalog The catalog name, always "def" (since PHP
  963. * 5.3.6) max_length The maximum width of the field for the result
  964. * set. length The width of the field, as specified in the table
  965. * definition. charsetnr The character set number for the field.
  966. * flags An integer representing the bit-flags for the field. type
  967. * The data type used for this field decimals The number of decimals
  968. * used (for integer fields)
  969. */
  970. <<__Native>>
  971. public function fetch_field(): mixed;
  972. /**
  973. * Returns an array of objects representing the fields in a result set
  974. *
  975. * @return array - Returns an array of objects which contains field
  976. * definition information or FALSE if no field information is
  977. * available. Object properties Property Description name The
  978. * name of the column orgname Original column name if an alias was
  979. * specified table The name of the table this field belongs to (if
  980. * not calculated) orgtable Original table name if an alias was
  981. * specified max_length The maximum width of the field for the result
  982. * set. length The width of the field, as specified in the table
  983. * definition. charsetnr The character set number for the field.
  984. * flags An integer representing the bit-flags for the field. type
  985. * The data type used for this field decimals The number of decimals
  986. * used (for integer fields)
  987. */
  988. public function fetch_fields(): array {
  989. $fields = array();
  990. $this->field_seek(0);
  991. while (($field = $this->fetch_field()) !== false) {
  992. $fields[] = $field;
  993. }
  994. return $fields;
  995. }
  996. /**
  997. * Returns the current row of a result set as an object
  998. *
  999. * @param string $class_name - The name of the class to instantiate,
  1000. * set the properties of and return. If not specified, a stdClass
  1001. * object is returned.
  1002. * @param array $params - An optional array of parameters to pass to
  1003. * the constructor for class_name objects.
  1004. *
  1005. * @return object - Returns an object with string properties that
  1006. * corresponds to the fetched row or NULL if there are no more rows in
  1007. * resultset.
  1008. */
  1009. public function fetch_object(?string $class_name = null,
  1010. array $params = array()): mixed {
  1011. if (func_num_args() == 0) {
  1012. $obj = mysql_fetch_object($this->__result);
  1013. } else {
  1014. $obj = mysql_fetch_object($this->__result, $class_name, $params);
  1015. }
  1016. return $this->__checkRow($obj);
  1017. }
  1018. /**
  1019. * Get a result row as an enumerated array
  1020. *
  1021. * @return mixed - mysqli_fetch_row() returns an array of strings that
  1022. * corresponds to the fetched row or NULL if there are no more rows in
  1023. * result set.
  1024. */
  1025. public function fetch_row(): mixed {
  1026. return $this->fetch_array(MYSQLI_NUM);
  1027. }
  1028. /**
  1029. * Set result pointer to a specified field offset
  1030. *
  1031. * @param int $fieldnr - The field number. This value must be in the
  1032. * range from 0 to number of fields - 1.
  1033. *
  1034. * @return bool -
  1035. */
  1036. public function field_seek(int $fieldnr): bool {
  1037. if (!mysql_field_seek($this->__result, $fieldnr)) {
  1038. return false;
  1039. }
  1040. return true;
  1041. }
  1042. /**
  1043. * Frees the memory associated with a result
  1044. *
  1045. * @return void -
  1046. */
  1047. public function free(): void {
  1048. mysql_free_result($this->__result);
  1049. $this->__result = null;
  1050. }
  1051. /**
  1052. * Frees the memory associated with a result
  1053. *
  1054. * @return void -
  1055. */
  1056. public function free_result(): void {
  1057. $this->free();
  1058. }
  1059. }
  1060. /**
  1061. * Represents a prepared statement.
  1062. */
  1063. class mysqli_stmt {
  1064. private ?resource $__stmt = null;
  1065. private ?mysqli $__link = null;
  1066. public function __construct(mysqli $link, string $query = null) {
  1067. $this->__link = $link;
  1068. $this->hh_init($link);
  1069. if ($query) {
  1070. $this->prepare($query);
  1071. }
  1072. }
  1073. public function __clone(): void {
  1074. hphp_throw_fatal_error(
  1075. 'Trying to clone an uncloneable object of class mysqli_result'
  1076. );
  1077. }
  1078. <<__Native>>
  1079. private function hh_init(mysqli $connection): void;
  1080. /**
  1081. * Used to get the current value of a statement attribute
  1082. *
  1083. * @param int $attr - The attribute that you want to get.
  1084. *
  1085. * @return int - Returns FALSE if the attribute is not found, otherwise
  1086. * returns the value of the attribute.
  1087. */
  1088. <<__Native>>
  1089. public function attr_get(int $attr): mixed;
  1090. /**
  1091. * Used to modify the behavior of a prepared statement
  1092. *
  1093. * @param int $attr - The attribute that you want to set. It can have
  1094. * one of the following values: Attribute values Character
  1095. * Description MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH If set to 1,
  1096. * causes mysqli_stmt_store_result() to update the metadata
  1097. * MYSQL_FIELD->max_length value. MYSQLI_STMT_ATTR_CURSOR_TYPE Type
  1098. * of cursor to open for statement when mysqli_stmt_execute() is
  1099. * invoked. mode can be MYSQLI_CURSOR_TYPE_NO_CURSOR (the default) or
  1100. * MYSQLI_CURSOR_TYPE_READ_ONLY. MYSQLI_STMT_ATTR_PREFETCH_ROWS
  1101. * Number of rows to fetch from server at a time when using a cursor.
  1102. * mode can be in the range from 1 to the maximum value of unsigned
  1103. * long. The default is 1. If you use the
  1104. * MYSQLI_STMT_ATTR_CURSOR_TYPE option with
  1105. * MYSQLI_CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement
  1106. * when you invoke mysqli_stmt_execute(). If there is already an open
  1107. * cursor from a previous mysqli_stmt_execute() call, it closes the
  1108. * cursor before opening a new one. mysqli_stmt_reset() also closes any
  1109. * open cursor before preparing the statement for re-execution.
  1110. * mysqli_stmt_free_result() closes any open cursor. If you open a
  1111. * cursor for a prepared statement, mysqli_stmt_store_result() is
  1112. * unnecessary.
  1113. * @param int $mode - The value to assign to the attribute.
  1114. *
  1115. * @return bool -
  1116. */
  1117. <<__Native>>
  1118. public function attr_set(int $attr, int $mode): mixed;
  1119. /**
  1120. * Binds variables to a prepared statement as parameters
  1121. *
  1122. * @param string $types - A string that contains one or more characters
  1123. * which specify the types for the corresponding bind variables: Type
  1124. * specification chars Character Description i corresponding
  1125. * variable has type integer d corresponding variable has type double
  1126. * s corresponding variable has type string b corresponding
  1127. * variable is a blob and will be sent in packets
  1128. * @param mixed $var1 - The number of variables and length of string
  1129. * types must match the parameters in the statement.
  1130. * @param mixed ... -
  1131. *
  1132. * @return bool -
  1133. */
  1134. <<__Native("ActRec", "VariadicByRef")>>
  1135. public function bind_param(string $types, ...): mixed;
  1136. /**
  1137. * Binds variables to a prepared statement for result storage
  1138. *
  1139. * @param mixed $var1 - The variable to be bound.
  1140. * @param mixed ... -
  1141. *
  1142. * @return bool -
  1143. */
  1144. <<__Native("ActRec", "VariadicByRef")>>
  1145. public function bind_result(...): mixed;
  1146. /**
  1147. * Closes a prepared statement
  1148. *
  1149. * @return bool -
  1150. */
  1151. <<__Native>>
  1152. public function close(): mixed;
  1153. /**
  1154. * Seeks to an arbitrary row in statement result set
  1155. *
  1156. * @param int $offset - Must be between zero and the total number of
  1157. * rows minus one (0.. mysqli_stmt_num_rows() - 1).
  1158. *
  1159. * @return void -
  1160. */
  1161. <<__Native>>
  1162. public function data_seek(int $offset): void;
  1163. /**
  1164. * Executes a prepared Query
  1165. *
  1166. * @return bool -
  1167. */
  1168. <<__Native>>
  1169. public function execute(): mixed;
  1170. /**
  1171. * Fetch results from a prepared statement into the bound variables
  1172. *
  1173. * @return bool - Value Description TRUE Success. Data has been
  1174. * fetched FALSE Error occurred NULL No more rows/data exists or
  1175. * data truncation occurred
  1176. */
  1177. <<__Native>>
  1178. public function fetch(): mixed;
  1179. /**
  1180. * Frees stored result memory for the given statement handle
  1181. *
  1182. * @return void -
  1183. */
  1184. <<__Native>>
  1185. public function free_result(): void;
  1186. /**
  1187. * Gets a result set from a prepared statement
  1188. *
  1189. * @return mysqli_result - Returns a resultset .
  1190. */
  1191. //public function get_result(): mysqli_result {
  1192. // return $this->__link->use_result();
  1193. //}
  1194. /**
  1195. * Get result of SHOW WARNINGS
  1196. *
  1197. * @param mysqli_stmt $stmt -
  1198. *
  1199. * @return object -
  1200. */
  1201. public function get_warnings(): mixed {
  1202. return $this->__link->get_warnings();
  1203. }
  1204. /**
  1205. * Check if there are more query results from a multiple query
  1206. *
  1207. * @return bool - Returns TRUE if more results exist, otherwise FALSE.
  1208. */
  1209. //public function more_results(): bool {
  1210. // return $this->__link->more_results();
  1211. //}
  1212. /**
  1213. * Reads the next result from a multiple query
  1214. *
  1215. * @return bool -
  1216. */
  1217. //public function next_result(): bool {
  1218. // return $this->__link->next_results();
  1219. //}
  1220. /**
  1221. * Prepare an SQL statement for execution
  1222. *
  1223. * @param string $query - The query, as a string. It must consist of a
  1224. * single SQL statement. You can include one or more parameter
  1225. * markers in the SQL statement by embedding question mark (?)
  1226. * characters at the appropriate positions. You should not add a
  1227. * terminating semicolon or \g to the statement. The markers are
  1228. * legal only in certain places in SQL statements. For example, they
  1229. * are allowed in the VALUES() list of an INSERT statement (to specify
  1230. * column values for a row), or in a comparison with a column in a
  1231. * WHERE clause to specify a comparison value. However, they are not
  1232. * allowed for identifiers (such as table or column names), in the
  1233. * select list that names the columns to be returned by a SELECT
  1234. * statement), or to specify both operands of a binary operator such as
  1235. * the = equal sign. The latter restriction is necessary because it
  1236. * would be impossible to determine the parameter type. In general,
  1237. * parameters are legal only in Data Manipulation Language (DML)
  1238. * statements, and not in Data Definition Language (DDL) statements.
  1239. *
  1240. * @return mixed -
  1241. */
  1242. <<__Native>>
  1243. public function prepare(string $query): mixed;
  1244. /**
  1245. * Resets a prepared statement
  1246. *
  1247. * @return bool -
  1248. */
  1249. <<__Native>>
  1250. public function reset(): mixed;
  1251. /**
  1252. * Returns result set metadata from a prepared statement
  1253. *
  1254. * @return mysqli_result - Returns a result object or FALSE if an error
  1255. * occurred.
  1256. */
  1257. <<__Native>>
  1258. public function result_metadata(): mixed;
  1259. /**
  1260. * Send data in blocks
  1261. *
  1262. * @param int $param_nr - Indicates which parameter to associate the
  1263. * data with. Parameters are numbered beginning with 0.
  1264. * @param string $data - A string containing data to be sent.
  1265. *
  1266. * @return bool -
  1267. */
  1268. <<__Native>>
  1269. public function send_long_data(int $param_nr, string $data): mixed;
  1270. /**
  1271. * Transfers a result set from a prepared statement
  1272. *
  1273. * @return bool -
  1274. */
  1275. public function store_result(): mixed {
  1276. // First we need to set the MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH attribute in
  1277. // some cases.
  1278. if ($this->__link->field_count > 0) {
  1279. $result = $this->result_metadata();
  1280. if (!is_bool($result)) {
  1281. $fields = $result->fetch_fields();
  1282. foreach ($fields as $field) {
  1283. if ($field->type == MYSQLI_TYPE_BLOB ||
  1284. $field->type == MYSQLI_TYPE_MEDIUM_BLOB ||
  1285. $field->type == MYSQLI_TYPE_LONG_BLOB ||
  1286. $field->type == MYSQLI_TYPE_GEOMETRY) {
  1287. $this->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1);
  1288. break;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. return $this->hh_store_result();
  1294. }
  1295. <<__Native>>
  1296. public function hh_store_result(): mixed;
  1297. }
  1298. /**
  1299. * Represents a MySQL warning.
  1300. */
  1301. class mysqli_warning {
  1302. public string $message;
  1303. public string $sqlstate = "HY000";
  1304. public int $errno;
  1305. private $__warnings;
  1306. /**
  1307. * The __construct purpose
  1308. *
  1309. * @return -
  1310. */
  1311. public function __construct(array $warnings): void {
  1312. $this->__warnings = $warnings;
  1313. $this->next();
  1314. }
  1315. /**
  1316. * The next purpose
  1317. *
  1318. * @return bool -
  1319. */
  1320. public function next(): bool {
  1321. if (!$this->__warnings) {
  1322. return false;
  1323. }
  1324. $next = array_shift($this->__warnings);
  1325. $this->message = $next['Message'];
  1326. $this->errno = (int)$next['Code'];
  1327. return true;
  1328. }
  1329. }
  1330. /**
  1331. * Returns client Zval cache statistics
  1332. *
  1333. * @return array - Returns an array with client Zval cache stats if
  1334. * success, FALSE otherwise.
  1335. */
  1336. //function mysqli_get_cache_stats(): array {
  1337. // throw NotSupportedException(__func__, "deprecated and removed");
  1338. //}
  1339. /**
  1340. * Gets the number of affected rows in a previous MySQL operation
  1341. *
  1342. * @param mysqli $link -
  1343. *
  1344. * @return int - An integer greater than zero indicates the number of
  1345. * rows affected or retrieved. Zero indicates that no records were
  1346. * updated for an UPDATE statement, no rows matched the WHERE clause in
  1347. * the query or that no query has yet been executed. -1 indicates that
  1348. * the query returned an error. If the number of affected rows is
  1349. * greater than the maximum integer value( PHP_INT_MAX ), the number of
  1350. * affected rows will be returned as a string.
  1351. */
  1352. function mysqli_affected_rows(mysqli $link): ?int {
  1353. return $link->affected_rows;
  1354. }
  1355. /**
  1356. * Turns on or off auto-committing database modifications
  1357. *
  1358. * @param mysqli $link -
  1359. * @param bool $mode - Whether to turn on auto-commit or not.
  1360. *
  1361. * @return bool -
  1362. */
  1363. function mysqli_autocommit(mysqli $link, bool $mode): bool {
  1364. return $link->autocommit($mode);
  1365. }
  1366. /**
  1367. * Starts a transaction
  1368. *
  1369. * @param mysqli $link -
  1370. * @param int $flags -
  1371. * @param string $name -
  1372. *
  1373. * @return bool -
  1374. */
  1375. function mysqli_begin_transaction(mysqli $link,
  1376. int $flags = 0,
  1377. ?string $name = null): bool {
  1378. return $link->begin_transaction($flags, $name);
  1379. }
  1380. function mysqli_connect(?string $host = null,
  1381. ?string $username = null,
  1382. ?string $passwd = null,
  1383. ?string $dbname = null,
  1384. mixed $port = null,
  1385. ?string $socket = null): mixed {
  1386. $link = new mysqli($host, $username, $passwd, $dbname, $port, $socket);
  1387. if ($link->connect_errno > 0) {
  1388. return false;
  1389. }
  1390. return $link;
  1391. }
  1392. /**
  1393. * Changes the user of the specified database connection
  1394. *
  1395. * @param mysqli $link -
  1396. * @param string $user - The MySQL user name.
  1397. * @param string $password - The MySQL password.
  1398. * @param string $database - The database to change to. If desired, the
  1399. * NULL value may be passed resulting in only changing the user and not
  1400. * selecting a database. To select a database in this case use the
  1401. * mysqli_select_db() function.
  1402. *
  1403. * @return bool -
  1404. */
  1405. function mysqli_change_user(mysqli $link,
  1406. string $user,
  1407. string $password,
  1408. string $database): bool {
  1409. return $link->change_user($user, $password, $database);
  1410. }
  1411. /**
  1412. * Returns the default character set for the database connection
  1413. *
  1414. * @param mysqli $link -
  1415. *
  1416. * @return string - The default character set for the current connection
  1417. */
  1418. function mysqli_character_set_name(mysqli $link): string {
  1419. return $link->character_set_name();
  1420. }
  1421. /**
  1422. * Get MySQL client info
  1423. *
  1424. * @param mysqli $link -
  1425. *
  1426. * @return string - A string that represents the MySQL client library
  1427. * version
  1428. */
  1429. <<__Native>>
  1430. function mysqli_get_client_info(): string;
  1431. /**
  1432. * Returns the MySQL client version as an integer
  1433. *
  1434. * @param mysqli $link -
  1435. *
  1436. * @return int - A number that represents the MySQL client library
  1437. * version in format: main_version*10000 + minor_version *100 +
  1438. * sub_version. For example, 4.1.0 is returned as 40100. This is useful
  1439. * to quickly determine the version of the client library to know if some
  1440. * capability exits.
  1441. */
  1442. <<__Native>>
  1443. function mysqli_get_client_version(): int;
  1444. /**
  1445. * Closes a previously opened database connection
  1446. *
  1447. * …

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