PageRenderTime 66ms CodeModel.GetById 7ms 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
  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. * @param mysqli $link -
  1448. *
  1449. * @return bool -
  1450. */
  1451. function mysqli_close(mysqli $link): bool {
  1452. return $link->close();
  1453. }
  1454. /**
  1455. * Commits the current transaction
  1456. *
  1457. * @param mysqli $link -
  1458. * @param int $flags - A bitmask of MYSQLI_TRANS_COR_* constants.
  1459. * @param string $name - If provided then COMMIT{name} is executed.
  1460. *
  1461. * @return bool -
  1462. */
  1463. function mysqli_commit(mysqli $link, int $flags = 0,
  1464. ?string $name = null): bool {
  1465. return $link->commit($flags, $name);
  1466. }
  1467. /**
  1468. * Returns the error code from last connect call
  1469. *
  1470. * @return int - An error code value for the last call to
  1471. * mysqli_connect(), if it failed. zero means no error occurred.
  1472. */
  1473. function mysqli_connect_errno(): int {
  1474. return mysqli::$__connection_errno;
  1475. }
  1476. /**
  1477. * Returns a string description of the last connect error
  1478. *
  1479. * @return string - A string that describes the error. NULL is returned
  1480. * if no error occurred.
  1481. */
  1482. function mysqli_connect_error(): ?string {
  1483. return mysqli::$__connection_error;
  1484. }
  1485. /**
  1486. * Performs debugging operations
  1487. *
  1488. * @param string $message - A string representing the debugging operation
  1489. * to perform
  1490. *
  1491. * @return bool - Returns TRUE.
  1492. */
  1493. //function mysqli_debug(string $message): bool {
  1494. // throw 'NOT IMPLEMENTED';
  1495. //}
  1496. /**
  1497. * Dump debugging information into the log
  1498. *
  1499. * @param mysqli $link -
  1500. *
  1501. * @return bool -
  1502. */
  1503. function mysqli_dump_debug_info(mysqli $link): mixed {
  1504. return $link->dump_debug_info();
  1505. }
  1506. /**
  1507. * Returns the error code for the most recent function call
  1508. *
  1509. * @param mysqli $link -
  1510. *
  1511. * @return int - An error code value for the last call, if it failed.
  1512. * zero means no error occurred.
  1513. */
  1514. function mysqli_errno(mysqli $link): ?int {
  1515. return $link->errno;
  1516. }
  1517. /**
  1518. * Returns a list of errors from the last command executed
  1519. *
  1520. * @param mysqli $link -
  1521. *
  1522. * @return array - A list of errors, each as an associative array
  1523. * containing the errno, error, and sqlstate.
  1524. */
  1525. function mysqli_error_list(mysqli $link): array {
  1526. return $link->error_list;
  1527. }
  1528. /**
  1529. * Returns a string description of the last error
  1530. *
  1531. * @param mysqli $link -
  1532. *
  1533. * @return string - A string that describes the error. An empty string if
  1534. * no error occurred.
  1535. */
  1536. function mysqli_error(mysqli $link): ?string {
  1537. return $link->error;
  1538. }
  1539. /**
  1540. * Returns the number of columns for the most recent query
  1541. *
  1542. * @param mysqli $link -
  1543. *
  1544. * @return int - An integer representing the number of fields in a result
  1545. * set.
  1546. */
  1547. function mysqli_field_count(mysqli $link): ?int {
  1548. return $link->field_count;
  1549. }
  1550. /**
  1551. * Returns a character set object
  1552. *
  1553. * @param mysqli $link -
  1554. *
  1555. * @return object - The function returns a character set object with the
  1556. * following properties:
  1557. * - charset Character set name
  1558. * - collation Collation name
  1559. * - dir Directory the charset description was fetched from (?) or "" for
  1560. * built-in character sets
  1561. * - min_length Minimum character length in bytes
  1562. * - max_length Maximum character length in bytes
  1563. * - number Internal character set number
  1564. * - state Character set status (?)
  1565. */
  1566. function mysqli_get_charset(mysqli $link): mixed {
  1567. return $link->get_charset();
  1568. }
  1569. /**
  1570. * Returns client per-process statistics
  1571. *
  1572. * @return array - Returns an array with client stats if success, FALSE
  1573. * otherwise.
  1574. */
  1575. //<<__Native>>
  1576. //function mysqli_get_client_stats(): array;
  1577. /**
  1578. * Returns statistics about the client connection
  1579. *
  1580. * @param mysqli $link -
  1581. *
  1582. * @return array - Returns an array with connection stats if success,
  1583. * FALSE otherwise.
  1584. */
  1585. //function mysqli_get_connection_stats(mysqli $link): mixed {
  1586. // return $link->get_connection_stats();
  1587. //}
  1588. /**
  1589. * Returns a string representing the type of connection used
  1590. *
  1591. * @param mysqli $link -
  1592. *
  1593. * @return string - A character string representing the server hostname
  1594. * and the connection type.
  1595. */
  1596. function mysqli_get_host_info(mysqli $link): ?string {
  1597. return $link->host_info;
  1598. }
  1599. /**
  1600. * Returns the version of the MySQL protocol used
  1601. *
  1602. * @param mysqli $link -
  1603. *
  1604. * @return int - Returns an integer representing the protocol version.
  1605. */
  1606. function mysqli_get_proto_info(mysqli $link): int {
  1607. return (int)$link->protocol_version;
  1608. }
  1609. /**
  1610. * Returns the version of the MySQL server
  1611. *
  1612. * @param mysqli $link -
  1613. *
  1614. * @return string - A character string representing the server version.
  1615. */
  1616. function mysqli_get_server_info(mysqli $link): ?string {
  1617. return $link->server_info;
  1618. }
  1619. /**
  1620. * Returns the version of the MySQL server as an integer
  1621. *
  1622. * @param mysqli $link -
  1623. *
  1624. * @return int - An integer representing the server version. The form
  1625. * of this version number is main_version * 10000 + minor_version * 100 +
  1626. * sub_version (i.e. version 4.1.0 is 40100).
  1627. */
  1628. function mysqli_get_server_version(mysqli $link): ?int {
  1629. return $link->server_version;
  1630. }
  1631. /**
  1632. * Get result of SHOW WARNINGS
  1633. *
  1634. * @param mysqli $link -
  1635. *
  1636. * @return mysqli_warning -
  1637. */
  1638. function mysqli_get_warnings(mysqli $link): mixed {
  1639. return $link->get_warnings();
  1640. }
  1641. /**
  1642. * Retrieves information about the most recently executed query
  1643. *
  1644. * @param mysqli $link -
  1645. *
  1646. * @return string - A character string representing additional
  1647. * information about the most recently executed query.
  1648. */
  1649. function mysqli_info(mysqli $link): ?string {
  1650. return $link->info;
  1651. }
  1652. /**
  1653. * Initializes MySQLi and returns a resource for use with
  1654. * mysqli_real_connect()
  1655. *
  1656. * @return mysqli - Returns an object.
  1657. */
  1658. function mysqli_init(): mysqli {
  1659. return new mysqli();
  1660. }
  1661. /**
  1662. * Returns the auto generated id used in the last query
  1663. *
  1664. * @param mysqli $link -
  1665. *
  1666. * @return mixed - The value of the AUTO_INCREMENT field that was updated
  1667. * by the previous query. Returns zero if there was no previous query on
  1668. * the connection or if the query did not update an AUTO_INCREMENT value.
  1669. * If the number is greater than maximal int value, mysqli_insert_id()
  1670. * will return a string.
  1671. */
  1672. function mysqli_insert_id(mysqli $link): mixed {
  1673. return $link->insert_id;
  1674. }
  1675. /**
  1676. * Asks the server to kill a MySQL thread
  1677. *
  1678. * @param mysqli $link -
  1679. * @param int $processid -
  1680. *
  1681. * @return bool -
  1682. */
  1683. function mysqli_kill(mysqli $link, int $processid): bool {
  1684. return $link->kill($processid);
  1685. }
  1686. /**
  1687. * Check if there are any more query results from a multi query
  1688. *
  1689. * @param mysqli $link -
  1690. *
  1691. * @return bool - Returns TRUE if one or more result sets are available
  1692. * from a previous call to mysqli_multi_query(), otherwise FALSE.
  1693. */
  1694. function mysqli_more_results(mysqli $link): bool {
  1695. return $link->more_results();
  1696. }
  1697. /**
  1698. * Performs a query on the database
  1699. *
  1700. * @param mysqli $link -
  1701. * @param string $query - The query, as a string. Data inside the query
  1702. * should be properly escaped.
  1703. *
  1704. * @return bool - Returns FALSE if the first statement failed. To
  1705. * retrieve subsequent errors from other statements you have to call
  1706. * mysqli_next_result() first.
  1707. */
  1708. function mysqli_multi_query(mysqli $link, string $query): bool {
  1709. return $link->multi_query($query);
  1710. }
  1711. /**
  1712. * Prepare next result from multi_query
  1713. *
  1714. * @param mysqli $link -
  1715. *
  1716. * @return bool -
  1717. */
  1718. function mysqli_next_result(mysqli $link): bool {
  1719. return $link->next_result();
  1720. }
  1721. /**
  1722. * Set options
  1723. *
  1724. * @param mysqli $link -
  1725. * @param int $option - The option that you want to set. It can be one of
  1726. * the following values: Valid options Name Description
  1727. * MYSQLI_OPT_CONNECT_TIMEOUT connection timeout in seconds (supported on
  1728. * Windows with TCP/IP since PHP 5.3.1) MYSQLI_OPT_LOCAL_INFILE
  1729. * enable/disable use of LOAD LOCAL INFILE MYSQLI_INIT_COMMAND command
  1730. * to execute after when connecting to MySQL server
  1731. * MYSQLI_READ_DEFAULT_FILE Read options from named option file instead
  1732. * of my.cnf MYSQLI_READ_DEFAULT_GROUP Read options from the named
  1733. * group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
  1734. * MYSQLI_SERVER_PUBLIC_KEY RSA public key file used with the SHA-256
  1735. * based authentication.
  1736. * @param mixed $value - The value for the option.
  1737. *
  1738. * @return bool -
  1739. */
  1740. function mysqli_options(mysqli $link, int $option, mixed $value): mixed {
  1741. return $link->options($option, $value);
  1742. }
  1743. /**
  1744. * Pings a server connection, or tries to reconnect if the connection has gone
  1745. * down
  1746. *
  1747. * @param mysqli $link -
  1748. *
  1749. * @return bool -
  1750. */
  1751. function mysqli_ping(mysqli $link): ?bool {
  1752. return $link->ping();
  1753. }
  1754. /**
  1755. * Poll connections
  1756. *
  1757. * @param array $read - List of connections to check for outstanding
  1758. * results that can be read.
  1759. * @param array $error - List of connections on which an error occurred,
  1760. * for example, query failure or lost connection.
  1761. * @param array $reject - List of connections rejected because no
  1762. * asynchronous query has been run on for which the function could poll
  1763. * results.
  1764. * @param int $sec - Number of seconds to wait, must be non-negative.
  1765. * @param int $usec - Number of microseconds to wait, must be
  1766. * non-negative.
  1767. *
  1768. * @return int - Returns number of ready connections upon success, FALSE
  1769. * otherwise.
  1770. */
  1771. //function mysqli_poll(array &$read,
  1772. // array &$error,
  1773. // array &$reject,
  1774. // int $sec,
  1775. // int $usec): int {
  1776. // return mysqli::poll($read, $error, $reject, $sec, $usec);
  1777. //}
  1778. /**
  1779. * Prepare an SQL statement for execution
  1780. *
  1781. * @param mysqli $link -
  1782. * @param string $query - The query, as a string. You should not add a
  1783. * terminating semicolon or \g to the statement. This parameter can
  1784. * include one or more parameter markers in the SQL statement by
  1785. * embedding question mark (?) characters at the appropriate positions.
  1786. * The markers are legal only in certain places in SQL statements. For
  1787. * example, they are allowed in the VALUES() list of an INSERT statement
  1788. * (to specify column values for a row), or in a comparison with a column
  1789. * in a WHERE clause to specify a comparison value. However, they are
  1790. * not allowed for identifiers (such as table or column names), in the
  1791. * select list that names the columns to be returned by a SELECT
  1792. * statement, or to specify both operands of a binary operator such as
  1793. * the = equal sign. The latter restriction is necessary because it would
  1794. * be impossible to determine the parameter type. It's not allowed to
  1795. * compare marker with NULL by ? IS NULL too. In general, parameters are
  1796. * legal only in Data Manipulation Language (DML) statements, and not in
  1797. * Data Definition Language (DDL) statements.
  1798. *
  1799. * @return mysqli_stmt - mysqli_prepare() returns a statement object or
  1800. * FALSE if an error occurred.
  1801. */
  1802. function mysqli_prepare(mysqli $link, string $query): mixed {
  1803. return $link->prepare($query);
  1804. }
  1805. /**
  1806. * Performs a query on the database
  1807. *
  1808. * @param mysqli $link -
  1809. * @param string $query - The query string. Data inside the query
  1810. * should be properly escaped.
  1811. * @param int $resultmode - Either the constant MYSQLI_USE_RESULT or
  1812. * MYSQLI_STORE_RESULT depending on the desired behavior. By default,
  1813. * MYSQLI_STORE_RESULT is used. If you use MYSQLI_USE_RESULT all
  1814. * subsequent calls will return error Commands out of sync unless you
  1815. * call mysqli_free_result() With MYSQLI_ASYNC (available with
  1816. * mysqlnd), it is possible to perform query asynchronously.
  1817. * mysqli_poll() is then used to get results from such queries.
  1818. *
  1819. * @return mixed - Returns FALSE on failure. For successful SELECT, SHOW,
  1820. * DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result
  1821. * object. For other successful queries mysqli_query() will return TRUE.
  1822. */
  1823. function mysqli_query(mysqli $link,
  1824. string $query,
  1825. int $resultmode = MYSQLI_STORE_RESULT): mixed {
  1826. return $link->query($query, $resultmode);
  1827. }
  1828. /**
  1829. * Opens a connection to a mysql server
  1830. *
  1831. * @param mysqli $link -
  1832. * @param string $host - Can be either a host name or an IP address.
  1833. * Passing the NULL value or the string "localhost" to this parameter,
  1834. * the local host is assumed. When possible, pipes will be used instead
  1835. * of the TCP/IP protocol.
  1836. * @param string $username - The MySQL user name.
  1837. * @param string $passwd - If provided or NULL, the MySQL server will
  1838. * attempt to authenticate the user against those user records which have
  1839. * no password only. This allows one username to be used with different
  1840. * permissions (depending on if a password as provided or not).
  1841. * @param string $dbname - If provided will specify the default database
  1842. * to be used when performing queries.
  1843. * @param mixed $port - Specifies the port number to attempt to connect to
  1844. * the MySQL server.
  1845. * @param string $socket - Specifies the socket or named pipe that should
  1846. * be used. Specifying the socket parameter will not explicitly
  1847. * determine the type of connection to be used when connecting to the
  1848. * MySQL server. How the connection is made to the MySQL database is
  1849. * determined by the host parameter.
  1850. * @param int $flags - With the parameter flags you can set different
  1851. * connection options: Supported flags Name Description
  1852. * MYSQLI_CLIENT_COMPRESS Use compression protocol
  1853. * MYSQLI_CLIENT_FOUND_ROWS return number of matched rows, not the number
  1854. * of affected rows MYSQLI_CLIENT_IGNORE_SPACE Allow spaces after
  1855. * function names. Makes all function names reserved words.
  1856. * MYSQLI_CLIENT_INTERACTIVE Allow interactive_timeout seconds (instead
  1857. * of wait_timeout seconds) of inactivity before closing the connection
  1858. * MYSQLI_CLIENT_SSL Use SSL (encryption) For security reasons the
  1859. * MULTI_STATEMENT flag is not supported in PHP. If you want to execute
  1860. * multiple queries use the mysqli_multi_query() function.
  1861. *
  1862. * @return bool -
  1863. */
  1864. function mysqli_real_connect(mysqli $link,
  1865. ?string $host = null,
  1866. ?string $username = null,
  1867. ?string $passwd = null,
  1868. ?string $dbname = null,
  1869. mixed $port = null,
  1870. ?string $socket = null,
  1871. ?int $flags = 0): bool {
  1872. return $link->real_connect($host, $username, $passwd, $dbname, $port, $socket,
  1873. $flags);
  1874. }
  1875. /**
  1876. * Alias of mysqli_real_escape_string
  1877. */
  1878. function mysqli_escape_string(mysqli $link, $escapestr): ?string {
  1879. return mysqli_real_escape_string($link, $escapestr);
  1880. }
  1881. /**
  1882. * Escapes special characters in a string for use in an SQL statement, taking
  1883. * into account the current charset of the connection
  1884. *
  1885. * @param mysqli $link -
  1886. * @param string $escapestr - The string to be escaped. Characters
  1887. * encoded are NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
  1888. *
  1889. * @return string - Returns an escaped string.
  1890. */
  1891. function mysqli_real_escape_string(mysqli $link, $escapestr): ?string {
  1892. return $link->real_escape_string($escapestr);
  1893. }
  1894. /**
  1895. * Execute an SQL query
  1896. *
  1897. * @param mysqli $link -
  1898. * @param string $query - The query, as a string. Data inside the query
  1899. * should be properly escaped.
  1900. *
  1901. * @return bool -
  1902. */
  1903. function mysqli_real_query(mysqli $link, string $query): bool {
  1904. return $link->real_query($query);
  1905. }
  1906. /**
  1907. * Get result from async query
  1908. *
  1909. * @param mysql $link -
  1910. *
  1911. * @return mysqli_result - Returns mysqli_result in success, FALSE
  1912. * otherwise.
  1913. */
  1914. //function mysqli_reap_async_query(mysqli $link): mysqli_result {
  1915. // return $link->reap_async_query();
  1916. //}
  1917. /**
  1918. * Refreshes
  1919. *
  1920. * @param resource $link -
  1921. * @param int $options - The options to refresh, using the
  1922. * MYSQLI_REFRESH_* constants as documented within the MySQLi constants
  1923. * documentation. See also the official MySQL Refresh documentation.
  1924. *
  1925. * @return int - TRUE if the refresh was a success, otherwise FALSE
  1926. */
  1927. function mysqli_refresh(mysqli $link, int $options): int {
  1928. return $link->refresh($options);
  1929. }
  1930. /**
  1931. * Rolls back a transaction to the named savepoint
  1932. *
  1933. * @param mysqli $link -
  1934. * @param string $name -
  1935. *
  1936. * @return bool -
  1937. */
  1938. function mysqli_release_savepoint(mysqli $link, string $name): bool {
  1939. return $link->release_savepoint($name);
  1940. }
  1941. /**
  1942. * Rolls back current transaction
  1943. *
  1944. * @param mysqli $link -
  1945. * @param int $flags - A bitmask of MYSQLI_TRANS_COR_* constants.
  1946. * @param string $name - If provided then ROLLBACK{name} is executed.
  1947. *
  1948. * @return bool -
  1949. */
  1950. function mysqli_rollback(mysqli $link, int $flags = 0,
  1951. ?string $name = null): ?bool {
  1952. return $link->rollback($flags, $name);
  1953. }
  1954. /**
  1955. * Set a named transaction savepoint
  1956. *
  1957. * @param mysqli $link -
  1958. * @param string $name -
  1959. *
  1960. * @return bool -
  1961. */
  1962. function mysqli_savepoint(mysqli $link, string $name): bool {
  1963. return $link->savepoint($name);
  1964. }
  1965. /**
  1966. * Selects the default database for database queries
  1967. *
  1968. * @param mysqli $link -
  1969. * @param string $dbname - The database name.
  1970. *
  1971. * @return bool -
  1972. */
  1973. function mysqli_select_db(mysqli $link, string $dbname): ?bool {
  1974. return $link->select_db($dbname);
  1975. }
  1976. /**
  1977. * Send the query and return
  1978. *
  1979. * @param mysqli $link -
  1980. * @param string $query -
  1981. *
  1982. * @return bool -
  1983. */
  1984. //function mysqli_send_query(mysqli $link, string $query): bool {
  1985. // return $link->send_query($query);
  1986. //}
  1987. /**
  1988. * Sets the default client character set
  1989. *
  1990. * @param mysqli $link -
  1991. * @param string $charset - The charset to be set as default.
  1992. *
  1993. * @return bool -
  1994. */
  1995. function mysqli_set_charset(mysqli $link, string $charset): mixed {
  1996. return $link->set_charset($charset);
  1997. }
  1998. /**
  1999. * Unsets user defined handler for load local infile command
  2000. *
  2001. * @param mysqli $link -
  2002. *
  2003. * @return void -
  2004. */
  2005. //<<__Native>>
  2006. //function mysqli_set_local_infile_default(mysqli $link): void;
  2007. /**
  2008. * Set callback function for LOAD DATA LOCAL INFILE command
  2009. *
  2010. * @param mysqli $link -
  2011. * @param callable $read_func - A callback function or object method
  2012. * taking the following parameters: stream A PHP stream associated
  2013. * with the SQL commands INFILE buffer A string buffer to store the
  2014. * rewritten input into buflen The maximum number of characters to be
  2015. * stored in the buffer errormsg If an error occurs you can store an
  2016. * error message in here
  2017. *
  2018. * @return bool -
  2019. */
  2020. //function mysqli_set_local_infile_handler(mysqli $link,
  2021. // callable $read_func): bool {
  2022. // $link->set_local_infile_handler($read_func);
  2023. //}
  2024. /**
  2025. * Returns the SQLSTATE error from previous MySQL operation
  2026. *
  2027. * @param mysqli $link -
  2028. *
  2029. * @return string - Returns a string containing the SQLSTATE error code
  2030. * for the last error. The error code consists of five characters.
  2031. * '00000' means no error.
  2032. */
  2033. function mysqli_sqlstate(mysqli $link): ?string {
  2034. return $link->sqlstate;
  2035. }
  2036. /**
  2037. * Used for establishing secure connections using SSL
  2038. *
  2039. * @param mysqli $link -
  2040. * @param string $key - The path name to the key file.
  2041. * @param string $cert - The path name to the certificate file.
  2042. * @param string $ca - The path name to the certificate authority file.
  2043. * @param string $capath - The pathname to a directory that contains
  2044. * trusted SSL CA certificates in PEM format.
  2045. * @param string $cipher - A list of allowable ciphers to use for SSL
  2046. * encryption.
  2047. *
  2048. * @return bool - This function always returns TRUE value. If SSL setup
  2049. * is incorrect mysqli_real_connect() will return an error when you
  2050. * attempt to connect.
  2051. */
  2052. function mysqli_ssl_set(mysqli $link,
  2053. ?string $key,
  2054. ?string $cert,
  2055. ?string $ca,
  2056. ?string $capath,
  2057. ?string $cipher): bool {
  2058. return $link->ssl_set($key, $cert, $ca, $capath, $cipher);
  2059. }
  2060. /**
  2061. * Gets the current system status
  2062. *
  2063. * @param mysqli $link -
  2064. *
  2065. * @return string - A string describing the server status. FALSE if an
  2066. * error occurred.
  2067. */
  2068. function mysqli_stat(mysqli $link): ?string {
  2069. return $link->stat();
  2070. }
  2071. /**
  2072. * Initializes a statement and returns an object for use with
  2073. * mysqli_stmt_prepare
  2074. *
  2075. * @param mysqli $link -
  2076. *
  2077. * @return mysqli_stmt - Returns an object.
  2078. */
  2079. function mysqli_stmt_init(mysqli $link): mysqli_stmt {
  2080. return $link->stmt_init();
  2081. }
  2082. /**
  2083. * Transfers a result set from the last query
  2084. *
  2085. * @param mysqli $link -
  2086. *
  2087. * @return mysqli_result - Returns a buffered result object or FALSE if
  2088. * an error occurred. mysqli_store_result() returns FALSE in case the
  2089. * query didn't return a result set (if the query was, for example an
  2090. * INSERT statement). This function also returns FALSE if the reading of
  2091. * the result set failed. You can check if you have got an error by
  2092. * checking if mysqli_error() doesn't return an empty string, if
  2093. * mysqli_errno() returns a non zero value, or if mysqli_field_count()
  2094. * returns a non zero value. Also possible reason for this function
  2095. * returning FALSE after successful call to mysqli_query() can be too
  2096. * large result set (memory for it cannot be allocated). If
  2097. * mysqli_field_count() returns a non-zero value, the statement should
  2098. * have produced a non-empty result set.
  2099. */
  2100. function mysqli_store_result(mysqli $link): mysqli_result {
  2101. return $link->store_result();
  2102. }
  2103. /**
  2104. * Returns the thread ID for the current connection
  2105. *
  2106. * @param mysqli $link -
  2107. *
  2108. * @return int - Returns the Thread ID for the current connection.
  2109. */
  2110. function mysqli_thread_id(mysqli $link): ?int {
  2111. return $link->thread_id;
  2112. }
  2113. /**
  2114. * Returns whether thread safety is given or not
  2115. *
  2116. * @return bool - TRUE if the client library is thread-safe, otherwise
  2117. * FALSE.
  2118. */
  2119. <<__Native>>
  2120. function mysqli_thread_safe(): bool;
  2121. /**
  2122. * Initiate a result set retrieval
  2123. *
  2124. * @param mysqli $link -
  2125. *
  2126. * @return mysqli_result - Returns an unbuffered result object or FALSE
  2127. * if an error occurred.
  2128. */
  2129. function mysqli_use_result(mysqli $link): ?mixed {
  2130. return $link->use_result();
  2131. }
  2132. /**
  2133. * Returns the number of warnings from the last query for the given link
  2134. *
  2135. * @param mysqli $link -
  2136. *
  2137. * @return int - Number of warnings or zero if there are no warnings.
  2138. */
  2139. function mysqli_warning_count(mysqli $link): ?int {
  2140. return $link->warning_count;
  2141. }
  2142. /**
  2143. * Enables or disables internal report functions
  2144. *
  2145. * @param int $flags - Supported flags Name Description
  2146. * MYSQLI_REPORT_OFF Turns reporting off MYSQLI_REPORT_ERROR Report
  2147. * errors from mysqli function calls MYSQLI_REPORT_STRICT Throw
  2148. * mysqli_sql_exception for errors instead of warnings
  2149. * MYSQLI_REPORT_INDEX Report if no index or bad index was used in a
  2150. * query MYSQLI_REPORT_ALL Set all options (report all)
  2151. *
  2152. * @return bool -
  2153. */
  2154. function mysqli_report(int $flags): bool {
  2155. (new mysqli_driver())->report_mode = $flags;
  2156. return true;
  2157. }
  2158. /**
  2159. * Alias of mysqli_options
  2160. */
  2161. function mysqli_set_opt(mysqli $link, int $option, mixed $value): mixed {
  2162. return mysqli_options($link, $option, $value);
  2163. }
  2164. /**
  2165. * Get current field offset of a result pointer
  2166. *
  2167. * @param mysqli_result $result -
  2168. *
  2169. * @return int - Returns current offset of field cursor.
  2170. */
  2171. function mysqli_field_tell(mysqli_result $result): int {
  2172. return $result->current_field;
  2173. }
  2174. /**
  2175. * Adjusts the result pointer to an arbitrary row in the result
  2176. *
  2177. * @param mysqli_result $result -
  2178. * @param int $offset - The field offset. Must be between zero and the
  2179. * total number of rows minus one (0..mysqli_num_rows() - 1).
  2180. *
  2181. * @return bool -
  2182. */
  2183. function mysqli_data_seek(mysqli_result $result, int $offset): mixed {
  2184. return $result->data_seek($offset);
  2185. }
  2186. /**
  2187. * Fetches all result rows as an associative array, a numeric array, or both
  2188. *
  2189. * @param mysqli_result $result -
  2190. * @param int $resulttype - This optional parameter is a constant
  2191. * indicating what type of array should be produced from the current row
  2192. * data. The possible values for this parameter are the constants
  2193. * MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.
  2194. *
  2195. * @return mixed - Returns an array of associative or numeric arrays
  2196. * holding result rows.
  2197. */
  2198. function mysqli_fetch_all(mysqli_result $result,
  2199. int $resulttype = MYSQLI_NUM): mixed {
  2200. return $result->fetch_all($resulttype);
  2201. }
  2202. /**
  2203. * Fetch a result row as an associative, a numeric array, or both
  2204. *
  2205. * @param mysqli_result $result -
  2206. * @param int $resulttype - This optional parameter is a constant
  2207. * indicating what type of array should be produced from the current row
  2208. * data. The possible values for this parameter are the constants
  2209. * MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH. By using the MYSQLI_ASSOC
  2210. * constant this function will behave identically to the
  2211. * mysqli_fetch_assoc(), while MYSQLI_NUM will behave identically to the
  2212. * mysqli_fetch_row() function. The final option MYSQLI_BOTH will create
  2213. * a single array with the attributes of both.
  2214. *
  2215. * @return mixed - Returns an array of strings that corresponds to the
  2216. * fetched row or NULL if there are no more rows in resultset.
  2217. */
  2218. function mysqli_fetch_array(mysqli_result $result,
  2219. int $resulttype = MYSQLI_BOTH): mixed {
  2220. return $result->fetch_array($resulttype);
  2221. }
  2222. /**
  2223. * Fetch a result row as an associative array
  2224. *
  2225. * @param mysqli_result $result -
  2226. *
  2227. * @return array - Returns an associative array of strings representing
  2228. * the fetched row in the result set, where each key in the array
  2229. * represents the name of one of the result set's columns or NULL if
  2230. * there are no more rows in resultset. If two or more columns of the
  2231. * result have the same field names, the last column will take
  2232. * precedence. To access the other column(s) of the same name, you either
  2233. * need to access the result with numeric indices by using
  2234. * mysqli_fetch_row() or add alias names.
  2235. */
  2236. function mysqli_fetch_assoc(mysqli_result $result): mixed {
  2237. return $result->fetch_assoc();
  2238. }
  2239. /**
  2240. * Fetch meta-data for a single field
  2241. *
  2242. * @param mysqli_result $result -
  2243. * @param int $fieldnr - The field number. This value must be in the
  2244. * range from 0 to number of fields - 1.
  2245. *
  2246. * @return object - Returns an object which contains field definition
  2247. * information or FALSE if no field information for specified fieldnr is
  2248. * available. Object attributes Attribute Description name The
  2249. * name of the column orgname Original column name if an alias was
  2250. * specified table The name of the table this field belongs to (if not
  2251. * calculated) orgtable Original table name if an alias was specified
  2252. * def The default value for this field, represented as a string
  2253. * max_length The maximum width of the field for the result set. length
  2254. * The width of the field, as specified in the table definition.
  2255. * charsetnr The character set number for the field. flags An integer
  2256. * representing the bit-flags for the field. type The data type used
  2257. * for this field decimals The number of decimals used (for integer
  2258. * fields)
  2259. */
  2260. function mysqli_fetch_field_direct(mysqli_result $result,
  2261. int $fieldnr): mixed {
  2262. return $result->fetch_field_direct($fieldnr);
  2263. }
  2264. /**
  2265. * Returns the next field in the result set
  2266. *
  2267. * @param mysqli_result $result -
  2268. *
  2269. * @return object - Returns an object which contains field definition
  2270. * information or FALSE if no field information is available. Object
  2271. * properties Property Description name The name of the column
  2272. * orgname Original column name if an alias was specified table The
  2273. * name of the table this field belongs to (if not calculated) orgtable
  2274. * Original table name if an alias was specified def Reserved for
  2275. * default value, currently always "" db Database (since PHP 5.3.6)
  2276. * catalog The catalog name, always "def" (since PHP 5.3.6) max_length
  2277. * The maximum width of the field for the result set. length The width
  2278. * of the field, as specified in the table definition. charsetnr The
  2279. * character set number for the field. flags An integer representing
  2280. * the bit-flags for the field. type The data type used for this field
  2281. * decimals The number of decimals used (for integer fields)
  2282. */
  2283. function mysqli_fetch_field(mysqli_result $result): mixed {
  2284. return $result->fetch_field();
  2285. }
  2286. /**
  2287. * Returns an array of objects representing the fields in a result set
  2288. *
  2289. * @param mysqli_result $result -
  2290. *
  2291. * @return array - Returns an array of objects which contains field
  2292. * definition information or FALSE if no field information is available.
  2293. * Object properties Property Description name The name of the
  2294. * column orgname Original column name if an alias was specified
  2295. * table The name of the table this field belongs to (if not calculated)
  2296. * orgtable Original table name if an alias was specified max_length
  2297. * The maximum width of the field for the result set. length The width
  2298. * of the field, as specified in the table definition. charsetnr The
  2299. * character set number for the field. flags An integer representing
  2300. * the bit-flags for the field. type The data type used for this field
  2301. * decimals The number of decimals used (for integer fields)
  2302. */
  2303. function mysqli_fetch_fields(mysqli_result $result): array {
  2304. return $result->fetch_fields();
  2305. }
  2306. /**
  2307. * Returns the current row of a result set as an object
  2308. *
  2309. * @param mysqli_result $result -
  2310. * @param string $class_name - The name of the class to instantiate, set
  2311. * the properties of and return. If not specified, a stdClass object is
  2312. * returned.
  2313. * @param array $params - An optional array of parameters to pass to the
  2314. * constructor for class_name objects.
  2315. *
  2316. * @return object - Returns an object with string properties that
  2317. * corresponds to the fetched row or NULL if there are no more rows in
  2318. * resultset.
  2319. */
  2320. function mysqli_fetch_object(mysqli_result $result,
  2321. ?string $class_name = null,
  2322. ?array $params = array()): mixed {
  2323. if (func_num_args() < 2) {
  2324. return $result->fetch_object();
  2325. }
  2326. return $result->fetch_object($class_name, $params);
  2327. }
  2328. /**
  2329. * Get a result row as an enumerated array
  2330. *
  2331. * @param mysqli_result $result -
  2332. *
  2333. * @return mixed - mysqli_fetch_row() returns an array of strings that
  2334. * corresponds to the fetched row or NULL if there are no more rows in
  2335. * result set.
  2336. */
  2337. function mysqli_fetch_row(mysqli_result $result): mixed {
  2338. return $result->fetch_row();
  2339. }
  2340. /**
  2341. * Get the number of fields in a result
  2342. *
  2343. * @param mysqli_result $result -
  2344. *
  2345. * @return int - The number of fields from a result set.
  2346. */
  2347. function mysqli_num_fields(mysqli_result $result): ?int {
  2348. return $result->field_count;
  2349. }
  2350. /**
  2351. * Set result pointer to a specified field offset
  2352. *
  2353. * @param mysqli_result $result -
  2354. * @param int $fieldnr - The field number. This value must be in the
  2355. * range from 0 to number of fields - 1.
  2356. *
  2357. * @return bool -
  2358. */
  2359. function mysqli_field_seek(mysqli_result $result,
  2360. int $fieldnr): bool {
  2361. return $result->field_seek($fieldnr);
  2362. }
  2363. /**
  2364. * Frees the memory associated with a result
  2365. *
  2366. * @param mysqli_result $result -
  2367. *
  2368. * @return void -
  2369. */
  2370. <<__Native>>
  2371. function mysqli_free_result(mixed $result): void;
  2372. /**
  2373. * Returns the lengths of the columns of the current row in the result set
  2374. *
  2375. * @param mysqli_result $result -
  2376. *
  2377. * @return array - An array of integers representing the size of each
  2378. * column (not including any terminating null characters). FALSE if an
  2379. * error occurred. mysqli_fetch_lengths() is valid only for the current
  2380. * row of the result set. It returns FALSE if you call it before calling
  2381. * mysqli_fetch_row/array/object or after retrieving all rows in the
  2382. * result.
  2383. */
  2384. function mysqli_fetch_lengths(mysqli_result $result): array {
  2385. return $result->lengths;
  2386. }
  2387. /**
  2388. * Gets the number of rows in a result
  2389. *
  2390. * @param mysqli_result $result -
  2391. *
  2392. * @return int - Returns number of rows in the result set. If the
  2393. * number of rows is greater than PHP_INT_MAX, the number will be
  2394. * returned as a string.
  2395. */
  2396. function mysqli_num_rows(mysqli_result $result): int {
  2397. return $result->num_rows;
  2398. }
  2399. /**
  2400. * Returns the total number of rows changed, deleted, or
  2401. * inserted by the last executed statement
  2402. *
  2403. *
  2404. * @param mysqli_stmt $stmt -
  2405. *
  2406. * @return int - An integer greater than zero indicates the number of
  2407. * rows affected or retrieved. Zero indicates that no records where
  2408. * updated for an UPDATE/DELETE statement, no rows matched the WHERE
  2409. * clause in the query or that no query has yet been executed. -1
  2410. * indicates that the query has returned an error. NULL indicates an
  2411. * invalid argument was supplied to the function. If the number of
  2412. * affected rows is greater than maximal PHP int value, the number of
  2413. * affected rows will be returned as a string value.
  2414. */
  2415. function mysqli_stmt_affected_rows(mysqli_stmt $stmt): ?int {
  2416. return $stmt->affected_rows;
  2417. }
  2418. /**
  2419. * Used to get the current value of a statement attribute
  2420. *
  2421. * @param mysqli_stmt $stmt -
  2422. * @param int $attr - The attribute that you want to get.
  2423. *
  2424. * @return int - Returns FALSE if the attribute is not found, otherwise
  2425. * returns the value of the attribute.
  2426. */
  2427. function mysqli_stmt_attr_get(mysqli_stmt $stmt, int $attr): mixed {
  2428. return $stmt->attr_get($attr);
  2429. }
  2430. /**
  2431. * Used to modify the behavior of a prepared statement
  2432. *
  2433. * @param mysqli_stmt $stmt -
  2434. * @param int $attr - The attribute that you want to set. It can have one
  2435. * of the following values: Attribute values Character Description
  2436. * MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH If set to 1, causes
  2437. * mysqli_stmt_store_result() to update the metadata
  2438. * MYSQL_FIELD->max_length value. MYSQLI_STMT_ATTR_CURSOR_TYPE Type
  2439. * of cursor to open for statement when mysqli_stmt_execute() is invoked.
  2440. * mode can be MYSQLI_CURSOR_TYPE_NO_CURSOR (the default) or
  2441. * MYSQLI_CURSOR_TYPE_READ_ONLY. MYSQLI_STMT_ATTR_PREFETCH_ROWS
  2442. * Number of rows to fetch from server at a time when using a cursor.
  2443. * mode can be in the range from 1 to the maximum value of unsigned long.
  2444. * The default is 1. If you use the MYSQLI_STMT_ATTR_CURSOR_TYPE
  2445. * option with MYSQLI_CURSOR_TYPE_READ_ONLY, a cursor is opened for the
  2446. * statement when you invoke mysqli_stmt_execute(). If there is already
  2447. * an open cursor from a previous mysqli_stmt_execute() call, it closes
  2448. * the cursor before opening a new one. mysqli_stmt_reset() also closes
  2449. * any open cursor before preparing the statement for re-execution.
  2450. * mysqli_stmt_free_result() closes any open cursor. If you open a
  2451. * cursor for a prepared statement, mysqli_stmt_store_result() is
  2452. * unnecessary.
  2453. * @param int $mode - The value to assign to the attribute.
  2454. *
  2455. * @return bool -
  2456. */
  2457. function mysqli_stmt_attr_set(mysqli_stmt $stmt, int $attr, int $mode): bool {
  2458. return $stmt->attr_set($attr, $mode);
  2459. }
  2460. /**
  2461. * Binds variables to a prepared statement as parameters
  2462. *
  2463. * @param mysqli_stmt $stmt -
  2464. * @param string $types - A string that contains one or more characters
  2465. * which specify the types for the corresponding bind variables: Type
  2466. * specification chars Character Description i corresponding
  2467. * variable has type integer d corresponding variable has type double
  2468. * s corresponding variable has type string b corresponding variable is
  2469. * a blob and will be sent in packets
  2470. * @param mixed $var1 - The number of variables and length of string
  2471. * types must match the parameters in the statement.
  2472. * @param mixed $... -
  2473. *
  2474. * @return bool -
  2475. */
  2476. <<__Native("ActRec", "VariadicByRef")>>
  2477. function mysqli_stmt_bind_param(mysqli_stmt $stmt, string $types, ...): mixed;
  2478. /**
  2479. * Binds variables to a prepared statement for result storage
  2480. *
  2481. * @param mysqli_stmt $stmt -
  2482. * @param mixed $var1 - The variable to be bound.
  2483. * @param mixed $... -
  2484. *
  2485. * @return bool -
  2486. */
  2487. <<__Native("ActRec", "VariadicByRef")>>
  2488. function mysqli_stmt_bind_result(mysqli_stmt $stmt, ...): mixed;
  2489. /**
  2490. * Closes a prepared statement
  2491. *
  2492. * @param mysqli_stmt $stmt -
  2493. *
  2494. * @return bool -
  2495. */
  2496. function mysqli_stmt_close(mysqli_stmt $stmt): bool {
  2497. return $stmt->close();
  2498. }
  2499. /**
  2500. * Seeks to an arbitrary row in statement result set
  2501. *
  2502. * @param mysqli_stmt $stmt -
  2503. * @param int $offset - Must be between zero and the total number of rows
  2504. * minus one (0.. mysqli_stmt_num_rows() - 1).
  2505. *
  2506. * @return void -
  2507. */
  2508. function mysqli_stmt_data_seek(mysqli_stmt $stmt, int $offset): void {
  2509. $stmt->data_seek($offset);
  2510. }
  2511. /**
  2512. * Returns the error code for the most recent statement call
  2513. *
  2514. * @param mysqli_stmt $stmt -
  2515. *
  2516. * @return int - An error code value. Zero means no error occurred.
  2517. */
  2518. function mysqli_stmt_errno(mysqli_stmt $stmt): ?int {
  2519. return $stmt->errno;
  2520. }
  2521. /**
  2522. * Returns a list of errors from the last statement executed
  2523. *
  2524. * @param mysqli_stmt $stmt -
  2525. *
  2526. * @return array - A list of errors, each as an associative array
  2527. * containing the errno, error, and sqlstate.
  2528. */
  2529. function mysqli_stmt_error_list(mysqli_stmt $stmt): ?array {
  2530. return $stmt->error_list;
  2531. }
  2532. /**
  2533. * Returns a string description for last statement error
  2534. *
  2535. * @param mysqli_stmt $stmt -
  2536. *
  2537. * @return string - A string that describes the error. An empty string if
  2538. * no error occurred.
  2539. */
  2540. function mysqli_stmt_error(mysqli_stmt $stmt): mixed {
  2541. return $stmt->error;
  2542. }
  2543. /**
  2544. * Executes a prepared Query
  2545. *
  2546. * @param mysqli_stmt $stmt -
  2547. *
  2548. * @return bool -
  2549. */
  2550. function mysqli_stmt_execute(mysqli_stmt $stmt): bool {
  2551. return $stmt->execute();
  2552. }
  2553. /**
  2554. * Fetch results from a prepared statement into the bound variables
  2555. *
  2556. * @param mysqli_stmt $stmt -
  2557. *
  2558. * @return bool - Value Description TRUE Success. Data has been
  2559. * fetched FALSE Error occurred NULL No more rows/data exists or data
  2560. * truncation occurred
  2561. */
  2562. function mysqli_stmt_fetch(mysqli_stmt $stmt): mixed {
  2563. return $stmt->fetch();
  2564. }
  2565. /**
  2566. * Returns the number of field in the given statement
  2567. *
  2568. * @param mysqli_stmt $stmt -
  2569. *
  2570. * @return int -
  2571. */
  2572. function mysqli_stmt_field_count(mysqli_stmt $stmt): ?int {
  2573. return $stmt->field_count;
  2574. }
  2575. /**
  2576. * Frees stored result memory for the given statement handle
  2577. *
  2578. * @param mysqli_stmt $stmt -
  2579. *
  2580. * @return void -
  2581. */
  2582. function mysqli_stmt_free_result(mysqli_stmt $stmt): void {
  2583. return $stmt->free_result();
  2584. }
  2585. /**
  2586. * Gets a result set from a prepared statement
  2587. *
  2588. * @param mysqli_stmt $stmt -
  2589. *
  2590. * @return mysqli_result - Returns a resultset .
  2591. */
  2592. //function mysqli_stmt_get_result(mysqli_stmt $stmt): mysqli_result {
  2593. // return $stmt->get_result();
  2594. //}
  2595. /**
  2596. * Get result of SHOW WARNINGS
  2597. *
  2598. * @param mysqli_stmt $stmt -
  2599. *
  2600. * @return object -
  2601. */
  2602. function mysqli_stmt_get_warnings(mysqli_stmt $stmt): mixed {
  2603. return $stmt->get_warnings();
  2604. }
  2605. /**
  2606. * Get the ID generated from the previous INSERT operation
  2607. *
  2608. * @param mysqli_stmt $stmt -
  2609. *
  2610. * @return mixed -
  2611. */
  2612. function mysqli_stmt_insert_id(mysqli_stmt $stmt): mixed {
  2613. return $stmt->insert_id;
  2614. }
  2615. /**
  2616. * Check if there are more query results from a multiple query
  2617. *
  2618. * @param mysqli_stmt $stmt -
  2619. *
  2620. * @return bool - Returns TRUE if more results exist, otherwise FALSE.
  2621. */
  2622. function mysqli_stmt_more_results(mysqli_stmt $stmt): bool {
  2623. return $stmt->more_results();
  2624. }
  2625. /**
  2626. * Reads the next result from a multiple query
  2627. *
  2628. * @param mysqli_stmt $stmt -
  2629. *
  2630. * @return bool -
  2631. */
  2632. function mysqli_stmt_next_result(mysqli_stmt $stmt): bool {
  2633. return $stmt->next_result;
  2634. }
  2635. /**
  2636. * Return the number of rows in statements result set
  2637. *
  2638. * @param mysqli_stmt $stmt -
  2639. *
  2640. * @return int - An integer representing the number of rows in result
  2641. * set.
  2642. */
  2643. function mysqli_stmt_num_rows(mysqli_stmt $stmt): mixed {
  2644. return $stmt->num_rows;
  2645. }
  2646. /**
  2647. * Returns the number of parameter for the given statement
  2648. *
  2649. * @param mysqli_stmt $stmt -
  2650. *
  2651. * @return int - Returns an integer representing the number of
  2652. * parameters.
  2653. */
  2654. function mysqli_stmt_param_count(mysqli_stmt $stmt): int {
  2655. return $stmt->param_count;
  2656. }
  2657. /**
  2658. * Prepare an SQL statement for execution
  2659. *
  2660. * @param mysqli_stmt $stmt -
  2661. * @param string $query - The query, as a string. It must consist of a
  2662. * single SQL statement. You can include one or more parameter markers
  2663. * in the SQL statement by embedding question mark (?) characters at the
  2664. * appropriate positions. You should not add a terminating semicolon
  2665. * or \g to the statement. The markers are legal only in certain
  2666. * places in SQL statements. For example, they are allowed in the
  2667. * VALUES() list of an INSERT statement (to specify column values for a
  2668. * row), or in a comparison with a column in a WHERE clause to specify a
  2669. * comparison value. However, they are not allowed for identifiers
  2670. * (such as table or column names), in the select list that names the
  2671. * columns to be returned by a SELECT statement), or to specify both
  2672. * operands of a binary operator such as the = equal sign. The latter
  2673. * restriction is necessary because it would be impossible to determine
  2674. * the parameter type. In general, parameters are legal only in Data
  2675. * Manipulation Language (DML) statements, and not in Data Definition
  2676. * Language (DDL) statements.
  2677. *
  2678. * @return bool -
  2679. */
  2680. function mysqli_stmt_prepare(mysqli_stmt $stmt, string $query): mixed {
  2681. return $stmt->prepare($query);
  2682. }
  2683. /**
  2684. * Resets a prepared statement
  2685. *
  2686. * @param mysqli_stmt $stmt -
  2687. *
  2688. * @return bool -
  2689. */
  2690. function mysqli_stmt_reset(mysqli_stmt $stmt): bool {
  2691. return $stmt->reset();
  2692. }
  2693. /**
  2694. * Returns result set metadata from a prepared statement
  2695. *
  2696. * @param mysqli_stmt $stmt -
  2697. *
  2698. * @return mysqli_result - Returns a result object or FALSE if an error
  2699. * occurred.
  2700. */
  2701. function mysqli_stmt_result_metadata(mysqli_stmt $stmt): mixed {
  2702. return $stmt->result_metadata();
  2703. }
  2704. /**
  2705. * Send data in blocks
  2706. *
  2707. * @param mysqli_stmt $stmt -
  2708. * @param int $param_nr - Indicates which parameter to associate the data
  2709. * with. Parameters are numbered beginning with 0.
  2710. * @param string $data - A string containing data to be sent.
  2711. *
  2712. * @return bool -
  2713. */
  2714. function mysqli_stmt_send_long_data(mysqli_stmt $stmt,
  2715. int $param_nr,
  2716. string $data): mixed {
  2717. return $stmt->send_long_data($param_nr, $data);
  2718. }
  2719. /**
  2720. * Returns SQLSTATE error from previous statement operation
  2721. *
  2722. * @param mysqli_stmt $stmt -
  2723. *
  2724. * @return string - Returns a string containing the SQLSTATE error code
  2725. * for the last error. The error code consists of five characters.
  2726. * '00000' means no error.
  2727. */
  2728. function mysqli_stmt_sqlstate(mysqli_stmt $stmt): ?string {
  2729. return $stmt->sqlstate;
  2730. }
  2731. /**
  2732. * Transfers a result set from a prepared statement
  2733. *
  2734. * @param mysqli_stmt $stmt -
  2735. *
  2736. * @return bool -
  2737. */
  2738. function mysqli_stmt_store_result(mysqli_stmt $stmt): bool {
  2739. return $stmt->store_result();
  2740. }