PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / mysql.php

mysql.php in Defender Security – Malware Scanner, Login Security & Firewall 5.3.1, at vendor/thecodingmachine/safe/generated/mysql.php

939 lines 30.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\MysqlException;
6
7 /**
8 * mysql_close closes the non-persistent connection to
9 * the MySQL server that's associated with the specified link identifier. If
10 * link_identifier isn't specified, the last opened
11 * link is used.
12 *
13 *
14 * Open non-persistent MySQL connections and result sets are automatically destroyed when a
15 * PHP script finishes its execution. So, while explicitly closing open
16 * connections and freeing result sets is optional, doing so is recommended.
17 * This will immediately return resources to PHP and MySQL, which can
18 * improve performance. For related information, see
19 * freeing resources
20 *
21 * @param resource $link_identifier The MySQL connection. If the
22 * link identifier is not specified, the last link opened by
23 * mysql_connect is assumed. If no connection is found or
24 * established, an E_WARNING level error is
25 * generated.
26 * @throws MysqlException
27 *
28 */
29 function mysql_close($link_identifier = null): void
30 {
31 error_clear_last();
32 $result = \mysql_close($link_identifier);
33 if ($result === false) {
34 throw MysqlException::createFromPhpError();
35 }
36 }
37
38
39 /**
40 * Opens or reuses a connection to a MySQL server.
41 *
42 * @param string $server The MySQL server. It can also include a port number. e.g.
43 * "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for
44 * the localhost.
45 *
46 * If the PHP directive
47 * mysql.default_host is undefined (default), then the default
48 * value is 'localhost:3306'. In SQL safe mode, this parameter is ignored
49 * and value 'localhost:3306' is always used.
50 * @param string $username The username. Default value is defined by mysql.default_user. In
51 * SQL safe mode, this parameter is ignored and the name of the user that
52 * owns the server process is used.
53 * @param string $password The password. Default value is defined by mysql.default_password. In
54 * SQL safe mode, this parameter is ignored and empty password is used.
55 * @param bool $new_link If a second call is made to mysql_connect
56 * with the same arguments, no new link will be established, but
57 * instead, the link identifier of the already opened link will be
58 * returned. The new_link parameter modifies this
59 * behavior and makes mysql_connect always open
60 * a new link, even if mysql_connect was called
61 * before with the same parameters.
62 * In SQL safe mode, this parameter is ignored.
63 * @param int $client_flags The client_flags parameter can be a combination
64 * of the following constants:
65 * 128 (enable LOAD DATA LOCAL handling),
66 * MYSQL_CLIENT_SSL,
67 * MYSQL_CLIENT_COMPRESS,
68 * MYSQL_CLIENT_IGNORE_SPACE or
69 * MYSQL_CLIENT_INTERACTIVE.
70 * Read the section about for further information.
71 * In SQL safe mode, this parameter is ignored.
72 * @return resource Returns a MySQL link identifier on success.
73 * @throws MysqlException
74 *
75 */
76 function mysql_connect(string $server = null, string $username = null, string $password = null, bool $new_link = false, int $client_flags = 0)
77 {
78 error_clear_last();
79 if ($client_flags !== 0) {
80 $result = \mysql_connect($server, $username, $password, $new_link, $client_flags);
81 } elseif ($new_link !== false) {
82 $result = \mysql_connect($server, $username, $password, $new_link);
83 } elseif ($password !== null) {
84 $result = \mysql_connect($server, $username, $password);
85 } elseif ($username !== null) {
86 $result = \mysql_connect($server, $username);
87 } elseif ($server !== null) {
88 $result = \mysql_connect($server);
89 } else {
90 $result = \mysql_connect();
91 }
92 if ($result === false) {
93 throw MysqlException::createFromPhpError();
94 }
95 return $result;
96 }
97
98
99 /**
100 * mysql_create_db attempts to create a new
101 * database on the server associated with the specified link
102 * identifier.
103 *
104 * @param string $database_name The name of the database being created.
105 * @param resource $link_identifier The MySQL connection. If the
106 * link identifier is not specified, the last link opened by
107 * mysql_connect is assumed. If no such link is found, it
108 * will try to create one as if mysql_connect had been called
109 * with no arguments. If no connection is found or established, an
110 * E_WARNING level error is generated.
111 * @throws MysqlException
112 *
113 */
114 function mysql_create_db(string $database_name, $link_identifier = null): void
115 {
116 error_clear_last();
117 $result = \mysql_create_db($database_name, $link_identifier);
118 if ($result === false) {
119 throw MysqlException::createFromPhpError();
120 }
121 }
122
123
124 /**
125 * mysql_data_seek moves the internal row
126 * pointer of the MySQL result associated with the specified result
127 * identifier to point to the specified row number. The next call
128 * to a MySQL fetch function, such as mysql_fetch_assoc,
129 * would return that row.
130 *
131 * row_number starts at 0. The
132 * row_number should be a value in the range from 0 to
133 * mysql_num_rows - 1. However if the result set
134 * is empty (mysql_num_rows == 0), a seek to 0 will
135 * fail with an E_WARNING and
136 * mysql_data_seek will return FALSE.
137 *
138 * @param resource $result The result resource that
139 * is being evaluated. This result comes from a call to
140 * mysql_query.
141 * @param int $row_number The desired row number of the new result pointer.
142 * @throws MysqlException
143 *
144 */
145 function mysql_data_seek($result, int $row_number): void
146 {
147 error_clear_last();
148 $result = \mysql_data_seek($result, $row_number);
149 if ($result === false) {
150 throw MysqlException::createFromPhpError();
151 }
152 }
153
154
155 /**
156 * Retrieve the database name from a call to
157 * mysql_list_dbs.
158 *
159 * @param resource $result The result pointer from a call to mysql_list_dbs.
160 * @param int $row The index into the result set.
161 * @param mixed $field The field name.
162 * @return string Returns the database name on success. If FALSE
163 * is returned, use mysql_error to determine the nature
164 * of the error.
165 * @throws MysqlException
166 *
167 */
168 function mysql_db_name($result, int $row, $field = null): string
169 {
170 error_clear_last();
171 $result = \mysql_db_name($result, $row, $field);
172 if ($result === false) {
173 throw MysqlException::createFromPhpError();
174 }
175 return $result;
176 }
177
178
179 /**
180 * mysql_db_query selects a database, and executes a
181 * query on it.
182 *
183 * @param string $database The name of the database that will be selected.
184 * @param string $query The MySQL query.
185 *
186 * Data inside the query should be properly escaped.
187 * @param resource $link_identifier The MySQL connection. If the
188 * link identifier is not specified, the last link opened by
189 * mysql_connect is assumed. If no such link is found, it
190 * will try to create one as if mysql_connect had been called
191 * with no arguments. If no connection is found or established, an
192 * E_WARNING level error is generated.
193 * @return resource|bool Returns a positive MySQL result resource to the query result. The function also returns TRUE/FALSE for
194 * INSERT/UPDATE/DELETE
195 * queries to indicate success/failure.
196 * @throws MysqlException
197 *
198 */
199 function mysql_db_query(string $database, string $query, $link_identifier = null)
200 {
201 error_clear_last();
202 $result = \mysql_db_query($database, $query, $link_identifier);
203 if ($result === false) {
204 throw MysqlException::createFromPhpError();
205 }
206 return $result;
207 }
208
209
210 /**
211 * mysql_drop_db attempts to drop (remove) an
212 * entire database from the server associated with the specified
213 * link identifier. This function is deprecated, it is preferable to use
214 * mysql_query to issue an sql
215 * DROP DATABASE statement instead.
216 *
217 * @param string $database_name The name of the database that will be deleted.
218 * @param resource $link_identifier The MySQL connection. If the
219 * link identifier is not specified, the last link opened by
220 * mysql_connect is assumed. If no such link is found, it
221 * will try to create one as if mysql_connect had been called
222 * with no arguments. If no connection is found or established, an
223 * E_WARNING level error is generated.
224 * @throws MysqlException
225 *
226 */
227 function mysql_drop_db(string $database_name, $link_identifier = null): void
228 {
229 error_clear_last();
230 $result = \mysql_drop_db($database_name, $link_identifier);
231 if ($result === false) {
232 throw MysqlException::createFromPhpError();
233 }
234 }
235
236
237 /**
238 * Returns an array that corresponds to the lengths of each field
239 * in the last row fetched by MySQL.
240 *
241 * mysql_fetch_lengths stores the lengths of
242 * each result column in the last row returned by
243 * mysql_fetch_row,
244 * mysql_fetch_assoc,
245 * mysql_fetch_array, and
246 * mysql_fetch_object in an array, starting at
247 * offset 0.
248 *
249 * @param resource $result The result resource that
250 * is being evaluated. This result comes from a call to
251 * mysql_query.
252 * @return array An array of lengths on success.
253 * @throws MysqlException
254 *
255 */
256 function mysql_fetch_lengths($result): array
257 {
258 error_clear_last();
259 $result = \mysql_fetch_lengths($result);
260 if ($result === false) {
261 throw MysqlException::createFromPhpError();
262 }
263 return $result;
264 }
265
266
267 /**
268 * mysql_field_flags returns the field flags of
269 * the specified field. The flags are reported as a single word
270 * per flag separated by a single space, so that you can split the
271 * returned value using explode.
272 *
273 * @param resource $result The result resource that
274 * is being evaluated. This result comes from a call to
275 * mysql_query.
276 * @param int $field_offset The numerical field offset. The
277 * field_offset starts at 0. If
278 * field_offset does not exist, an error of level
279 * E_WARNING is also issued.
280 * @return string Returns a string of flags associated with the result.
281 *
282 * The following flags are reported, if your version of MySQL
283 * is current enough to support them: "not_null",
284 * "primary_key", "unique_key",
285 * "multiple_key", "blob",
286 * "unsigned", "zerofill",
287 * "binary", "enum",
288 * "auto_increment" and "timestamp".
289 * @throws MysqlException
290 *
291 */
292 function mysql_field_flags($result, int $field_offset): string
293 {
294 error_clear_last();
295 $result = \mysql_field_flags($result, $field_offset);
296 if ($result === false) {
297 throw MysqlException::createFromPhpError();
298 }
299 return $result;
300 }
301
302
303 /**
304 * mysql_field_len returns the length of the
305 * specified field.
306 *
307 * @param resource $result The result resource that
308 * is being evaluated. This result comes from a call to
309 * mysql_query.
310 * @param int $field_offset The numerical field offset. The
311 * field_offset starts at 0. If
312 * field_offset does not exist, an error of level
313 * E_WARNING is also issued.
314 * @return int The length of the specified field index on success.
315 * @throws MysqlException
316 *
317 */
318 function mysql_field_len($result, int $field_offset): int
319 {
320 error_clear_last();
321 $result = \mysql_field_len($result, $field_offset);
322 if ($result === false) {
323 throw MysqlException::createFromPhpError();
324 }
325 return $result;
326 }
327
328
329 /**
330 * mysql_field_name returns the name of the
331 * specified field index.
332 *
333 * @param resource $result The result resource that
334 * is being evaluated. This result comes from a call to
335 * mysql_query.
336 * @param int $field_offset The numerical field offset. The
337 * field_offset starts at 0. If
338 * field_offset does not exist, an error of level
339 * E_WARNING is also issued.
340 * @return string The name of the specified field index on success.
341 * @throws MysqlException
342 *
343 */
344 function mysql_field_name($result, int $field_offset): string
345 {
346 error_clear_last();
347 $result = \mysql_field_name($result, $field_offset);
348 if ($result === false) {
349 throw MysqlException::createFromPhpError();
350 }
351 return $result;
352 }
353
354
355 /**
356 * Seeks to the specified field offset. If the next call to
357 * mysql_fetch_field doesn't include a field
358 * offset, the field offset specified in
359 * mysql_field_seek will be returned.
360 *
361 * @param resource $result The result resource that
362 * is being evaluated. This result comes from a call to
363 * mysql_query.
364 * @param int $field_offset The numerical field offset. The
365 * field_offset starts at 0. If
366 * field_offset does not exist, an error of level
367 * E_WARNING is also issued.
368 * @throws MysqlException
369 *
370 */
371 function mysql_field_seek($result, int $field_offset): void
372 {
373 error_clear_last();
374 $result = \mysql_field_seek($result, $field_offset);
375 if ($result === false) {
376 throw MysqlException::createFromPhpError();
377 }
378 }
379
380
381 /**
382 * mysql_free_result will free all memory
383 * associated with the result identifier result.
384 *
385 * mysql_free_result only needs to be called if
386 * you are concerned about how much memory is being used for queries
387 * that return large result sets. All associated result memory is
388 * automatically freed at the end of the script's execution.
389 *
390 * @param resource $result The result resource that
391 * is being evaluated. This result comes from a call to
392 * mysql_query.
393 * @throws MysqlException
394 *
395 */
396 function mysql_free_result($result): void
397 {
398 error_clear_last();
399 $result = \mysql_free_result($result);
400 if ($result === false) {
401 throw MysqlException::createFromPhpError();
402 }
403 }
404
405
406 /**
407 * Describes the type of connection in use for the connection, including the
408 * server host name.
409 *
410 * @param resource $link_identifier The MySQL connection. If the
411 * link identifier is not specified, the last link opened by
412 * mysql_connect is assumed. If no such link is found, it
413 * will try to create one as if mysql_connect had been called
414 * with no arguments. If no connection is found or established, an
415 * E_WARNING level error is generated.
416 * @return string Returns a string describing the type of MySQL connection in use for the
417 * connection.
418 * @throws MysqlException
419 *
420 */
421 function mysql_get_host_info($link_identifier = null): string
422 {
423 error_clear_last();
424 $result = \mysql_get_host_info($link_identifier);
425 if ($result === false) {
426 throw MysqlException::createFromPhpError();
427 }
428 return $result;
429 }
430
431
432 /**
433 * Retrieves the MySQL protocol.
434 *
435 * @param resource $link_identifier The MySQL connection. If the
436 * link identifier is not specified, the last link opened by
437 * mysql_connect is assumed. If no such link is found, it
438 * will try to create one as if mysql_connect had been called
439 * with no arguments. If no connection is found or established, an
440 * E_WARNING level error is generated.
441 * @return int Returns the MySQL protocol on success.
442 * @throws MysqlException
443 *
444 */
445 function mysql_get_proto_info($link_identifier = null): int
446 {
447 error_clear_last();
448 $result = \mysql_get_proto_info($link_identifier);
449 if ($result === false) {
450 throw MysqlException::createFromPhpError();
451 }
452 return $result;
453 }
454
455
456 /**
457 * Retrieves the MySQL server version.
458 *
459 * @param resource $link_identifier The MySQL connection. If the
460 * link identifier is not specified, the last link opened by
461 * mysql_connect is assumed. If no such link is found, it
462 * will try to create one as if mysql_connect had been called
463 * with no arguments. If no connection is found or established, an
464 * E_WARNING level error is generated.
465 * @return string Returns the MySQL server version on success.
466 * @throws MysqlException
467 *
468 */
469 function mysql_get_server_info($link_identifier = null): string
470 {
471 error_clear_last();
472 $result = \mysql_get_server_info($link_identifier);
473 if ($result === false) {
474 throw MysqlException::createFromPhpError();
475 }
476 return $result;
477 }
478
479
480 /**
481 * Returns detailed information about the last query.
482 *
483 * @param resource $link_identifier The MySQL connection. If the
484 * link identifier is not specified, the last link opened by
485 * mysql_connect is assumed. If no such link is found, it
486 * will try to create one as if mysql_connect had been called
487 * with no arguments. If no connection is found or established, an
488 * E_WARNING level error is generated.
489 * @return string Returns information about the statement on success. See the example below for which statements provide information,
490 * and what the returned value may look like. Statements that are not listed
491 * will return FALSE.
492 * @throws MysqlException
493 *
494 */
495 function mysql_info($link_identifier = null): string
496 {
497 error_clear_last();
498 $result = \mysql_info($link_identifier);
499 if ($result === false) {
500 throw MysqlException::createFromPhpError();
501 }
502 return $result;
503 }
504
505
506 /**
507 * Returns a result pointer containing the databases available from the
508 * current mysql daemon.
509 *
510 * @param resource $link_identifier The MySQL connection. If the
511 * link identifier is not specified, the last link opened by
512 * mysql_connect is assumed. If no such link is found, it
513 * will try to create one as if mysql_connect had been called
514 * with no arguments. If no connection is found or established, an
515 * E_WARNING level error is generated.
516 * @return resource Returns a result pointer resource on success. Use the mysql_tablename function to traverse
517 * this result pointer, or any function for result tables, such as
518 * mysql_fetch_array.
519 * @throws MysqlException
520 *
521 */
522 function mysql_list_dbs($link_identifier = null)
523 {
524 error_clear_last();
525 $result = \mysql_list_dbs($link_identifier);
526 if ($result === false) {
527 throw MysqlException::createFromPhpError();
528 }
529 return $result;
530 }
531
532
533 /**
534 * Retrieves information about the given table name.
535 *
536 * This function is deprecated. It is preferable to use
537 * mysql_query to issue an SQL SHOW COLUMNS FROM
538 * table [LIKE 'name'] statement instead.
539 *
540 * @param string $database_name The name of the database that's being queried.
541 * @param string $table_name The name of the table that's being queried.
542 * @param resource $link_identifier The MySQL connection. If the
543 * link identifier is not specified, the last link opened by
544 * mysql_connect is assumed. If no such link is found, it
545 * will try to create one as if mysql_connect had been called
546 * with no arguments. If no connection is found or established, an
547 * E_WARNING level error is generated.
548 * @return resource A result pointer resource on success.
549 *
550 * The returned result can be used with mysql_field_flags,
551 * mysql_field_len,
552 * mysql_field_name and
553 * mysql_field_type.
554 * @throws MysqlException
555 *
556 */
557 function mysql_list_fields(string $database_name, string $table_name, $link_identifier = null)
558 {
559 error_clear_last();
560 $result = \mysql_list_fields($database_name, $table_name, $link_identifier);
561 if ($result === false) {
562 throw MysqlException::createFromPhpError();
563 }
564 return $result;
565 }
566
567
568 /**
569 * Retrieves the current MySQL server threads.
570 *
571 * @param resource $link_identifier The MySQL connection. If the
572 * link identifier is not specified, the last link opened by
573 * mysql_connect is assumed. If no such link is found, it
574 * will try to create one as if mysql_connect had been called
575 * with no arguments. If no connection is found or established, an
576 * E_WARNING level error is generated.
577 * @return resource A result pointer resource on success.
578 * @throws MysqlException
579 *
580 */
581 function mysql_list_processes($link_identifier = null)
582 {
583 error_clear_last();
584 $result = \mysql_list_processes($link_identifier);
585 if ($result === false) {
586 throw MysqlException::createFromPhpError();
587 }
588 return $result;
589 }
590
591
592 /**
593 * Retrieves a list of table names from a MySQL database.
594 *
595 * This function is deprecated. It is preferable to use
596 * mysql_query to issue an SQL SHOW TABLES
597 * [FROM db_name] [LIKE 'pattern'] statement instead.
598 *
599 * @param string $database The name of the database
600 * @param resource $link_identifier The MySQL connection. If the
601 * link identifier is not specified, the last link opened by
602 * mysql_connect is assumed. If no such link is found, it
603 * will try to create one as if mysql_connect had been called
604 * with no arguments. If no connection is found or established, an
605 * E_WARNING level error is generated.
606 * @return resource A result pointer resource on success.
607 *
608 * Use the mysql_tablename function to
609 * traverse this result pointer, or any function for result tables,
610 * such as mysql_fetch_array.
611 * @throws MysqlException
612 *
613 */
614 function mysql_list_tables(string $database, $link_identifier = null)
615 {
616 error_clear_last();
617 $result = \mysql_list_tables($database, $link_identifier);
618 if ($result === false) {
619 throw MysqlException::createFromPhpError();
620 }
621 return $result;
622 }
623
624
625 /**
626 * Retrieves the number of fields from a query.
627 *
628 * @param resource $result The result resource that
629 * is being evaluated. This result comes from a call to
630 * mysql_query.
631 * @return int Returns the number of fields in the result set resource on
632 * success.
633 * @throws MysqlException
634 *
635 */
636 function mysql_num_fields($result): int
637 {
638 error_clear_last();
639 $result = \mysql_num_fields($result);
640 if ($result === false) {
641 throw MysqlException::createFromPhpError();
642 }
643 return $result;
644 }
645
646
647 /**
648 * Retrieves the number of rows from a result set. This command is only valid
649 * for statements like SELECT or SHOW that return an actual result set.
650 * To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or
651 * DELETE query, use mysql_affected_rows.
652 *
653 * @param resource $result The result resource that
654 * is being evaluated. This result comes from a call to
655 * mysql_query.
656 * @return int The number of rows in a result set on success.
657 * @throws MysqlException
658 *
659 */
660 function mysql_num_rows($result): int
661 {
662 error_clear_last();
663 $result = \mysql_num_rows($result);
664 if ($result === false) {
665 throw MysqlException::createFromPhpError();
666 }
667 return $result;
668 }
669
670
671 /**
672 * mysql_query sends a unique query (multiple queries
673 * are not supported) to the currently
674 * active database on the server that's associated with the
675 * specified link_identifier.
676 *
677 * @param string $query An SQL query
678 *
679 * The query string should not end with a semicolon.
680 * Data inside the query should be properly escaped.
681 * @param resource $link_identifier The MySQL connection. If the
682 * link identifier is not specified, the last link opened by
683 * mysql_connect is assumed. If no such link is found, it
684 * will try to create one as if mysql_connect had been called
685 * with no arguments. If no connection is found or established, an
686 * E_WARNING level error is generated.
687 * @return resource|bool For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset,
688 * mysql_query
689 * returns a resource on success.
690 *
691 * For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
692 * mysql_query returns TRUE on success.
693 *
694 * The returned result resource should be passed to
695 * mysql_fetch_array, and other
696 * functions for dealing with result tables, to access the returned data.
697 *
698 * Use mysql_num_rows to find out how many rows
699 * were returned for a SELECT statement or
700 * mysql_affected_rows to find out how many
701 * rows were affected by a DELETE, INSERT, REPLACE, or UPDATE
702 * statement.
703 *
704 * mysql_query will also fail and return FALSE
705 * if the user does not have permission to access the table(s) referenced by
706 * the query.
707 * @throws MysqlException
708 *
709 */
710 function mysql_query(string $query, $link_identifier = null)
711 {
712 error_clear_last();
713 $result = \mysql_query($query, $link_identifier);
714 if ($result === false) {
715 throw MysqlException::createFromPhpError();
716 }
717 return $result;
718 }
719
720
721 /**
722 * Escapes special characters in the unescaped_string,
723 * taking into account the current character set of the connection so that it
724 * is safe to place it in a mysql_query. If binary data
725 * is to be inserted, this function must be used.
726 *
727 * mysql_real_escape_string calls MySQL's library function
728 * mysql_real_escape_string, which prepends backslashes to the following characters:
729 * \x00, \n,
730 * \r, \, ',
731 * " and \x1a.
732 *
733 * This function must always (with few exceptions) be used to make data
734 * safe before sending a query to MySQL.
735 *
736 * @param string $unescaped_string The string that is to be escaped.
737 * @param resource $link_identifier The MySQL connection. If the
738 * link identifier is not specified, the last link opened by
739 * mysql_connect is assumed. If no such link is found, it
740 * will try to create one as if mysql_connect had been called
741 * with no arguments. If no connection is found or established, an
742 * E_WARNING level error is generated.
743 * @return string Returns the escaped string.
744 * @throws MysqlException
745 *
746 */
747 function mysql_real_escape_string(string $unescaped_string, $link_identifier = null): string
748 {
749 error_clear_last();
750 $result = \mysql_real_escape_string($unescaped_string, $link_identifier);
751 if ($result === false) {
752 throw MysqlException::createFromPhpError();
753 }
754 return $result;
755 }
756
757
758 /**
759 * Retrieves the contents of one cell from a MySQL result set.
760 *
761 * When working on large result sets, you should consider using one
762 * of the functions that fetch an entire row (specified below). As
763 * these functions return the contents of multiple cells in one
764 * function call, they're MUCH quicker than
765 * mysql_result. Also, note that specifying a
766 * numeric offset for the field argument is much quicker than
767 * specifying a fieldname or tablename.fieldname argument.
768 *
769 * @param resource $result The result resource that
770 * is being evaluated. This result comes from a call to
771 * mysql_query.
772 * @param int $row The row number from the result that's being retrieved. Row numbers
773 * start at 0.
774 * @param mixed $field The name or offset of the field being retrieved.
775 *
776 * It can be the field's offset, the field's name, or the field's table
777 * dot field name (tablename.fieldname). If the column name has been
778 * aliased ('select foo as bar from...'), use the alias instead of the
779 * column name. If undefined, the first field is retrieved.
780 * @return string The contents of one cell from a MySQL result set on success.
781 * @throws MysqlException
782 *
783 */
784 function mysql_result($result, int $row, $field = 0): string
785 {
786 error_clear_last();
787 $result = \mysql_result($result, $row, $field);
788 if ($result === false) {
789 throw MysqlException::createFromPhpError();
790 }
791 return $result;
792 }
793
794
795 /**
796 * Sets the current active database on the server that's associated with the
797 * specified link identifier. Every subsequent call to
798 * mysql_query will be made on the active database.
799 *
800 * @param string $database_name The name of the database that is to be selected.
801 * @param resource $link_identifier The MySQL connection. If the
802 * link identifier is not specified, the last link opened by
803 * mysql_connect is assumed. If no such link is found, it
804 * will try to create one as if mysql_connect had been called
805 * with no arguments. If no connection is found or established, an
806 * E_WARNING level error is generated.
807 * @throws MysqlException
808 *
809 */
810 function mysql_select_db(string $database_name, $link_identifier = null): void
811 {
812 error_clear_last();
813 $result = \mysql_select_db($database_name, $link_identifier);
814 if ($result === false) {
815 throw MysqlException::createFromPhpError();
816 }
817 }
818
819
820 /**
821 * Sets the default character set for the current connection.
822 *
823 * @param string $charset A valid character set name.
824 * @param resource $link_identifier The MySQL connection. If the
825 * link identifier is not specified, the last link opened by
826 * mysql_connect is assumed. If no such link is found, it
827 * will try to create one as if mysql_connect had been called
828 * with no arguments. If no connection is found or established, an
829 * E_WARNING level error is generated.
830 * @throws MysqlException
831 *
832 */
833 function mysql_set_charset(string $charset, $link_identifier = null): void
834 {
835 error_clear_last();
836 $result = \mysql_set_charset($charset, $link_identifier);
837 if ($result === false) {
838 throw MysqlException::createFromPhpError();
839 }
840 }
841
842
843 /**
844 * Retrieves the table name from a result.
845 *
846 * This function is deprecated. It is preferable to use
847 * mysql_query to issue an SQL SHOW TABLES
848 * [FROM db_name] [LIKE 'pattern'] statement instead.
849 *
850 * @param resource $result A result pointer resource that's returned from
851 * mysql_list_tables.
852 * @param int $i The integer index (row/table number)
853 * @return string The name of the table on success.
854 *
855 * Use the mysql_tablename function to
856 * traverse this result pointer, or any function for result tables,
857 * such as mysql_fetch_array.
858 * @throws MysqlException
859 *
860 */
861 function mysql_tablename($result, int $i): string
862 {
863 error_clear_last();
864 $result = \mysql_tablename($result, $i);
865 if ($result === false) {
866 throw MysqlException::createFromPhpError();
867 }
868 return $result;
869 }
870
871
872 /**
873 * Retrieves the current thread ID. If the connection is lost, and a reconnect
874 * with mysql_ping is executed, the thread ID will
875 * change. This means only retrieve the thread ID when needed.
876 *
877 * @param resource $link_identifier The MySQL connection. If the
878 * link identifier is not specified, the last link opened by
879 * mysql_connect is assumed. If no such link is found, it
880 * will try to create one as if mysql_connect had been called
881 * with no arguments. If no connection is found or established, an
882 * E_WARNING level error is generated.
883 * @return int The thread ID on success.
884 * @throws MysqlException
885 *
886 */
887 function mysql_thread_id($link_identifier = null): int
888 {
889 error_clear_last();
890 $result = \mysql_thread_id($link_identifier);
891 if ($result === false) {
892 throw MysqlException::createFromPhpError();
893 }
894 return $result;
895 }
896
897
898 /**
899 * mysql_unbuffered_query sends the SQL query
900 * query to MySQL without automatically
901 * fetching and buffering the result rows as
902 * mysql_query does. This saves a considerable
903 * amount of memory with SQL queries that produce large result sets,
904 * and you can start working on the result set immediately after the
905 * first row has been retrieved as you don't have to wait until the
906 * complete SQL query has been performed. To use
907 * mysql_unbuffered_query while multiple database
908 * connections are open, you must specify the optional parameter
909 * link_identifier to identify which connection
910 * you want to use.
911 *
912 * @param string $query The SQL query to execute.
913 *
914 * Data inside the query should be properly escaped.
915 * @param resource $link_identifier The MySQL connection. If the
916 * link identifier is not specified, the last link opened by
917 * mysql_connect is assumed. If no such link is found, it
918 * will try to create one as if mysql_connect had been called
919 * with no arguments. If no connection is found or established, an
920 * E_WARNING level error is generated.
921 * @return resource|bool For SELECT, SHOW, DESCRIBE or EXPLAIN statements,
922 * mysql_unbuffered_query
923 * returns a resource on success.
924 *
925 * For other type of SQL statements, UPDATE, DELETE, DROP, etc,
926 * mysql_unbuffered_query returns TRUE on success.
927 * @throws MysqlException
928 *
929 */
930 function mysql_unbuffered_query(string $query, $link_identifier = null)
931 {
932 error_clear_last();
933 $result = \mysql_unbuffered_query($query, $link_identifier);
934 if ($result === false) {
935 throw MysqlException::createFromPhpError();
936 }
937 return $result;
938 }
939