Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 73... Línea 73...
73
	var $ssl_cert = null;
73
	var $ssl_cert = null;
74
	var $ssl_ca = null;
74
	var $ssl_ca = null;
75
	var $ssl_capath = null;
75
	var $ssl_capath = null;
76
	var $ssl_cipher = null;
76
	var $ssl_cipher = null;
Línea -... Línea 77...
-
 
77
 
-
 
78
	/**
-
 
79
	 * Forcing emulated prepared statements.
-
 
80
	 *
-
 
81
	 * When set to true, ADODb will not execute queries using MySQLi native
-
 
82
	 * bound variables, and will instead use the built-in string interpolation
-
 
83
	 * and argument quoting from the parent class {@see ADOConnection::Execute()}.
-
 
84
	 *
-
 
85
	 * This is needed for some database engines that use mysql wire-protocol but
-
 
86
	 * do not support prepared statements, like
-
 
87
	 * {@see https://manticoresearch.com/ Manticore Search} or
-
 
88
	 * {@see https://clickhouse.com/ ClickHouse}.
-
 
89
	 *
-
 
90
	 * WARNING: This is a potential security risk, and strongly discouraged for code
-
 
91
	 * handling untrusted input {@see https://github.com/ADOdb/ADOdb/issues/1028#issuecomment-2081586024}.
-
 
92
	 *
-
 
93
	 * @var bool $doNotUseBoundVariables
-
 
94
	 */
-
 
95
	var $doNotUseBoundVariables = false;
77
 
96
 
78
	/** @var mysqli Identifier for the native database connection */
97
	/** @var mysqli Identifier for the native database connection */
Línea 79... Línea 98...
79
	var $_connectionID = false;
98
	var $_connectionID = false;
80
 
99
 
Línea 124... Línea 143...
124
		if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
143
		if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
125
		$this->execute("SET SESSION TRANSACTION ".$transaction_mode);
144
		$this->execute("SET SESSION TRANSACTION ".$transaction_mode);
126
	}
145
	}
Línea 127... Línea 146...
127
 
146
 
128
	/**
147
	/**
129
	 * Adds a parameter to the connection string.
148
	 * Adds a parameter to the connection string, can also set connection property values.
130
	 *
149
	 *
131
	 * Parameter must be one of the constants listed in mysqli_options().
150
	 * Parameter must be one of the constants listed in mysqli_options().
132
	 * @see https://www.php.net/manual/en/mysqli.options.php
151
	 * @see https://www.php.net/manual/en/mysqli.options.php
-
 
152
	 * 
-
 
153
	 * OR 
-
 
154
	 * 
-
 
155
	 * Parameter must be a string matching one of the following special cases.
-
 
156
	 * 'ssl' - SSL values e.g. ('ssl' => ['ca' => '/path/to/ca.crt.pem'])
-
 
157
	 * 'clientflags' - Client flags of type 'MYSQLI_CLIENT_'
-
 
158
	 * @see https://www.php.net/manual/en/mysqli.real-connect.php
-
 
159
	 * @see https://www.php.net/manual/en/mysqli.constants.php
-
 
160
	 * 'socket' - The socket or named pipe that should be used
-
 
161
	 * 'port' - The port number to attempt to connect to the MySQL server
133
	 *
162
	 * 
134
	 * @param int    $parameter The parameter to set
163
	 * @param string|int $parameter The parameter to set
135
	 * @param string $value     The value of the parameter
164
	 * @param string|int|array $value The value of the parameter
136
	 *
165
	 *
137
	 * @return bool
166
	 * @return bool
138
	 */
167
	 */
-
 
168
	public function setConnectionParameter($parameter, $value) {
-
 
169
 
-
 
170
		// Special case for setting SSL values.
-
 
171
		if ("ssl" === $parameter && is_array($value)) {
-
 
172
			if (isset($value["key"])) {
-
 
173
				$this->ssl_key = $value["key"];
139
	public function setConnectionParameter($parameter, $value) {
174
			}
-
 
175
			if (isset($value["cert"])) {
-
 
176
				$this->ssl_cert = $value["cert"];
-
 
177
			}
-
 
178
			if (isset($value["ca"])) {
-
 
179
				$this->ssl_ca = $value["ca"];
-
 
180
			}
-
 
181
			if (isset($value["capath"])) {
-
 
182
				$this->ssl_capath = $value["capath"];
-
 
183
			}
-
 
184
			if (isset($value["cipher"])) {
-
 
185
				$this->ssl_cipher = $value["cipher"];
-
 
186
			}
-
 
187
 
-
 
188
			return true;
-
 
189
		}
-
 
190
 
140
		if(!is_numeric($parameter)) {
191
		// Special case for setting the client flag(s).
-
 
192
		if ("clientflags" === $parameter && is_numeric($value)) {
-
 
193
			$this->clientFlags = $value;
-
 
194
			return true;
-
 
195
		}
-
 
196
 
-
 
197
		// Special case for setting the socket.
-
 
198
		if ("socket" === $parameter && is_string($value)) {
-
 
199
			$this->socket = $value;
-
 
200
			return true;
-
 
201
		}
-
 
202
 
-
 
203
		// Special case for setting the port.
-
 
204
		if ("port" === $parameter && is_numeric($value)) {
141
			$this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__);
205
			$this->port = (int)$value;
-
 
206
			return true;
-
 
207
		}
-
 
208
 
-
 
209
		// Standard mysqli_options.
-
 
210
		if (is_numeric($parameter)) {
142
			return false;
211
			return parent::setConnectionParameter($parameter, $value);
-
 
212
		}
143
		}
213
 
-
 
214
		$this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__);
