summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/generated/sqlsrv.php
blob: e93aa37af57b830451953c4f51a85df43b6db4d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?php

namespace Safe;

use Safe\Exceptions\SqlsrvException;

/**
 * The transaction begun by sqlsrv_begin_transaction includes
 * all statements that were executed after the call to
 * sqlsrv_begin_transaction and before calls to
 * sqlsrv_rollback or sqlsrv_commit.
 * Explicit transactions should be started and committed or rolled back using
 * these functions instead of executing SQL statements that begin and commit/roll
 * back transactions. For more information, see
 * SQLSRV Transactions.
 *
 * @param resource $conn The connection resource returned by a call to sqlsrv_connect.
 * @throws SqlsrvException
 *
 */
function sqlsrv_begin_transaction($conn): void
{
    error_clear_last();
    $result = \sqlsrv_begin_transaction($conn);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Cancels a statement. Any results associated with the statement that have not
 * been consumed are deleted. After sqlsrv_cancel has been
 * called, the specified statement can be re-executed if it was created with
 * sqlsrv_prepare. Calling sqlsrv_cancel
 * is not necessary if all the results associated with the statement have been
 * consumed.
 *
 * @param resource $stmt The statement resource to be cancelled.
 * @throws SqlsrvException
 *
 */
function sqlsrv_cancel($stmt): void
{
    error_clear_last();
    $result = \sqlsrv_cancel($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Returns information about the client and specified connection
 *
 * @param resource $conn The connection about which information is returned.
 * @return array Returns an associative array with keys described in the table below.
 *
 * Array returned by sqlsrv_client_info
 *
 *
 *
 * Key
 * Description
 *
 *
 *
 *
 * DriverDllName
 * SQLNCLI10.DLL
 *
 *
 * DriverODBCVer
 * ODBC version (xx.yy)
 *
 *
 * DriverVer
 * SQL Server Native Client DLL version (10.5.xxx)
 *
 *
 * ExtensionVer
 * php_sqlsrv.dll version (2.0.xxx.x)
 *
 *
 *
 *
 * @throws SqlsrvException
 *
 */
function sqlsrv_client_info($conn): array
{
    error_clear_last();
    $result = \sqlsrv_client_info($conn);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Closes an open connection and releases resourses associated with the connection.
 *
 * @param resource $conn The connection to be closed.
 * @throws SqlsrvException
 *
 */
function sqlsrv_close($conn): void
{
    error_clear_last();
    $result = \sqlsrv_close($conn);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Commits a transaction that was begun with sqlsrv_begin_transaction.
 * The connection is returned to auto-commit mode after sqlsrv_commit
 * is called. The transaction that is committed includes all statements that were
 * executed after the call to sqlsrv_begin_transaction.
 * Explicit transactions should be started and committed or rolled back using these
 * functions instead of executing SQL statements that begin and commit/roll back
 * transactions. For more information, see
 * SQLSRV Transactions.
 *
 * @param resource $conn The connection on which the transaction is to be committed.
 * @throws SqlsrvException
 *
 */
function sqlsrv_commit($conn): void
{
    error_clear_last();
    $result = \sqlsrv_commit($conn);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Changes the driver error handling and logging configurations.
 *
 * @param string $setting The name of the setting to set. The possible values are
 * "WarningsReturnAsErrors", "LogSubsystems", and "LogSeverity".
 * @param mixed $value The value of the specified setting. The following table shows possible values:
 *
 * Error and Logging Setting Options
 *
 *
 *
 * Setting
 * Options
 *
 *
 *
 *
 * WarningsReturnAsErrors
 * 1 (TRUE) or 0 (FALSE)
 *
 *
 * LogSubsystems
 * SQLSRV_LOG_SYSTEM_ALL (-1)
 * SQLSRV_LOG_SYSTEM_CONN (2)
 * SQLSRV_LOG_SYSTEM_INIT (1)
 * SQLSRV_LOG_SYSTEM_OFF (0)
 * SQLSRV_LOG_SYSTEM_STMT (4)
 * SQLSRV_LOG_SYSTEM_UTIL (8)
 *
 *
 * LogSeverity
 * SQLSRV_LOG_SEVERITY_ALL (-1)
 * SQLSRV_LOG_SEVERITY_ERROR (1)
 * SQLSRV_LOG_SEVERITY_NOTICE (4)
 * SQLSRV_LOG_SEVERITY_WARNING (2)
 *
 *
 *
 *
 * @throws SqlsrvException
 *
 */
function sqlsrv_configure(string $setting, $value): void
{
    error_clear_last();
    $result = \sqlsrv_configure($setting, $value);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Executes a statement prepared with sqlsrv_prepare. This
 * function is ideal for executing a prepared statement multiple times with
 * different parameter values.
 *
 * @param resource $stmt A statement resource returned by sqlsrv_prepare.
 * @throws SqlsrvException
 *
 */
function sqlsrv_execute($stmt): void
{
    error_clear_last();
    $result = \sqlsrv_execute($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Frees all resources for the specified statement. The statement cannot be used
 * after sqlsrv_free_stmt has been called on it. If
 * sqlsrv_free_stmt is called on an in-progress statement
 * that alters server state, statement execution is terminated and the statement
 * is rolled back.
 *
 * @param resource $stmt The statement for which resources are freed.
 * Note that NULL is a valid parameter value. This allows the function to be
 * called multiple times in a script.
 * @throws SqlsrvException
 *
 */
function sqlsrv_free_stmt($stmt): void
{
    error_clear_last();
    $result = \sqlsrv_free_stmt($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}


/**
 * Gets field data from the currently selected row. Fields must be accessed in
 * order. Field indices start at 0.
 *
 * @param resource $stmt A statement resource returned by sqlsrv_query or
 * sqlsrv_execute.
 * @param int $fieldIndex The index of the field to be retrieved. Field indices start at 0. Fields
 * must be accessed in order. i.e. If you access field index 1, then field
 * index 0 will not be available.
 * @param int $getAsType The PHP data type for the returned field data. If this parameter is not
 * set, the field data will be returned as its default PHP data type.
 * For information about default PHP data types, see
 * Default PHP Data Types
 * in the Microsoft SQLSRV documentation.
 * @return mixed Returns data from the specified field on success.
 * @throws SqlsrvException
 *
 */
function sqlsrv_get_field($stmt, int $fieldIndex, int $getAsType = null)
{
    error_clear_last();
    if ($getAsType !== null) {
        $result = \sqlsrv_get_field($stmt, $fieldIndex, $getAsType);
    } else {
        $result = \sqlsrv_get_field($stmt, $fieldIndex);
    }
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Makes the next result of the specified statement active. Results include result
 * sets, row counts, and output parameters.
 *
 * @param resource $stmt The statement on which the next result is being called.
 * @return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error
 * occurred, and NULL if there are no more results to retrieve.
 * @throws SqlsrvException
 *
 */
function sqlsrv_next_result($stmt): ?bool
{
    error_clear_last();
    $result = \sqlsrv_next_result($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Retrieves the number of fields (columns) on a statement.
 *
 * @param resource $stmt The statement for which the number of fields is returned.
 * sqlsrv_num_fields can be called on a statement before
 * or after statement execution.
 * @return int Returns the number of fields on success.
 * @throws SqlsrvException
 *
 */
function sqlsrv_num_fields($stmt): int
{
    error_clear_last();
    $result = \sqlsrv_num_fields($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Retrieves the number of rows in a result set. This function requires that the
 * statement resource be created with a static or keyset cursor. For more information,
 * see sqlsrv_query, sqlsrv_prepare,
 * or Specifying a Cursor Type and Selecting Rows
 * in the Microsoft SQLSRV documentation.
 *
 * @param resource $stmt The statement for which the row count is returned. The statement resource
 * must be created with a static or keyset cursor. For more information, see
 * sqlsrv_query, sqlsrv_prepare, or
 * Specifying a Cursor Type and Selecting Rows
 * in the Microsoft SQLSRV documentation.
 * @return int Returns the number of rows retrieved on success.
 * If a forward cursor (the default) or dynamic cursor is used, FALSE is returned.
 * @throws SqlsrvException
 *
 */
function sqlsrv_num_rows($stmt): int
{
    error_clear_last();
    $result = \sqlsrv_num_rows($stmt);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Prepares a query for execution. This function is ideal for preparing a query
 * that will be executed multiple times with different parameter values.
 *
 * @param resource $conn A connection resource returned by sqlsrv_connect.
 * @param string $sql The string that defines the query to be prepared and executed.
 * @param array $params An array specifying parameter information when executing a parameterized
 * query. Array elements can be any of the following:
 *
 * A literal value
 * A PHP variable
 * An array with this structure:
 * array($value [, $direction [, $phpType [, $sqlType]]])
 *
 * The following table describes the elements in the array structure above:
 * @param array $options An array specifying query property options. The supported keys are described
 * in the following table:
 * @return resource Returns a statement resource on success.
 * @throws SqlsrvException
 *
 */
function sqlsrv_prepare($conn, string $sql, array $params = null, array $options = null)
{
    error_clear_last();
    if ($options !== null) {
        $result = \sqlsrv_prepare($conn, $sql, $params, $options);
    } elseif ($params !== null) {
        $result = \sqlsrv_prepare($conn, $sql, $params);
    } else {
        $result = \sqlsrv_prepare($conn, $sql);
    }
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Prepares and executes a query.
 *
 * @param resource $conn A connection resource returned by sqlsrv_connect.
 * @param string $sql The string that defines the query to be prepared and executed.
 * @param array $params An array specifying parameter information when executing a parameterized query.
 * Array elements can be any of the following:
 *
 * A literal value
 * A PHP variable
 * An array with this structure:
 * array($value [, $direction [, $phpType [, $sqlType]]])
 *
 * The following table describes the elements in the array structure above:
 * @param array $options An array specifying query property options. The supported keys are described
 * in the following table:
 * @return resource Returns a statement resource on success.
 * @throws SqlsrvException
 *
 */
function sqlsrv_query($conn, string $sql, array $params = null, array $options = null)
{
    error_clear_last();
    if ($options !== null) {
        $result = \sqlsrv_query($conn, $sql, $params, $options);
    } elseif ($params !== null) {
        $result = \sqlsrv_query($conn, $sql, $params);
    } else {
        $result = \sqlsrv_query($conn, $sql);
    }
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
    return $result;
}


/**
 * Rolls back a transaction that was begun with sqlsrv_begin_transaction
 * and returns the connection to auto-commit mode.
 *
 * @param resource $conn The connection resource returned by a call to sqlsrv_connect.
 * @throws SqlsrvException
 *
 */
function sqlsrv_rollback($conn): void
{
    error_clear_last();
    $result = \sqlsrv_rollback($conn);
    if ($result === false) {
        throw SqlsrvException::createFromPhpError();
    }
}