xref: /PHP-8.1/ext/mysqli/mysqli_driver.c (revision 01b3fc03)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Author: Georg Richter <georg@php.net>                                |
14   +----------------------------------------------------------------------+
15 
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <signal.h>
22 
23 #include "php.h"
24 #include "php_ini.h"
25 #include "ext/standard/info.h"
26 #include "php_mysqli_structs.h"
27 #include "zend_exceptions.h"
28 
29 
30 /* {{{ property driver_reconnect_read */
driver_reconnect_read(mysqli_object * obj,zval * retval,bool quiet)31 static int driver_reconnect_read(mysqli_object *obj, zval *retval, bool quiet)
32 {
33 	ZVAL_BOOL(retval, MyG(reconnect));
34 	return SUCCESS;
35 }
36 /* }}} */
37 
38 /* {{{ property driver_reconnect_write */
driver_reconnect_write(mysqli_object * obj,zval * value)39 static int driver_reconnect_write(mysqli_object *obj, zval *value)
40 {
41 	ZEND_ASSERT(Z_TYPE_P(value) == IS_TRUE || Z_TYPE_P(value) == IS_FALSE);
42 	MyG(reconnect) = Z_TYPE_P(value) == IS_TRUE;
43 	return SUCCESS;
44 }
45 /* }}} */
46 
47 /* {{{ property driver_report_read */
driver_report_read(mysqli_object * obj,zval * retval,bool quiet)48 static int driver_report_read(mysqli_object *obj, zval *retval, bool quiet)
49 {
50 	ZVAL_LONG(retval, MyG(report_mode));
51 	return SUCCESS;
52 }
53 /* }}} */
54 
55 /* {{{ property driver_report_write */
driver_report_write(mysqli_object * obj,zval * value)56 static int driver_report_write(mysqli_object *obj, zval *value)
57 {
58 	ZEND_ASSERT(Z_TYPE_P(value) == IS_LONG);
59 	MyG(report_mode) = Z_LVAL_P(value);
60 	return SUCCESS;
61 }
62 /* }}} */
63 
64 /* {{{ property driver_client_version_read */
driver_client_version_read(mysqli_object * obj,zval * retval,bool quiet)65 static int driver_client_version_read(mysqli_object *obj, zval *retval, bool quiet)
66 {
67 	ZVAL_LONG(retval, mysql_get_client_version());
68 	return SUCCESS;
69 }
70 /* }}} */
71 
72 /* {{{ property driver_client_info_read */
driver_client_info_read(mysqli_object * obj,zval * retval,bool quiet)73 static int driver_client_info_read(mysqli_object *obj, zval *retval, bool quiet)
74 {
75 	ZVAL_STRING(retval, (char *)mysql_get_client_info());
76 	return SUCCESS;
77 }
78 /* }}} */
79 
80 /* {{{ property driver_driver_version_read */
driver_driver_version_read(mysqli_object * obj,zval * retval,bool quiet)81 static int driver_driver_version_read(mysqli_object *obj, zval *retval, bool quiet)
82 {
83 	if (quiet) {
84 		return FAILURE;
85 	}
86 	zend_error(E_DEPRECATED, "The driver_version property is deprecated");
87 	ZVAL_LONG(retval, MYSQLI_VERSION_ID);
88 	return SUCCESS;
89 }
90 /* }}} */
91 
92 const mysqli_property_entry mysqli_driver_property_entries[] = {
93 	{"client_info", sizeof("client_info") - 1, driver_client_info_read, NULL},
94 	{"client_version", sizeof("client_version") - 1, driver_client_version_read, NULL},
95 	{"driver_version", sizeof("driver_version") - 1, driver_driver_version_read, NULL},
96 	{"reconnect", sizeof("reconnect") - 1, driver_reconnect_read, driver_reconnect_write},
97 	{"report_mode", sizeof("report_mode") - 1, driver_report_read, driver_report_write},
98 	{NULL, 0, NULL, NULL}
99 };
100 
101