PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
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 / lib / packages / Safe / deprecated / mssql.php

mssql.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Safe/deprecated/mssql.php

429 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_DEFENDER_VENDOR\Safe;
4
5 use WP_DEFENDER_VENDOR\Safe\Exceptions\MssqlException;
6
7 /**
8 * Binds a parameter to a stored procedure or a remote stored procedure.
9 *
10 * @param resource $stmt Statement resource, obtained with mssql_init.
11 * @param string $param_name The parameter name, as a string.
12 *
13 * You have to include the @ character, like in the
14 * T-SQL syntax. See the explanation included in
15 * mssql_execute.
16 * @param mixed $var The PHP variable you'll bind the MSSQL parameter to. It is passed by
17 * reference, to retrieve OUTPUT and RETVAL values after
18 * the procedure execution.
19 * @param int $type One of: SQLTEXT,
20 * SQLVARCHAR, SQLCHAR,
21 * SQLINT1, SQLINT2,
22 * SQLINT4, SQLBIT,
23 * SQLFLT4, SQLFLT8,
24 * SQLFLTN.
25 * @param bool $is_output Whether the value is an OUTPUT parameter or not. If it's an OUTPUT
26 * parameter and you don't mention it, it will be treated as a normal
27 * input parameter and no error will be thrown.
28 * @param bool $is_null Whether the parameter is NULL or not. Passing the NULL value as
29 * var will not do the job.
30 * @param int $maxlen Used with char/varchar values. You have to indicate the length of the
31 * data so if the parameter is a varchar(50), the type must be
32 * SQLVARCHAR and this value 50.
33 * @throws MssqlException
34 *
35 */
36 function mssql_bind($stmt, string $param_name, &$var, int $type, bool $is_output = false, bool $is_null = false, int $maxlen = -1): void
37 {
38 error_clear_last();
39 $result = \mssql_bind($stmt, $param_name, $var, $type, $is_output, $is_null, $maxlen);
40 if ($result === false) {
41 throw MssqlException::createFromPhpError();
42 }
43 }
44
45
46 /**
47 * Closes the link to a MS SQL Server database that's associated with the
48 * specified link identifier. If the link identifier isn't specified, the
49 * last opened link is assumed.
50 *
51 * Note that this isn't usually necessary, as non-persistent open
52 * links are automatically closed at the end of the script's
53 * execution.
54 *
55 * @param resource $link_identifier A MS SQL link identifier, returned by
56 * mssql_connect.
57 *
58 * This function will not close persistent links generated by
59 * mssql_pconnect.
60 * @throws MssqlException
61 *
62 */
63 function mssql_close($link_identifier = null): void
64 {
65 error_clear_last();
66 if ($link_identifier !== null) {
67 $result = \mssql_close($link_identifier);
68 } else {
69 $result = \mssql_close();
70 }
71 if ($result === false) {
72 throw MssqlException::createFromPhpError();
73 }
74 }
75
76
77 /**
78 * mssql_connect establishes a connection to a
79 * MS SQL server.
80 *
81 * The link to the server will be closed as soon as the execution of
82 * the script ends, unless it's closed earlier by explicitly calling
83 * mssql_close.
84 *
85 * @param string|null $servername The MS SQL server. It can also include a port number, e.g.
86 * hostname:port (Linux), or
87 * hostname,port (Windows).
88 * @param string|null $username The username.
89 * @param string|null $password The password.
90 * @param bool $new_link If a second call is made to mssql_connect with the
91 * same arguments, no new link will be established, but instead, the link
92 * identifier of the already opened link will be returned. This parameter
93 * modifies this behavior and makes mssql_connect
94 * always open a new link, even if mssql_connect was
95 * called before with the same parameters.
96 *
97 * @return resource Returns a MS SQL link identifier on success.
98 * @throws MssqlException
99 *
100 */
101 function mssql_connect( ?string $servername = null, ?string $username = null, ?string $password = null, bool $new_link = false)
102 {
103 error_clear_last();
104 if ($new_link !== false) {
105 $result = \mssql_connect($servername, $username, $password, $new_link);
106 } elseif ($password !== null) {
107 $result = \mssql_connect($servername, $username, $password);
108 } elseif ($username !== null) {
109 $result = \mssql_connect($servername, $username);
110 } elseif ($servername !== null) {
111 $result = \mssql_connect($servername);
112 } else {
113 $result = \mssql_connect();
114 }
115 if ($result === false) {
116 throw MssqlException::createFromPhpError();
117 }
118 return $result;
119 }
120
121
122 /**
123 * mssql_data_seek moves the internal row
124 * pointer of the MS SQL result associated with the specified result
125 * identifier to point to the specified row number, first row being
126 * number 0. The next call to mssql_fetch_row
127 * would return that row.
128 *
129 * @param resource $result_identifier The result resource that is being evaluated.
130 * @param int $row_number The desired row number of the new result pointer.
131 * @throws MssqlException
132 *
133 */
134 function mssql_data_seek($result_identifier, int $row_number): void
135 {
136 error_clear_last();
137 $result = \mssql_data_seek($result_identifier, $row_number);
138 if ($result === false) {
139 throw MssqlException::createFromPhpError();
140 }
141 }
142
143
144 /**
145 * Returns the length of field no. offset in
146 * result.
147 *
148 * @param resource $result The result resource that is being evaluated. This result comes from a
149 * call to mssql_query.
150 * @param int $offset The field offset, starts at 0. If omitted, the current field is used.
151 * @return int The length of the specified field index on success.
152 * @throws MssqlException
153 *
154 */
155 function mssql_field_length($result, int $offset = -1): int
156 {
157 error_clear_last();
158 $result = \mssql_field_length($result, $offset);
159 if ($result === false) {
160 throw MssqlException::createFromPhpError();
161 }
162 return $result;
163 }
164
165
166 /**
167 * Returns the name of field no. offset in
168 * result.
169 *
170 * @param resource $result The result resource that is being evaluated. This result comes from a
171 * call to mssql_query.
172 * @param int $offset The field offset, starts at 0. If omitted, the current field is used.
173 * @return string The name of the specified field index on success.
174 * @throws MssqlException
175 *
176 */
177 function mssql_field_name($result, int $offset = -1): string
178 {
179 error_clear_last();
180 $result = \mssql_field_name($result, $offset);
181 if ($result === false) {
182 throw MssqlException::createFromPhpError();
183 }
184 return $result;
185 }
186
187
188 /**
189 * Seeks to the specified field offset. If the next call to
190 * mssql_fetch_field won't include a field
191 * offset, this field would be returned.
192 *
193 * @param resource $result The result resource that is being evaluated. This result comes from a
194 * call to mssql_query.
195 * @param int $field_offset The field offset, starts at 0.
196 * @throws MssqlException
197 *
198 */
199 function mssql_field_seek($result, int $field_offset): void
200 {
201 error_clear_last();
202 $result = \mssql_field_seek($result, $field_offset);
203 if ($result === false) {
204 throw MssqlException::createFromPhpError();
205 }
206 }
207
208
209 /**
210 * Returns the type of field no. offset in
211 * result.
212 *
213 * @param resource $result The result resource that is being evaluated. This result comes from a
214 * call to mssql_query.
215 * @param int $offset The field offset, starts at 0. If omitted, the current field is used.
216 * @return string The type of the specified field index on success.
217 * @throws MssqlException
218 *
219 */
220 function mssql_field_type($result, int $offset = -1): string
221 {
222 error_clear_last();
223 $result = \mssql_field_type($result, $offset);
224 if ($result === false) {
225 throw MssqlException::createFromPhpError();
226 }
227 return $result;
228 }
229
230
231 /**
232 * mssql_free_result only needs to be called
233 * if you are worried about using too much memory while your script
234 * is running. All result memory will automatically be freed when
235 * the script ends. You may call mssql_free_result
236 * with the result identifier as an argument and the associated
237 * result memory will be freed.
238 *
239 * @param resource $result The result resource that is being freed. This result comes from a
240 * call to mssql_query.
241 * @throws MssqlException
242 *
243 */
244 function mssql_free_result($result): void
245 {
246 error_clear_last();
247 $result = \mssql_free_result($result);
248 if ($result === false) {
249 throw MssqlException::createFromPhpError();
250 }
251 }
252
253
254 /**
255 * mssql_free_statement only needs to be called
256 * if you are worried about using too much memory while your script
257 * is running. All statement memory will automatically be freed when
258 * the script ends. You may call mssql_free_statement
259 * with the statement identifier as an argument and the associated
260 * statement memory will be freed.
261 *
262 * @param resource $stmt Statement resource, obtained with mssql_init.
263 * @throws MssqlException
264 *
265 */
266 function mssql_free_statement($stmt): void
267 {
268 error_clear_last();
269 $result = \mssql_free_statement($stmt);
270 if ($result === false) {
271 throw MssqlException::createFromPhpError();
272 }
273 }
274
275
276 /**
277 * Initializes a stored procedure or a remote stored procedure.
278 *
279 * @param string $sp_name Stored procedure name, like ownew.sp_name or
280 * otherdb.owner.sp_name.
281 * @param resource $link_identifier A MS SQL link identifier, returned by
282 * mssql_connect.
283 * @return resource Returns a resource identifier "statement", used in subsequent calls to
284 * mssql_bind and mssql_executes.
285 * @throws MssqlException
286 *
287 */
288 function mssql_init(string $sp_name, $link_identifier = null)
289 {
290 error_clear_last();
291 if ($link_identifier !== null) {
292 $result = \mssql_init($sp_name, $link_identifier);
293 } else {
294 $result = \mssql_init($sp_name);
295 }
296 if ($result === false) {
297 throw MssqlException::createFromPhpError();
298 }
299 return $result;
300 }
301
302
303 /**
304 * mssql_pconnect acts very much like
305 * mssql_connect with two major differences.
306 *
307 * First, when connecting, the function would first try to find a
308 * (persistent) link that's already open with the same host,
309 * username and password. If one is found, an identifier for it
310 * will be returned instead of opening a new connection.
311 *
312 * Second, the connection to the SQL server will not be closed when
313 * the execution of the script ends. Instead, the link will remain
314 * open for future use (mssql_close will not
315 * close links established by mssql_pconnect).
316 *
317 * This type of links is therefore called 'persistent'.
318 *
319 * @param string|null $servername The MS SQL server. It can also include a port number. e.g.
320 * hostname:port.
321 * @param string|null $username The username.
322 * @param string|null $password The password.
323 * @param bool $new_link If a second call is made to mssql_pconnect with
324 * the same arguments, no new link will be established, but instead, the
325 * link identifier of the already opened link will be returned. This
326 * parameter modifies this behavior and makes
327 * mssql_pconnect always open a new link, even if
328 * mssql_pconnect was called before with the same
329 * parameters.
330 *
331 * @return resource Returns a positive MS SQL persistent link identifier on success.
332 * @throws MssqlException
333 *
334 */
335 function mssql_pconnect( ?string $servername = null, ?string $username = null, ?string $password = null, bool $new_link = false)
336 {
337 error_clear_last();
338 if ($new_link !== false) {
339 $result = \mssql_pconnect($servername, $username, $password, $new_link);
340 } elseif ($password !== null) {
341 $result = \mssql_pconnect($servername, $username, $password);
342 } elseif ($username !== null) {
343 $result = \mssql_pconnect($servername, $username);
344 } elseif ($servername !== null) {
345 $result = \mssql_pconnect($servername);
346 } else {
347 $result = \mssql_pconnect();
348 }
349 if ($result === false) {
350 throw MssqlException::createFromPhpError();
351 }
352 return $result;
353 }
354
355
356 /**
357 * mssql_query sends a query to the currently active
358 * database on the server that's associated with the specified link
359 * identifier.
360 *
361 * @param string $query An SQL query.
362 * @param resource $link_identifier A MS SQL link identifier, returned by
363 * mssql_connect or
364 * mssql_pconnect.
365 *
366 * If the link identifier isn't specified, the last opened link is
367 * assumed. If no link is open, the function tries to establish a link
368 * as if mssql_connect was called, and use it.
369 * @param int $batch_size The number of records to batch in the buffer.
370 * @return mixed Returns a MS SQL result resource on success, TRUE if no rows were
371 * returned.
372 * @throws MssqlException
373 *
374 */
375 function mssql_query(string $query, $link_identifier = null, int $batch_size = 0)
376 {
377 error_clear_last();
378 if ($batch_size !== 0) {
379 $result = \mssql_query($query, $link_identifier, $batch_size);
380 } elseif ($link_identifier !== null) {
381 $result = \mssql_query($query, $link_identifier);
382 } else {
383 $result = \mssql_query($query);
384 }
385 if ($result === false) {
386 throw MssqlException::createFromPhpError();
387 }
388 return $result;
389 }
390
391
392 /**
393 * mssql_select_db sets the current active
394 * database on the server that's associated with the specified link
395 * identifier.
396 *
397 * Every subsequent call to mssql_query will be
398 * made on the active database.
399 *
400 * @param string $database_name The database name.
401 *
402 * To escape the name of a database that contains spaces, hyphens ("-"),
403 * or any other exceptional characters, the database name must be
404 * enclosed in brackets, as is shown in the example, below. This
405 * technique must also be applied when selecting a database name that is
406 * also a reserved word (such as primary).
407 * @param resource $link_identifier A MS SQL link identifier, returned by
408 * mssql_connect or
409 * mssql_pconnect.
410 *
411 * If no link identifier is specified, the last opened link is assumed.
412 * If no link is open, the function will try to establish a link as if
413 * mssql_connect was called, and use it.
414 * @throws MssqlException
415 *
416 */
417 function mssql_select_db(string $database_name, $link_identifier = null): void
418 {
419 error_clear_last();
420 if ($link_identifier !== null) {
421 $result = \mssql_select_db($database_name, $link_identifier);
422 } else {
423 $result = \mssql_select_db($database_name);
424 }
425 if ($result === false) {
426 throw MssqlException::createFromPhpError();
427 }
428 }
429