144
		return parent::setConnectionParameter($parameter, $value);
215
		return false;
Línea 145... Línea 216...
145
	}
216
	}
146
 
217
 
147
	/**
218
	/**
Línea 212... Línea 283...
212
			$argHostname = 'p:' . $argHostname;
283
			$argHostname = 'p:' . $argHostname;
213
		}
284
		}
Línea 214... Línea 285...
214
 
285
 
215
		// SSL Connections for MySQLI
286
		// SSL Connections for MySQLI
-
 
287
		if ($this->ssl_key || $this->ssl_cert || $this->ssl_ca || $this->ssl_capath || $this->ssl_cipher) {
216
		if ($this->ssl_key || $this->ssl_cert || $this->ssl_ca || $this->ssl_capath || $this->ssl_cipher) {
288
 
-
 
289
			mysqli_ssl_set($this->_connectionID, $this->ssl_key, $this->ssl_cert, $this->ssl_ca, $this->ssl_capath, $this->ssl_cipher);
-
 
290
 
217
			mysqli_ssl_set($this->_connectionID, $this->ssl_key, $this->ssl_cert, $this->ssl_ca, $this->ssl_capath, $this->ssl_cipher);
291
			// Check for any SSL client flag set, NOTE: bitwise operation.
218
			$this->socket = MYSQLI_CLIENT_SSL;
292
			if (!($this->clientFlags & MYSQLI_CLIENT_SSL)) {
-
 
293
        			ADOConnection::outp('When using certificates, set the client flag MYSQLI_CLIENT_SSL_VERIFY_SERVER_CERT or MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT');
-
 
294
				return false;
219
			$this->clientFlags = MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
295
			}
Línea 220... Línea 296...
220
		}
296
		}
221
 
297
 
222
		#if (!empty($this->port)) $argHostname .= ":".$this->port;
298
		#if (!empty($this->port)) $argHostname .= ":".$this->port;
Línea 942... Línea 1018...
942
				  FROM information_schema.columns
1018
				  FROM information_schema.columns
943
				 WHERE table_schema='{$this->database}'
1019
				 WHERE table_schema='{$this->database}'
944
				   AND table_name='$table'";
1020
				   AND table_name='$table'";
Línea 945... Línea 1021...
945
 
1021
 
-
 
1022
		$schemaArray = $this->getAssoc($SQL);
946
		$schemaArray = $this->getAssoc($SQL);
1023
		if (is_array($schemaArray)) {
-
 
1024
			$schemaArray = array_change_key_case($schemaArray,CASE_LOWER);
-
 
1025
			$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
Línea 947... Línea -...
947
		$schemaArray = array_change_key_case($schemaArray,CASE_LOWER);
-
 
948
 
1026
		}
949
		$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
1027
 
950
		if (isset($savem)) $this->SetFetchMode($savem);
1028
		if (isset($savem)) $this->SetFetchMode($savem);
951
		$ADODB_FETCH_MODE = $save;
1029
		$ADODB_FETCH_MODE = $save;
Línea 1099... Línea 1177...
1099
		return array($sql,$stmt);
1177
		return array($sql,$stmt);
1100
	}
1178
	}
Línea 1101... Línea 1179...
1101
 
1179
 
1102
	public function execute($sql, $inputarr = false)
1180
	public function execute($sql, $inputarr = false)
-
 
1181
	{
-
 
1182
		if ($this->doNotUseBoundVariables) {
-
 
1183
			return parent::execute($sql, $inputarr);
-
 
1184
		}
1103
	{
1185
 
1104
		if ($this->fnExecute) {
1186
		if ($this->fnExecute) {
1105
			$fn = $this->fnExecute;
1187
			$fn = $this->fnExecute;
1106
			$ret = $fn($this, $sql, $inputarr);
1188
			$ret = $fn($this, $sql, $inputarr);
1107
			if (isset($ret)) {
1189
			if (isset($ret)) {