Exceptions
5 days ago
apache.php
5 days ago
apcu.php
5 days ago
array.php
5 days ago
bzip2.php
5 days ago
calendar.php
5 days ago
classobj.php
5 days ago
com.php
5 days ago
cubrid.php
5 days ago
curl.php
5 days ago
datetime.php
5 days ago
dir.php
5 days ago
eio.php
5 days ago
errorfunc.php
5 days ago
exec.php
5 days ago
fileinfo.php
5 days ago
filesystem.php
5 days ago
filter.php
5 days ago
fpm.php
5 days ago
ftp.php
5 days ago
funchand.php
5 days ago
functionsList.php
5 days ago
gmp.php
5 days ago
gnupg.php
5 days ago
hash.php
5 days ago
ibase.php
5 days ago
ibmDb2.php
5 days ago
iconv.php
5 days ago
image.php
5 days ago
imap.php
5 days ago
info.php
5 days ago
ingres-ii.php
5 days ago
inotify.php
5 days ago
json.php
5 days ago
ldap.php
5 days ago
libxml.php
5 days ago
lzf.php
5 days ago
mailparse.php
5 days ago
mbstring.php
5 days ago
misc.php
5 days ago
msql.php
5 days ago
mysql.php
5 days ago
mysqli.php
5 days ago
mysqlndMs.php
5 days ago
mysqlndQc.php
5 days ago
network.php
5 days ago
oci8.php
5 days ago
opcache.php
5 days ago
openssl.php
5 days ago
outcontrol.php
5 days ago
password.php
5 days ago
pcntl.php
5 days ago
pcre.php
5 days ago
pdf.php
5 days ago
pgsql.php
5 days ago
posix.php
5 days ago
ps.php
5 days ago
pspell.php
5 days ago
readline.php
5 days ago
rpminfo.php
5 days ago
rrd.php
5 days ago
sem.php
5 days ago
session.php
5 days ago
shmop.php
5 days ago
simplexml.php
5 days ago
sockets.php
5 days ago
sodium.php
5 days ago
solr.php
5 days ago
spl.php
5 days ago
sqlsrv.php
5 days ago
ssdeep.php
5 days ago
ssh2.php
5 days ago
stream.php
5 days ago
strings.php
5 days ago
swoole.php
5 days ago
uodbc.php
5 days ago
uopz.php
5 days ago
url.php
5 days ago
var.php
5 days ago
xdiff.php
5 days ago
xml.php
5 days ago
xmlrpc.php
5 days ago
yaml.php
5 days ago
yaz.php
5 days ago
zip.php
5 days ago
zlib.php
5 days ago
sqlsrv.php
401 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\SqlsrvException; |
| 6 | /** |
| 7 | * The transaction begun by sqlsrv_begin_transaction includes |
| 8 | * all statements that were executed after the call to |
| 9 | * sqlsrv_begin_transaction and before calls to |
| 10 | * sqlsrv_rollback or sqlsrv_commit. |
| 11 | * Explicit transactions should be started and committed or rolled back using |
| 12 | * these functions instead of executing SQL statements that begin and commit/roll |
| 13 | * back transactions. For more information, see |
| 14 | * SQLSRV Transactions. |
| 15 | * |
| 16 | * @param resource $conn The connection resource returned by a call to sqlsrv_connect. |
| 17 | * @throws SqlsrvException |
| 18 | * |
| 19 | */ |
| 20 | function sqlsrv_begin_transaction($conn): void |
| 21 | { |
| 22 | error_clear_last(); |
| 23 | $result = \sqlsrv_begin_transaction($conn); |
| 24 | if ($result === \false) { |
| 25 | throw SqlsrvException::createFromPhpError(); |
| 26 | } |
| 27 | } |
| 28 | /** |
| 29 | * Cancels a statement. Any results associated with the statement that have not |
| 30 | * been consumed are deleted. After sqlsrv_cancel has been |
| 31 | * called, the specified statement can be re-executed if it was created with |
| 32 | * sqlsrv_prepare. Calling sqlsrv_cancel |
| 33 | * is not necessary if all the results associated with the statement have been |
| 34 | * consumed. |
| 35 | * |
| 36 | * @param resource $stmt The statement resource to be cancelled. |
| 37 | * @throws SqlsrvException |
| 38 | * |
| 39 | */ |
| 40 | function sqlsrv_cancel($stmt): void |
| 41 | { |
| 42 | error_clear_last(); |
| 43 | $result = \sqlsrv_cancel($stmt); |
| 44 | if ($result === \false) { |
| 45 | throw SqlsrvException::createFromPhpError(); |
| 46 | } |
| 47 | } |
| 48 | /** |
| 49 | * Returns information about the client and specified connection |
| 50 | * |
| 51 | * @param resource $conn The connection about which information is returned. |
| 52 | * @return array Returns an associative array with keys described in the table below. |
| 53 | * |
| 54 | * Array returned by sqlsrv_client_info |
| 55 | * |
| 56 | * |
| 57 | * |
| 58 | * Key |
| 59 | * Description |
| 60 | * |
| 61 | * |
| 62 | * |
| 63 | * |
| 64 | * DriverDllName |
| 65 | * SQLNCLI10.DLL |
| 66 | * |
| 67 | * |
| 68 | * DriverODBCVer |
| 69 | * ODBC version (xx.yy) |
| 70 | * |
| 71 | * |
| 72 | * DriverVer |
| 73 | * SQL Server Native Client DLL version (10.5.xxx) |
| 74 | * |
| 75 | * |
| 76 | * ExtensionVer |
| 77 | * php_sqlsrv.dll version (2.0.xxx.x) |
| 78 | * |
| 79 | * |
| 80 | * |
| 81 | * |
| 82 | * @throws SqlsrvException |
| 83 | * |
| 84 | */ |
| 85 | function sqlsrv_client_info($conn): array |
| 86 | { |
| 87 | error_clear_last(); |
| 88 | $result = \sqlsrv_client_info($conn); |
| 89 | if ($result === \false) { |
| 90 | throw SqlsrvException::createFromPhpError(); |
| 91 | } |
| 92 | return $result; |
| 93 | } |
| 94 | /** |
| 95 | * Closes an open connection and releases resourses associated with the connection. |
| 96 | * |
| 97 | * @param resource $conn The connection to be closed. |
| 98 | * @throws SqlsrvException |
| 99 | * |
| 100 | */ |
| 101 | function sqlsrv_close($conn): void |
| 102 | { |
| 103 | error_clear_last(); |
| 104 | $result = \sqlsrv_close($conn); |
| 105 | if ($result === \false) { |
| 106 | throw SqlsrvException::createFromPhpError(); |
| 107 | } |
| 108 | } |
| 109 | /** |
| 110 | * Commits a transaction that was begun with sqlsrv_begin_transaction. |
| 111 | * The connection is returned to auto-commit mode after sqlsrv_commit |
| 112 | * is called. The transaction that is committed includes all statements that were |
| 113 | * executed after the call to sqlsrv_begin_transaction. |
| 114 | * Explicit transactions should be started and committed or rolled back using these |
| 115 | * functions instead of executing SQL statements that begin and commit/roll back |
| 116 | * transactions. For more information, see |
| 117 | * SQLSRV Transactions. |
| 118 | * |
| 119 | * @param resource $conn The connection on which the transaction is to be committed. |
| 120 | * @throws SqlsrvException |
| 121 | * |
| 122 | */ |
| 123 | function sqlsrv_commit($conn): void |
| 124 | { |
| 125 | error_clear_last(); |
| 126 | $result = \sqlsrv_commit($conn); |
| 127 | if ($result === \false) { |
| 128 | throw SqlsrvException::createFromPhpError(); |
| 129 | } |
| 130 | } |
| 131 | /** |
| 132 | * Changes the driver error handling and logging configurations. |
| 133 | * |
| 134 | * @param string $setting The name of the setting to set. The possible values are |
| 135 | * "WarningsReturnAsErrors", "LogSubsystems", and "LogSeverity". |
| 136 | * @param mixed $value The value of the specified setting. The following table shows possible values: |
| 137 | * |
| 138 | * Error and Logging Setting Options |
| 139 | * |
| 140 | * |
| 141 | * |
| 142 | * Setting |
| 143 | * Options |
| 144 | * |
| 145 | * |
| 146 | * |
| 147 | * |
| 148 | * WarningsReturnAsErrors |
| 149 | * 1 (TRUE) or 0 (FALSE) |
| 150 | * |
| 151 | * |
| 152 | * LogSubsystems |
| 153 | * SQLSRV_LOG_SYSTEM_ALL (-1) |
| 154 | * SQLSRV_LOG_SYSTEM_CONN (2) |
| 155 | * SQLSRV_LOG_SYSTEM_INIT (1) |
| 156 | * SQLSRV_LOG_SYSTEM_OFF (0) |
| 157 | * SQLSRV_LOG_SYSTEM_STMT (4) |
| 158 | * SQLSRV_LOG_SYSTEM_UTIL (8) |
| 159 | * |
| 160 | * |
| 161 | * LogSeverity |
| 162 | * SQLSRV_LOG_SEVERITY_ALL (-1) |
| 163 | * SQLSRV_LOG_SEVERITY_ERROR (1) |
| 164 | * SQLSRV_LOG_SEVERITY_NOTICE (4) |
| 165 | * SQLSRV_LOG_SEVERITY_WARNING (2) |
| 166 | * |
| 167 | * |
| 168 | * |
| 169 | * |
| 170 | * @throws SqlsrvException |
| 171 | * |
| 172 | */ |
| 173 | function sqlsrv_configure(string $setting, $value): void |
| 174 | { |
| 175 | error_clear_last(); |
| 176 | $result = \sqlsrv_configure($setting, $value); |
| 177 | if ($result === \false) { |
| 178 | throw SqlsrvException::createFromPhpError(); |
| 179 | } |
| 180 | } |
| 181 | /** |
| 182 | * Executes a statement prepared with sqlsrv_prepare. This |
| 183 | * function is ideal for executing a prepared statement multiple times with |
| 184 | * different parameter values. |
| 185 | * |
| 186 | * @param resource $stmt A statement resource returned by sqlsrv_prepare. |
| 187 | * @throws SqlsrvException |
| 188 | * |
| 189 | */ |
| 190 | function sqlsrv_execute($stmt): void |
| 191 | { |
| 192 | error_clear_last(); |
| 193 | $result = \sqlsrv_execute($stmt); |
| 194 | if ($result === \false) { |
| 195 | throw SqlsrvException::createFromPhpError(); |
| 196 | } |
| 197 | } |
| 198 | /** |
| 199 | * Frees all resources for the specified statement. The statement cannot be used |
| 200 | * after sqlsrv_free_stmt has been called on it. If |
| 201 | * sqlsrv_free_stmt is called on an in-progress statement |
| 202 | * that alters server state, statement execution is terminated and the statement |
| 203 | * is rolled back. |
| 204 | * |
| 205 | * @param resource $stmt The statement for which resources are freed. |
| 206 | * Note that NULL is a valid parameter value. This allows the function to be |
| 207 | * called multiple times in a script. |
| 208 | * @throws SqlsrvException |
| 209 | * |
| 210 | */ |
| 211 | function sqlsrv_free_stmt($stmt): void |
| 212 | { |
| 213 | error_clear_last(); |
| 214 | $result = \sqlsrv_free_stmt($stmt); |
| 215 | if ($result === \false) { |
| 216 | throw SqlsrvException::createFromPhpError(); |
| 217 | } |
| 218 | } |
| 219 | /** |
| 220 | * Gets field data from the currently selected row. Fields must be accessed in |
| 221 | * order. Field indices start at 0. |
| 222 | * |
| 223 | * @param resource $stmt A statement resource returned by sqlsrv_query or |
| 224 | * sqlsrv_execute. |
| 225 | * @param int $fieldIndex The index of the field to be retrieved. Field indices start at 0. Fields |
| 226 | * must be accessed in order. i.e. If you access field index 1, then field |
| 227 | * index 0 will not be available. |
| 228 | * @param int $getAsType The PHP data type for the returned field data. If this parameter is not |
| 229 | * set, the field data will be returned as its default PHP data type. |
| 230 | * For information about default PHP data types, see |
| 231 | * Default PHP Data Types |
| 232 | * in the Microsoft SQLSRV documentation. |
| 233 | * @return mixed Returns data from the specified field on success. |
| 234 | * @throws SqlsrvException |
| 235 | * |
| 236 | */ |
| 237 | function sqlsrv_get_field($stmt, int $fieldIndex, int $getAsType = null) |
| 238 | { |
| 239 | error_clear_last(); |
| 240 | if ($getAsType !== null) { |
| 241 | $result = \sqlsrv_get_field($stmt, $fieldIndex, $getAsType); |
| 242 | } else { |
| 243 | $result = \sqlsrv_get_field($stmt, $fieldIndex); |
| 244 | } |
| 245 | if ($result === \false) { |
| 246 | throw SqlsrvException::createFromPhpError(); |
| 247 | } |
| 248 | return $result; |
| 249 | } |
| 250 | /** |
| 251 | * Makes the next result of the specified statement active. Results include result |
| 252 | * sets, row counts, and output parameters. |
| 253 | * |
| 254 | * @param resource $stmt The statement on which the next result is being called. |
| 255 | * @return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error |
| 256 | * occurred, and NULL if there are no more results to retrieve. |
| 257 | * @throws SqlsrvException |
| 258 | * |
| 259 | */ |
| 260 | function sqlsrv_next_result($stmt): ?bool |
| 261 | { |
| 262 | error_clear_last(); |
| 263 | $result = \sqlsrv_next_result($stmt); |
| 264 | if ($result === \false) { |
| 265 | throw SqlsrvException::createFromPhpError(); |
| 266 | } |
| 267 | return $result; |
| 268 | } |
| 269 | /** |
| 270 | * Retrieves the number of fields (columns) on a statement. |
| 271 | * |
| 272 | * @param resource $stmt The statement for which the number of fields is returned. |
| 273 | * sqlsrv_num_fields can be called on a statement before |
| 274 | * or after statement execution. |
| 275 | * @return int Returns the number of fields on success. |
| 276 | * @throws SqlsrvException |
| 277 | * |
| 278 | */ |
| 279 | function sqlsrv_num_fields($stmt): int |
| 280 | { |
| 281 | error_clear_last(); |
| 282 | $result = \sqlsrv_num_fields($stmt); |
| 283 | if ($result === \false) { |
| 284 | throw SqlsrvException::createFromPhpError(); |
| 285 | } |
| 286 | return $result; |
| 287 | } |
| 288 | /** |
| 289 | * Retrieves the number of rows in a result set. This function requires that the |
| 290 | * statement resource be created with a static or keyset cursor. For more information, |
| 291 | * see sqlsrv_query, sqlsrv_prepare, |
| 292 | * or Specifying a Cursor Type and Selecting Rows |
| 293 | * in the Microsoft SQLSRV documentation. |
| 294 | * |
| 295 | * @param resource $stmt The statement for which the row count is returned. The statement resource |
| 296 | * must be created with a static or keyset cursor. For more information, see |
| 297 | * sqlsrv_query, sqlsrv_prepare, or |
| 298 | * Specifying a Cursor Type and Selecting Rows |
| 299 | * in the Microsoft SQLSRV documentation. |
| 300 | * @return int Returns the number of rows retrieved on success. |
| 301 | * If a forward cursor (the default) or dynamic cursor is used, FALSE is returned. |
| 302 | * @throws SqlsrvException |
| 303 | * |
| 304 | */ |
| 305 | function sqlsrv_num_rows($stmt): int |
| 306 | { |
| 307 | error_clear_last(); |
| 308 | $result = \sqlsrv_num_rows($stmt); |
| 309 | if ($result === \false) { |
| 310 | throw SqlsrvException::createFromPhpError(); |
| 311 | } |
| 312 | return $result; |
| 313 | } |
| 314 | /** |
| 315 | * Prepares a query for execution. This function is ideal for preparing a query |
| 316 | * that will be executed multiple times with different parameter values. |
| 317 | * |
| 318 | * @param resource $conn A connection resource returned by sqlsrv_connect. |
| 319 | * @param string $sql The string that defines the query to be prepared and executed. |
| 320 | * @param array $params An array specifying parameter information when executing a parameterized |
| 321 | * query. Array elements can be any of the following: |
| 322 | * |
| 323 | * A literal value |
| 324 | * A PHP variable |
| 325 | * An array with this structure: |
| 326 | * array($value [, $direction [, $phpType [, $sqlType]]]) |
| 327 | * |
| 328 | * The following table describes the elements in the array structure above: |
| 329 | * @param array $options An array specifying query property options. The supported keys are described |
| 330 | * in the following table: |
| 331 | * @return resource Returns a statement resource on success. |
| 332 | * @throws SqlsrvException |
| 333 | * |
| 334 | */ |
| 335 | function sqlsrv_prepare($conn, string $sql, array $params = null, array $options = null) |
| 336 | { |
| 337 | error_clear_last(); |
| 338 | if ($options !== null) { |
| 339 | $result = \sqlsrv_prepare($conn, $sql, $params, $options); |
| 340 | } elseif ($params !== null) { |
| 341 | $result = \sqlsrv_prepare($conn, $sql, $params); |
| 342 | } else { |
| 343 | $result = \sqlsrv_prepare($conn, $sql); |
| 344 | } |
| 345 | if ($result === \false) { |
| 346 | throw SqlsrvException::createFromPhpError(); |
| 347 | } |
| 348 | return $result; |
| 349 | } |
| 350 | /** |
| 351 | * Prepares and executes a query. |
| 352 | * |
| 353 | * @param resource $conn A connection resource returned by sqlsrv_connect. |
| 354 | * @param string $sql The string that defines the query to be prepared and executed. |
| 355 | * @param array $params An array specifying parameter information when executing a parameterized query. |
| 356 | * Array elements can be any of the following: |
| 357 | * |
| 358 | * A literal value |
| 359 | * A PHP variable |
| 360 | * An array with this structure: |
| 361 | * array($value [, $direction [, $phpType [, $sqlType]]]) |
| 362 | * |
| 363 | * The following table describes the elements in the array structure above: |
| 364 | * @param array $options An array specifying query property options. The supported keys are described |
| 365 | * in the following table: |
| 366 | * @return resource Returns a statement resource on success. |
| 367 | * @throws SqlsrvException |
| 368 | * |
| 369 | */ |
| 370 | function sqlsrv_query($conn, string $sql, array $params = null, array $options = null) |
| 371 | { |
| 372 | error_clear_last(); |
| 373 | if ($options !== null) { |
| 374 | $result = \sqlsrv_query($conn, $sql, $params, $options); |
| 375 | } elseif ($params !== null) { |
| 376 | $result = \sqlsrv_query($conn, $sql, $params); |
| 377 | } else { |
| 378 | $result = \sqlsrv_query($conn, $sql); |
| 379 | } |
| 380 | if ($result === \false) { |
| 381 | throw SqlsrvException::createFromPhpError(); |
| 382 | } |
| 383 | return $result; |
| 384 | } |
| 385 | /** |
| 386 | * Rolls back a transaction that was begun with sqlsrv_begin_transaction |
| 387 | * and returns the connection to auto-commit mode. |
| 388 | * |
| 389 | * @param resource $conn The connection resource returned by a call to sqlsrv_connect. |
| 390 | * @throws SqlsrvException |
| 391 | * |
| 392 | */ |
| 393 | function sqlsrv_rollback($conn): void |
| 394 | { |
| 395 | error_clear_last(); |
| 396 | $result = \sqlsrv_rollback($conn); |
| 397 | if ($result === \false) { |
| 398 | throw SqlsrvException::createFromPhpError(); |
| 399 | } |
| 400 | } |
| 401 |