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
oci8.php
1647 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Safe; |
| 4 | |
| 5 | use ProfilePressVendor\Safe\Exceptions\Oci8Exception; |
| 6 | /** |
| 7 | * Binds the PHP array var_array to the Oracle |
| 8 | * placeholder name, which points to an Oracle PL/SQL |
| 9 | * array. Whether it will be used for input or output will be determined at |
| 10 | * run-time. |
| 11 | * |
| 12 | * @param resource $statement A valid OCI statement identifier. |
| 13 | * @param string $name The Oracle placeholder. |
| 14 | * @param array $var_array An array. |
| 15 | * @param int $max_table_length Sets the maximum length both for incoming and result arrays. |
| 16 | * @param int $max_item_length Sets maximum length for array items. If not specified or equals to -1, |
| 17 | * oci_bind_array_by_name will find the longest |
| 18 | * element in the incoming array and will use it as the maximum length. |
| 19 | * @param int $type Should be used to set the type of PL/SQL array items. See list of |
| 20 | * available types below: |
| 21 | * |
| 22 | * |
| 23 | * |
| 24 | * |
| 25 | * SQLT_NUM - for arrays of NUMBER. |
| 26 | * |
| 27 | * |
| 28 | * |
| 29 | * |
| 30 | * SQLT_INT - for arrays of INTEGER (Note: INTEGER |
| 31 | * it is actually a synonym for NUMBER(38), but |
| 32 | * SQLT_NUM type won't work in this case even |
| 33 | * though they are synonyms). |
| 34 | * |
| 35 | * |
| 36 | * |
| 37 | * |
| 38 | * SQLT_FLT - for arrays of FLOAT. |
| 39 | * |
| 40 | * |
| 41 | * |
| 42 | * |
| 43 | * SQLT_AFC - for arrays of CHAR. |
| 44 | * |
| 45 | * |
| 46 | * |
| 47 | * |
| 48 | * SQLT_CHR - for arrays of VARCHAR2. |
| 49 | * |
| 50 | * |
| 51 | * |
| 52 | * |
| 53 | * SQLT_VCS - for arrays of VARCHAR. |
| 54 | * |
| 55 | * |
| 56 | * |
| 57 | * |
| 58 | * SQLT_AVC - for arrays of CHARZ. |
| 59 | * |
| 60 | * |
| 61 | * |
| 62 | * |
| 63 | * SQLT_STR - for arrays of STRING. |
| 64 | * |
| 65 | * |
| 66 | * |
| 67 | * |
| 68 | * SQLT_LVC - for arrays of LONG VARCHAR. |
| 69 | * |
| 70 | * |
| 71 | * |
| 72 | * |
| 73 | * SQLT_ODT - for arrays of DATE. |
| 74 | * |
| 75 | * |
| 76 | * |
| 77 | * |
| 78 | * SQLT_NUM - for arrays of NUMBER. |
| 79 | * |
| 80 | * SQLT_INT - for arrays of INTEGER (Note: INTEGER |
| 81 | * it is actually a synonym for NUMBER(38), but |
| 82 | * SQLT_NUM type won't work in this case even |
| 83 | * though they are synonyms). |
| 84 | * |
| 85 | * SQLT_FLT - for arrays of FLOAT. |
| 86 | * |
| 87 | * SQLT_AFC - for arrays of CHAR. |
| 88 | * |
| 89 | * SQLT_CHR - for arrays of VARCHAR2. |
| 90 | * |
| 91 | * SQLT_VCS - for arrays of VARCHAR. |
| 92 | * |
| 93 | * SQLT_AVC - for arrays of CHARZ. |
| 94 | * |
| 95 | * SQLT_STR - for arrays of STRING. |
| 96 | * |
| 97 | * SQLT_LVC - for arrays of LONG VARCHAR. |
| 98 | * |
| 99 | * SQLT_ODT - for arrays of DATE. |
| 100 | * @throws Oci8Exception |
| 101 | * |
| 102 | */ |
| 103 | function oci_bind_array_by_name($statement, string $name, array &$var_array, int $max_table_length, int $max_item_length = -1, int $type = \SQLT_AFC): void |
| 104 | { |
| 105 | error_clear_last(); |
| 106 | $result = \oci_bind_array_by_name($statement, $name, $var_array, $max_table_length, $max_item_length, $type); |
| 107 | if ($result === \false) { |
| 108 | throw Oci8Exception::createFromPhpError(); |
| 109 | } |
| 110 | } |
| 111 | /** |
| 112 | * Binds a PHP variable variable to the Oracle |
| 113 | * bind variable placeholder bv_name. Binding |
| 114 | * is important for Oracle database performance and also as a way to |
| 115 | * avoid SQL Injection security issues. |
| 116 | * |
| 117 | * Binding allows the database to reuse the statement context and |
| 118 | * caches from previous executions of the statement, even if another |
| 119 | * user or process originally executed it. Binding reduces SQL |
| 120 | * Injection concerns because the data associated with a bind |
| 121 | * variable is never treated as part of the SQL statement. It does |
| 122 | * not need quoting or escaping. |
| 123 | * |
| 124 | * PHP variables that have been bound can be changed and the |
| 125 | * statement re-executed without needing to re-parse the statement or |
| 126 | * re-bind. |
| 127 | * |
| 128 | * In Oracle, bind variables are commonly divided |
| 129 | * into IN binds for values that are passed into |
| 130 | * the database, and OUT binds for values that are |
| 131 | * returned to PHP. A bind variable may be |
| 132 | * both IN and OUT. Whether a |
| 133 | * bind variable will be used for input or output is determined at |
| 134 | * run-time. |
| 135 | * |
| 136 | * You must specify maxlength when using |
| 137 | * an OUT bind so that PHP allocates enough memory |
| 138 | * to hold the returned value. |
| 139 | * |
| 140 | * For IN binds it is recommended to set |
| 141 | * the maxlength length if the statement is |
| 142 | * re-executed multiple times with different values for the PHP |
| 143 | * variable. Otherwise Oracle may truncate data to the length of the |
| 144 | * initial PHP variable value. If you don't know what the maximum |
| 145 | * length will be, then re-call oci_bind_by_name |
| 146 | * with the current data size prior to |
| 147 | * each oci_execute call. Binding an |
| 148 | * unnecessarily large length will have an impact on process memory |
| 149 | * in the database. |
| 150 | * |
| 151 | * A bind call tells Oracle which memory address to read data from. |
| 152 | * For IN binds that address needs to contain |
| 153 | * valid data when oci_execute is called. This |
| 154 | * means that the variable bound must remain in scope until |
| 155 | * execution. If it doesn't, unexpected results or errors such as |
| 156 | * "ORA-01460: unimplemented or unreasonable conversion requested" |
| 157 | * may occur. For OUT binds one symptom is no |
| 158 | * value being set in the PHP variable. |
| 159 | * |
| 160 | * For a statement that is repeatedly executed, binding values that |
| 161 | * never change may reduce the ability of the Oracle optimizer to |
| 162 | * choose the best statement execution plan. Long running statements |
| 163 | * that are rarely re-executed may not benefit from binding. However |
| 164 | * in both cases, binding might be safer than joining strings into a |
| 165 | * SQL statement, as this can be a security risk if unfiltered user |
| 166 | * text is concatenated. |
| 167 | * |
| 168 | * @param resource $statement A valid OCI8 statement identifer. |
| 169 | * @param string $bv_name The colon-prefixed bind variable placeholder used in the |
| 170 | * statement. The colon is optional |
| 171 | * in bv_name. Oracle does not use question |
| 172 | * marks for placeholders. |
| 173 | * @param mixed $variable The PHP variable to be associated with bv_name |
| 174 | * @param int $maxlength Sets the maximum length for the data. If you set it to -1, this |
| 175 | * function will use the current length |
| 176 | * of variable to set the maximum |
| 177 | * length. In this case the variable must |
| 178 | * exist and contain data |
| 179 | * when oci_bind_by_name is called. |
| 180 | * @param int $type The datatype that Oracle will treat the data as. The |
| 181 | * default type used |
| 182 | * is SQLT_CHR. Oracle will convert the data |
| 183 | * between this type and the database column (or PL/SQL variable |
| 184 | * type), when possible. |
| 185 | * |
| 186 | * If you need to bind an abstract datatype (LOB/ROWID/BFILE) you |
| 187 | * need to allocate it first using the |
| 188 | * oci_new_descriptor function. The |
| 189 | * length is not used for abstract datatypes |
| 190 | * and should be set to -1. |
| 191 | * |
| 192 | * Possible values for type are: |
| 193 | * |
| 194 | * |
| 195 | * |
| 196 | * SQLT_BFILEE or OCI_B_BFILE |
| 197 | * - for BFILEs; |
| 198 | * |
| 199 | * |
| 200 | * |
| 201 | * |
| 202 | * SQLT_CFILEE or OCI_B_CFILEE |
| 203 | * - for CFILEs; |
| 204 | * |
| 205 | * |
| 206 | * |
| 207 | * |
| 208 | * SQLT_CLOB or OCI_B_CLOB |
| 209 | * - for CLOBs; |
| 210 | * |
| 211 | * |
| 212 | * |
| 213 | * |
| 214 | * SQLT_BLOB or OCI_B_BLOB |
| 215 | * - for BLOBs; |
| 216 | * |
| 217 | * |
| 218 | * |
| 219 | * |
| 220 | * SQLT_RDD or OCI_B_ROWID |
| 221 | * - for ROWIDs; |
| 222 | * |
| 223 | * |
| 224 | * |
| 225 | * |
| 226 | * SQLT_NTY or OCI_B_NTY |
| 227 | * - for named datatypes; |
| 228 | * |
| 229 | * |
| 230 | * |
| 231 | * |
| 232 | * SQLT_INT or OCI_B_INT - for integers; |
| 233 | * |
| 234 | * |
| 235 | * |
| 236 | * |
| 237 | * SQLT_CHR - for VARCHARs; |
| 238 | * |
| 239 | * |
| 240 | * |
| 241 | * |
| 242 | * SQLT_BIN or OCI_B_BIN |
| 243 | * - for RAW columns; |
| 244 | * |
| 245 | * |
| 246 | * |
| 247 | * |
| 248 | * SQLT_LNG - for LONG columns; |
| 249 | * |
| 250 | * |
| 251 | * |
| 252 | * |
| 253 | * SQLT_LBI - for LONG RAW columns; |
| 254 | * |
| 255 | * |
| 256 | * |
| 257 | * |
| 258 | * SQLT_RSET - for cursors created |
| 259 | * with oci_new_cursor; |
| 260 | * |
| 261 | * |
| 262 | * |
| 263 | * |
| 264 | * SQLT_BOL or OCI_B_BOL |
| 265 | * - for PL/SQL BOOLEANs (Requires OCI8 2.0.7 and Oracle Database 12c) |
| 266 | * |
| 267 | * |
| 268 | * |
| 269 | * |
| 270 | * SQLT_BFILEE or OCI_B_BFILE |
| 271 | * - for BFILEs; |
| 272 | * |
| 273 | * SQLT_CFILEE or OCI_B_CFILEE |
| 274 | * - for CFILEs; |
| 275 | * |
| 276 | * SQLT_CLOB or OCI_B_CLOB |
| 277 | * - for CLOBs; |
| 278 | * |
| 279 | * SQLT_BLOB or OCI_B_BLOB |
| 280 | * - for BLOBs; |
| 281 | * |
| 282 | * SQLT_RDD or OCI_B_ROWID |
| 283 | * - for ROWIDs; |
| 284 | * |
| 285 | * SQLT_NTY or OCI_B_NTY |
| 286 | * - for named datatypes; |
| 287 | * |
| 288 | * SQLT_INT or OCI_B_INT - for integers; |
| 289 | * |
| 290 | * SQLT_CHR - for VARCHARs; |
| 291 | * |
| 292 | * SQLT_BIN or OCI_B_BIN |
| 293 | * - for RAW columns; |
| 294 | * |
| 295 | * SQLT_LNG - for LONG columns; |
| 296 | * |
| 297 | * SQLT_LBI - for LONG RAW columns; |
| 298 | * |
| 299 | * SQLT_RSET - for cursors created |
| 300 | * with oci_new_cursor; |
| 301 | * |
| 302 | * SQLT_BOL or OCI_B_BOL |
| 303 | * - for PL/SQL BOOLEANs (Requires OCI8 2.0.7 and Oracle Database 12c) |
| 304 | * @throws Oci8Exception |
| 305 | * |
| 306 | */ |
| 307 | function oci_bind_by_name($statement, string $bv_name, &$variable, int $maxlength = -1, int $type = \SQLT_CHR): void |
| 308 | { |
| 309 | error_clear_last(); |
| 310 | $result = \oci_bind_by_name($statement, $bv_name, $variable, $maxlength, $type); |
| 311 | if ($result === \false) { |
| 312 | throw Oci8Exception::createFromPhpError(); |
| 313 | } |
| 314 | } |
| 315 | /** |
| 316 | * Invalidates a cursor, freeing all associated resources and cancels the |
| 317 | * ability to read from it. |
| 318 | * |
| 319 | * @param resource $statement An OCI statement. |
| 320 | * @throws Oci8Exception |
| 321 | * |
| 322 | */ |
| 323 | function oci_cancel($statement): void |
| 324 | { |
| 325 | error_clear_last(); |
| 326 | $result = \oci_cancel($statement); |
| 327 | if ($result === \false) { |
| 328 | throw Oci8Exception::createFromPhpError(); |
| 329 | } |
| 330 | } |
| 331 | /** |
| 332 | * Unsets connection. The underlying database |
| 333 | * connection is closed if no other resources are using it and if it |
| 334 | * was created with oci_connect |
| 335 | * or oci_new_connect. |
| 336 | * |
| 337 | * It is recommended to close connections that are no longer needed |
| 338 | * because this makes database resources available for other users. |
| 339 | * |
| 340 | * @param resource $connection An Oracle connection identifier returned by |
| 341 | * oci_connect, oci_pconnect, |
| 342 | * or oci_new_connect. |
| 343 | * @throws Oci8Exception |
| 344 | * |
| 345 | */ |
| 346 | function oci_close($connection): void |
| 347 | { |
| 348 | error_clear_last(); |
| 349 | $result = \oci_close($connection); |
| 350 | if ($result === \false) { |
| 351 | throw Oci8Exception::createFromPhpError(); |
| 352 | } |
| 353 | } |
| 354 | /** |
| 355 | * Commits the outstanding transaction for the |
| 356 | * Oracle connection. A commit ends the |
| 357 | * current transaction and makes permanent all changes. It releases |
| 358 | * all locks held. |
| 359 | * |
| 360 | * A transaction begins when the first SQL statement that changes data |
| 361 | * is executed with oci_execute using |
| 362 | * the OCI_NO_AUTO_COMMIT flag. Further data |
| 363 | * changes made by other statements become part of the same |
| 364 | * transaction. Data changes made in a transaction are temporary |
| 365 | * until the transaction is committed or rolled back. Other users of |
| 366 | * the database will not see the changes until they are committed. |
| 367 | * |
| 368 | * When inserting or updating data, using transactions is recommended |
| 369 | * for relational data consistency and for performance reasons. |
| 370 | * |
| 371 | * @param resource $connection An Oracle connection identifier, returned by |
| 372 | * oci_connect, oci_pconnect, or oci_new_connect. |
| 373 | * @throws Oci8Exception |
| 374 | * |
| 375 | */ |
| 376 | function oci_commit($connection): void |
| 377 | { |
| 378 | error_clear_last(); |
| 379 | $result = \oci_commit($connection); |
| 380 | if ($result === \false) { |
| 381 | throw Oci8Exception::createFromPhpError(); |
| 382 | } |
| 383 | } |
| 384 | /** |
| 385 | * Returns a connection identifier needed for most other OCI8 operations. |
| 386 | * |
| 387 | * See Connection Handling for |
| 388 | * general information on connection management and connection |
| 389 | * pooling. |
| 390 | * |
| 391 | * From PHP 5.1.2 (PECL OCI8 1.1) oci_close can |
| 392 | * be used to close the connection. |
| 393 | * |
| 394 | * The second and subsequent calls to oci_connect |
| 395 | * with the same parameters will return the connection handle returned |
| 396 | * from the first call. This means that transactions in one handle are |
| 397 | * also in the other handles, because they use the |
| 398 | * same underlying database connection. If two |
| 399 | * handles need to be transactionally isolated from each other, use |
| 400 | * oci_new_connect instead. |
| 401 | * |
| 402 | * @param string $username The Oracle user name. |
| 403 | * @param string $password The password for username. |
| 404 | * @param string $connection_string Contains |
| 405 | * the Oracle instance to connect to. It can be |
| 406 | * an Easy Connect |
| 407 | * string, or a Connect Name from |
| 408 | * the tnsnames.ora file, or the name of a local |
| 409 | * Oracle instance. |
| 410 | * |
| 411 | * If not specified, PHP uses |
| 412 | * environment variables such as TWO_TASK (on Linux) |
| 413 | * or LOCAL (on Windows) |
| 414 | * and ORACLE_SID to determine the |
| 415 | * Oracle instance to connect to. |
| 416 | * |
| 417 | * |
| 418 | * To use the Easy Connect naming method, PHP must be linked with Oracle |
| 419 | * 10g or greater Client libraries. The Easy Connect string for Oracle |
| 420 | * 10g is of the form: |
| 421 | * [//]host_name[:port][/service_name]. From Oracle |
| 422 | * 11g, the syntax is: |
| 423 | * [//]host_name[:port][/service_name][:server_type][/instance_name]. |
| 424 | * Service names can be found by running the Oracle |
| 425 | * utility lsnrctl status on the database server |
| 426 | * machine. |
| 427 | * |
| 428 | * |
| 429 | * The tnsnames.ora file can be in the Oracle Net |
| 430 | * search path, which |
| 431 | * includes $ORACLE_HOME/network/admin |
| 432 | * and /etc. Alternatively |
| 433 | * set TNS_ADMIN so |
| 434 | * that $TNS_ADMIN/tnsnames.ora is read. Make sure |
| 435 | * the web daemon has read access to the file. |
| 436 | * @param string $character_set Determines |
| 437 | * the character set used by the Oracle Client libraries. The character |
| 438 | * set does not need to match the character set used by the database. If |
| 439 | * it doesn't match, Oracle will do its best to convert data to and from |
| 440 | * the database character set. Depending on the character sets this may |
| 441 | * not give usable results. Conversion also adds some time overhead. |
| 442 | * |
| 443 | * If not specified, the |
| 444 | * Oracle Client libraries determine a character set from |
| 445 | * the NLS_LANG environment variable. |
| 446 | * |
| 447 | * Passing this parameter can |
| 448 | * reduce the time taken to connect. |
| 449 | * @param int $session_mode This |
| 450 | * parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the |
| 451 | * following values: OCI_DEFAULT, |
| 452 | * OCI_SYSOPER and OCI_SYSDBA. |
| 453 | * If either OCI_SYSOPER or |
| 454 | * OCI_SYSDBA were specified, this function will try |
| 455 | * to establish privileged connection using external credentials. |
| 456 | * Privileged connections are disabled by default. To enable them you |
| 457 | * need to set oci8.privileged_connect |
| 458 | * to On. |
| 459 | * |
| 460 | * |
| 461 | * PHP 5.3 (PECL OCI8 1.3.4) introduced the |
| 462 | * OCI_CRED_EXT mode value. This tells Oracle to use |
| 463 | * External or OS authentication, which must be configured in the |
| 464 | * database. The OCI_CRED_EXT flag can only be used |
| 465 | * with username of "/" and a empty password. |
| 466 | * oci8.privileged_connect |
| 467 | * may be On or Off. |
| 468 | * |
| 469 | * |
| 470 | * OCI_CRED_EXT may be combined with the |
| 471 | * OCI_SYSOPER or |
| 472 | * OCI_SYSDBA modes. |
| 473 | * |
| 474 | * |
| 475 | * OCI_CRED_EXT is not supported on Windows for |
| 476 | * security reasons. |
| 477 | * @return resource Returns a connection identifier. |
| 478 | * @throws Oci8Exception |
| 479 | * |
| 480 | */ |
| 481 | function oci_connect(string $username, string $password, string $connection_string = null, string $character_set = null, int $session_mode = null) |
| 482 | { |
| 483 | error_clear_last(); |
| 484 | if ($session_mode !== null) { |
| 485 | $result = \oci_connect($username, $password, $connection_string, $character_set, $session_mode); |
| 486 | } elseif ($character_set !== null) { |
| 487 | $result = \oci_connect($username, $password, $connection_string, $character_set); |
| 488 | } elseif ($connection_string !== null) { |
| 489 | $result = \oci_connect($username, $password, $connection_string); |
| 490 | } else { |
| 491 | $result = \oci_connect($username, $password); |
| 492 | } |
| 493 | if ($result === \false) { |
| 494 | throw Oci8Exception::createFromPhpError(); |
| 495 | } |
| 496 | return $result; |
| 497 | } |
| 498 | /** |
| 499 | * Associates a PHP variable with a column for query fetches using oci_fetch. |
| 500 | * |
| 501 | * The oci_define_by_name call must occur before |
| 502 | * executing oci_execute. |
| 503 | * |
| 504 | * @param resource $statement A valid OCI8 statement |
| 505 | * identifier created by oci_parse and executed |
| 506 | * by oci_execute, or a REF |
| 507 | * CURSOR statement identifier. |
| 508 | * @param string $column_name The column name used in the query. |
| 509 | * |
| 510 | * Use uppercase for Oracle's default, non-case sensitive column |
| 511 | * names. Use the exact column name case for case-sensitive |
| 512 | * column names. |
| 513 | * @param mixed $variable The PHP variable that will contain the returned column value. |
| 514 | * @param int $type The data type to be returned. Generally not needed. Note that |
| 515 | * Oracle-style data conversions are not performed. For example, |
| 516 | * SQLT_INT will be ignored and the returned |
| 517 | * data type will still be SQLT_CHR. |
| 518 | * |
| 519 | * You can optionally use oci_new_descriptor |
| 520 | * to allocate LOB/ROWID/BFILE descriptors. |
| 521 | * @throws Oci8Exception |
| 522 | * |
| 523 | */ |
| 524 | function oci_define_by_name($statement, string $column_name, &$variable, int $type = \SQLT_CHR): void |
| 525 | { |
| 526 | error_clear_last(); |
| 527 | $result = \oci_define_by_name($statement, $column_name, $variable, $type); |
| 528 | if ($result === \false) { |
| 529 | throw Oci8Exception::createFromPhpError(); |
| 530 | } |
| 531 | } |
| 532 | /** |
| 533 | * Executes a statement previously returned |
| 534 | * from oci_parse. |
| 535 | * |
| 536 | * After execution, statements like INSERT will |
| 537 | * have data committed to the database by default. For statements |
| 538 | * like SELECT, execution performs the logic of the |
| 539 | * query. Query results can subsequently be fetched in PHP with |
| 540 | * functions like oci_fetch_array. |
| 541 | * |
| 542 | * Each parsed statement may be executed multiple times, saving the |
| 543 | * cost of re-parsing. This is commonly used |
| 544 | * for INSERT statements when data is bound |
| 545 | * with oci_bind_by_name. |
| 546 | * |
| 547 | * @param resource $statement A valid OCI statement identifier. |
| 548 | * @param int $mode An optional second parameter can be one of the following constants: |
| 549 | * |
| 550 | * Execution Modes |
| 551 | * |
| 552 | * |
| 553 | * |
| 554 | * Constant |
| 555 | * Description |
| 556 | * |
| 557 | * |
| 558 | * |
| 559 | * |
| 560 | * OCI_COMMIT_ON_SUCCESS |
| 561 | * Automatically commit all outstanding changes for |
| 562 | * this connection when the statement has succeeded. This |
| 563 | * is the default. |
| 564 | * |
| 565 | * |
| 566 | * OCI_DESCRIBE_ONLY |
| 567 | * Make query meta data available to functions |
| 568 | * like oci_field_name but do not |
| 569 | * create a result set. Any subsequent fetch call such |
| 570 | * as oci_fetch_array will |
| 571 | * fail. |
| 572 | * |
| 573 | * |
| 574 | * OCI_NO_AUTO_COMMIT |
| 575 | * Do not automatically commit changes. Prior to PHP |
| 576 | * 5.3.2 (PECL OCI8 1.4) |
| 577 | * use OCI_DEFAULT which is equivalent |
| 578 | * to OCI_NO_AUTO_COMMIT. |
| 579 | * |
| 580 | * |
| 581 | * |
| 582 | * |
| 583 | * |
| 584 | * Using OCI_NO_AUTO_COMMIT mode starts or continues a |
| 585 | * transaction. Transactions are automatically rolled back when |
| 586 | * the connection is closed, or when the script ends. Explicitly |
| 587 | * call oci_commit to commit a transaction, |
| 588 | * or oci_rollback to abort it. |
| 589 | * |
| 590 | * When inserting or updating data, using transactions is |
| 591 | * recommended for relational data consistency and for performance |
| 592 | * reasons. |
| 593 | * |
| 594 | * If OCI_NO_AUTO_COMMIT mode is used for any |
| 595 | * statement including queries, and |
| 596 | * oci_commit |
| 597 | * or oci_rollback is not subsequently |
| 598 | * called, then OCI8 will perform a rollback at the end of the |
| 599 | * script even if no data was changed. To avoid an unnecessary |
| 600 | * rollback, many scripts do not |
| 601 | * use OCI_NO_AUTO_COMMIT mode for queries or |
| 602 | * PL/SQL. Be careful to ensure the appropriate transactional |
| 603 | * consistency for the application when |
| 604 | * using oci_execute with different modes in |
| 605 | * the same script. |
| 606 | * @throws Oci8Exception |
| 607 | * |
| 608 | */ |
| 609 | function oci_execute($statement, int $mode = \OCI_COMMIT_ON_SUCCESS): void |
| 610 | { |
| 611 | error_clear_last(); |
| 612 | $result = \oci_execute($statement, $mode); |
| 613 | if ($result === \false) { |
| 614 | throw Oci8Exception::createFromPhpError(); |
| 615 | } |
| 616 | } |
| 617 | /** |
| 618 | * Fetches multiple rows from a query into a two-dimensional array. |
| 619 | * By default, all rows are returned. |
| 620 | * |
| 621 | * This function can be called only once for each query executed |
| 622 | * with oci_execute. |
| 623 | * |
| 624 | * @param resource $statement A valid OCI8 statement |
| 625 | * identifier created by oci_parse and executed |
| 626 | * by oci_execute, or a REF |
| 627 | * CURSOR statement identifier. |
| 628 | * @param array|null $output The variable to contain the returned rows. |
| 629 | * |
| 630 | * LOB columns are returned as strings, where Oracle supports |
| 631 | * conversion. |
| 632 | * |
| 633 | * See oci_fetch_array for more information |
| 634 | * on how data and types are fetched. |
| 635 | * @param int $skip The number of initial rows to discard when fetching the |
| 636 | * result. The default value is 0, so the first row onwards is |
| 637 | * returned. |
| 638 | * @param int $maxrows The number of rows to return. The default is -1 meaning return |
| 639 | * all the rows from skip + 1 onwards. |
| 640 | * @param int $flags Parameter flags indicates the array |
| 641 | * structure and whether associative arrays should be used. |
| 642 | * |
| 643 | * oci_fetch_all Array Structure Modes |
| 644 | * |
| 645 | * |
| 646 | * |
| 647 | * Constant |
| 648 | * Description |
| 649 | * |
| 650 | * |
| 651 | * |
| 652 | * |
| 653 | * OCI_FETCHSTATEMENT_BY_ROW |
| 654 | * The outer array will contain one sub-array per query |
| 655 | * row. |
| 656 | * |
| 657 | * |
| 658 | * OCI_FETCHSTATEMENT_BY_COLUMN |
| 659 | * The outer array will contain one sub-array per query |
| 660 | * column. This is the default. |
| 661 | * |
| 662 | * |
| 663 | * |
| 664 | * |
| 665 | * |
| 666 | * Arrays can be indexed either by column heading or numerically. |
| 667 | * Only one index mode will be returned. |
| 668 | * |
| 669 | * oci_fetch_all Array Index Modes |
| 670 | * |
| 671 | * |
| 672 | * |
| 673 | * Constant |
| 674 | * Description |
| 675 | * |
| 676 | * |
| 677 | * |
| 678 | * |
| 679 | * OCI_NUM |
| 680 | * Numeric indexes are used for each column's array. |
| 681 | * |
| 682 | * |
| 683 | * OCI_ASSOC |
| 684 | * Associative indexes are used for each column's |
| 685 | * array. This is the default. |
| 686 | * |
| 687 | * |
| 688 | * |
| 689 | * |
| 690 | * |
| 691 | * Use the addition operator "+" to choose a combination |
| 692 | * of array structure and index modes. |
| 693 | * |
| 694 | * Oracle's default, non-case sensitive column names will have |
| 695 | * uppercase array keys. Case-sensitive column names will have |
| 696 | * array keys using the exact column case. |
| 697 | * Use var_dump |
| 698 | * on output to verify the appropriate case |
| 699 | * to use for each query. |
| 700 | * |
| 701 | * Queries that have more than one column with the same name |
| 702 | * should use column aliases. Otherwise only one of the columns |
| 703 | * will appear in an associative array. |
| 704 | * @return int Returns the number of rows in output, which |
| 705 | * may be 0 or more. |
| 706 | * @throws Oci8Exception |
| 707 | * |
| 708 | */ |
| 709 | function oci_fetch_all($statement, ?array &$output, int $skip = 0, int $maxrows = -1, int $flags = \OCI_FETCHSTATEMENT_BY_COLUMN + \OCI_ASSOC): int |
| 710 | { |
| 711 | error_clear_last(); |
| 712 | $result = \oci_fetch_all($statement, $output, $skip, $maxrows, $flags); |
| 713 | if ($result === \false) { |
| 714 | throw Oci8Exception::createFromPhpError(); |
| 715 | } |
| 716 | return $result; |
| 717 | } |
| 718 | /** |
| 719 | * Returns the name of the field. |
| 720 | * |
| 721 | * @param resource $statement A valid OCI statement identifier. |
| 722 | * @param mixed $field Can be the field's index (1-based) or name. |
| 723 | * @return string Returns the name as a strings. |
| 724 | * @throws Oci8Exception |
| 725 | * |
| 726 | */ |
| 727 | function oci_field_name($statement, $field): string |
| 728 | { |
| 729 | error_clear_last(); |
| 730 | $result = \oci_field_name($statement, $field); |
| 731 | if ($result === \false) { |
| 732 | throw Oci8Exception::createFromPhpError(); |
| 733 | } |
| 734 | return $result; |
| 735 | } |
| 736 | /** |
| 737 | * Returns precision of the field. |
| 738 | * |
| 739 | * For FLOAT columns, precision is nonzero and scale is -127. |
| 740 | * If precision is 0, then column is NUMBER. Else it's |
| 741 | * NUMBER(precision, scale). |
| 742 | * |
| 743 | * @param resource $statement A valid OCI statement identifier. |
| 744 | * @param mixed $field Can be the field's index (1-based) or name. |
| 745 | * @return int Returns the precision as an integers. |
| 746 | * @throws Oci8Exception |
| 747 | * |
| 748 | */ |
| 749 | function oci_field_precision($statement, $field): int |
| 750 | { |
| 751 | error_clear_last(); |
| 752 | $result = \oci_field_precision($statement, $field); |
| 753 | if ($result === \false) { |
| 754 | throw Oci8Exception::createFromPhpError(); |
| 755 | } |
| 756 | return $result; |
| 757 | } |
| 758 | /** |
| 759 | * Returns the scale of the column with field index. |
| 760 | * |
| 761 | * For FLOAT columns, precision is nonzero and scale is -127. |
| 762 | * If precision is 0, then column is NUMBER. Else it's |
| 763 | * NUMBER(precision, scale). |
| 764 | * |
| 765 | * @param resource $statement A valid OCI statement identifier. |
| 766 | * @param mixed $field Can be the field's index (1-based) or name. |
| 767 | * @return int Returns the scale as an integers. |
| 768 | * @throws Oci8Exception |
| 769 | * |
| 770 | */ |
| 771 | function oci_field_scale($statement, $field): int |
| 772 | { |
| 773 | error_clear_last(); |
| 774 | $result = \oci_field_scale($statement, $field); |
| 775 | if ($result === \false) { |
| 776 | throw Oci8Exception::createFromPhpError(); |
| 777 | } |
| 778 | return $result; |
| 779 | } |
| 780 | /** |
| 781 | * Returns the size of a field. |
| 782 | * |
| 783 | * @param resource $statement A valid OCI statement identifier. |
| 784 | * @param mixed $field Can be the field's index (1-based) or name. |
| 785 | * @return int Returns the size of a field in bytess. |
| 786 | * @throws Oci8Exception |
| 787 | * |
| 788 | */ |
| 789 | function oci_field_size($statement, $field): int |
| 790 | { |
| 791 | error_clear_last(); |
| 792 | $result = \oci_field_size($statement, $field); |
| 793 | if ($result === \false) { |
| 794 | throw Oci8Exception::createFromPhpError(); |
| 795 | } |
| 796 | return $result; |
| 797 | } |
| 798 | /** |
| 799 | * Returns Oracle's raw "SQLT" data type of the field. |
| 800 | * |
| 801 | * If you want a field's type name, then use oci_field_type instead. |
| 802 | * |
| 803 | * @param resource $statement A valid OCI statement identifier. |
| 804 | * @param mixed $field Can be the field's index (1-based) or name. |
| 805 | * @return int Returns Oracle's raw data type as a numbers. |
| 806 | * @throws Oci8Exception |
| 807 | * |
| 808 | */ |
| 809 | function oci_field_type_raw($statement, $field): int |
| 810 | { |
| 811 | error_clear_last(); |
| 812 | $result = \oci_field_type_raw($statement, $field); |
| 813 | if ($result === \false) { |
| 814 | throw Oci8Exception::createFromPhpError(); |
| 815 | } |
| 816 | return $result; |
| 817 | } |
| 818 | /** |
| 819 | * Returns a field's data type name. |
| 820 | * |
| 821 | * @param resource $statement A valid OCI statement identifier. |
| 822 | * @param mixed $field Can be the field's index (1-based) or name. |
| 823 | * @return mixed Returns the field data type as a strings. |
| 824 | * @throws Oci8Exception |
| 825 | * |
| 826 | */ |
| 827 | function oci_field_type($statement, $field) |
| 828 | { |
| 829 | error_clear_last(); |
| 830 | $result = \oci_field_type($statement, $field); |
| 831 | if ($result === \false) { |
| 832 | throw Oci8Exception::createFromPhpError(); |
| 833 | } |
| 834 | return $result; |
| 835 | } |
| 836 | /** |
| 837 | * Frees a descriptor allocated by oci_new_descriptor. |
| 838 | * |
| 839 | * @param resource $descriptor |
| 840 | * @throws Oci8Exception |
| 841 | * |
| 842 | */ |
| 843 | function oci_free_descriptor($descriptor): void |
| 844 | { |
| 845 | error_clear_last(); |
| 846 | $result = \oci_free_descriptor($descriptor); |
| 847 | if ($result === \false) { |
| 848 | throw Oci8Exception::createFromPhpError(); |
| 849 | } |
| 850 | } |
| 851 | /** |
| 852 | * Frees resources associated with Oracle's cursor or statement, which was |
| 853 | * received from as a result of oci_parse or obtained |
| 854 | * from Oracle. |
| 855 | * |
| 856 | * @param resource $statement A valid OCI statement identifier. |
| 857 | * @throws Oci8Exception |
| 858 | * |
| 859 | */ |
| 860 | function oci_free_statement($statement): void |
| 861 | { |
| 862 | error_clear_last(); |
| 863 | $result = \oci_free_statement($statement); |
| 864 | if ($result === \false) { |
| 865 | throw Oci8Exception::createFromPhpError(); |
| 866 | } |
| 867 | } |
| 868 | /** |
| 869 | * Allocates a new collection object. |
| 870 | * |
| 871 | * @param resource $connection An Oracle connection identifier, returned by |
| 872 | * oci_connect or oci_pconnect. |
| 873 | * @param string $tdo Should be a valid named type (uppercase). |
| 874 | * @param string $schema Should point to the scheme, where the named type was created. The name |
| 875 | * of the current user is the default value. |
| 876 | * @return \OCI-Collection Returns a new OCICollection object. |
| 877 | * @throws Oci8Exception |
| 878 | * |
| 879 | */ |
| 880 | function oci_new_collection($connection, string $tdo, string $schema = null) |
| 881 | { |
| 882 | error_clear_last(); |
| 883 | $result = \oci_new_collection($connection, $tdo, $schema); |
| 884 | if ($result === \false) { |
| 885 | throw Oci8Exception::createFromPhpError(); |
| 886 | } |
| 887 | return $result; |
| 888 | } |
| 889 | /** |
| 890 | * Establishes a new connection to an Oracle server and logs on. |
| 891 | * |
| 892 | * Unlike oci_connect and |
| 893 | * oci_pconnect, oci_new_connect |
| 894 | * does not cache connections and will always return a brand-new freshly |
| 895 | * opened connection handle. This is useful if your application needs |
| 896 | * transactional isolation between two sets of queries. |
| 897 | * |
| 898 | * @param string $username The Oracle user name. |
| 899 | * @param string $password The password for username. |
| 900 | * @param string $connection_string Contains |
| 901 | * the Oracle instance to connect to. It can be |
| 902 | * an Easy Connect |
| 903 | * string, or a Connect Name from |
| 904 | * the tnsnames.ora file, or the name of a local |
| 905 | * Oracle instance. |
| 906 | * |
| 907 | * If not specified, PHP uses |
| 908 | * environment variables such as TWO_TASK (on Linux) |
| 909 | * or LOCAL (on Windows) |
| 910 | * and ORACLE_SID to determine the |
| 911 | * Oracle instance to connect to. |
| 912 | * |
| 913 | * |
| 914 | * To use the Easy Connect naming method, PHP must be linked with Oracle |
| 915 | * 10g or greater Client libraries. The Easy Connect string for Oracle |
| 916 | * 10g is of the form: |
| 917 | * [//]host_name[:port][/service_name]. From Oracle |
| 918 | * 11g, the syntax is: |
| 919 | * [//]host_name[:port][/service_name][:server_type][/instance_name]. |
| 920 | * Service names can be found by running the Oracle |
| 921 | * utility lsnrctl status on the database server |
| 922 | * machine. |
| 923 | * |
| 924 | * |
| 925 | * The tnsnames.ora file can be in the Oracle Net |
| 926 | * search path, which |
| 927 | * includes $ORACLE_HOME/network/admin |
| 928 | * and /etc. Alternatively |
| 929 | * set TNS_ADMIN so |
| 930 | * that $TNS_ADMIN/tnsnames.ora is read. Make sure |
| 931 | * the web daemon has read access to the file. |
| 932 | * @param string $character_set Determines |
| 933 | * the character set used by the Oracle Client libraries. The character |
| 934 | * set does not need to match the character set used by the database. If |
| 935 | * it doesn't match, Oracle will do its best to convert data to and from |
| 936 | * the database character set. Depending on the character sets this may |
| 937 | * not give usable results. Conversion also adds some time overhead. |
| 938 | * |
| 939 | * If not specified, the |
| 940 | * Oracle Client libraries determine a character set from |
| 941 | * the NLS_LANG environment variable. |
| 942 | * |
| 943 | * Passing this parameter can |
| 944 | * reduce the time taken to connect. |
| 945 | * @param int $session_mode This |
| 946 | * parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the |
| 947 | * following values: OCI_DEFAULT, |
| 948 | * OCI_SYSOPER and OCI_SYSDBA. |
| 949 | * If either OCI_SYSOPER or |
| 950 | * OCI_SYSDBA were specified, this function will try |
| 951 | * to establish privileged connection using external credentials. |
| 952 | * Privileged connections are disabled by default. To enable them you |
| 953 | * need to set oci8.privileged_connect |
| 954 | * to On. |
| 955 | * |
| 956 | * |
| 957 | * PHP 5.3 (PECL OCI8 1.3.4) introduced the |
| 958 | * OCI_CRED_EXT mode value. This tells Oracle to use |
| 959 | * External or OS authentication, which must be configured in the |
| 960 | * database. The OCI_CRED_EXT flag can only be used |
| 961 | * with username of "/" and a empty password. |
| 962 | * oci8.privileged_connect |
| 963 | * may be On or Off. |
| 964 | * |
| 965 | * |
| 966 | * OCI_CRED_EXT may be combined with the |
| 967 | * OCI_SYSOPER or |
| 968 | * OCI_SYSDBA modes. |
| 969 | * |
| 970 | * |
| 971 | * OCI_CRED_EXT is not supported on Windows for |
| 972 | * security reasons. |
| 973 | * @return resource Returns a connection identifier. |
| 974 | * @throws Oci8Exception |
| 975 | * |
| 976 | */ |
| 977 | function oci_new_connect(string $username, string $password, string $connection_string = null, string $character_set = null, int $session_mode = null) |
| 978 | { |
| 979 | error_clear_last(); |
| 980 | if ($session_mode !== null) { |
| 981 | $result = \oci_new_connect($username, $password, $connection_string, $character_set, $session_mode); |
| 982 | } elseif ($character_set !== null) { |
| 983 | $result = \oci_new_connect($username, $password, $connection_string, $character_set); |
| 984 | } elseif ($connection_string !== null) { |
| 985 | $result = \oci_new_connect($username, $password, $connection_string); |
| 986 | } else { |
| 987 | $result = \oci_new_connect($username, $password); |
| 988 | } |
| 989 | if ($result === \false) { |
| 990 | throw Oci8Exception::createFromPhpError(); |
| 991 | } |
| 992 | return $result; |
| 993 | } |
| 994 | /** |
| 995 | * Allocates a new statement handle on the specified connection. |
| 996 | * |
| 997 | * @param resource $connection An Oracle connection identifier, returned by |
| 998 | * oci_connect or oci_pconnect. |
| 999 | * @return resource Returns a new statement handle. |
| 1000 | * @throws Oci8Exception |
| 1001 | * |
| 1002 | */ |
| 1003 | function oci_new_cursor($connection) |
| 1004 | { |
| 1005 | error_clear_last(); |
| 1006 | $result = \oci_new_cursor($connection); |
| 1007 | if ($result === \false) { |
| 1008 | throw Oci8Exception::createFromPhpError(); |
| 1009 | } |
| 1010 | return $result; |
| 1011 | } |
| 1012 | /** |
| 1013 | * Allocates resources to hold descriptor or LOB locator. |
| 1014 | * |
| 1015 | * @param resource $connection An Oracle connection identifier, returned by |
| 1016 | * oci_connect or oci_pconnect. |
| 1017 | * @param int $type Valid values for type are: |
| 1018 | * OCI_DTYPE_FILE, OCI_DTYPE_LOB and |
| 1019 | * OCI_DTYPE_ROWID. |
| 1020 | * @return \OCI-Lob Returns a new LOB or FILE descriptor on success, FALSE on error. |
| 1021 | * @throws Oci8Exception |
| 1022 | * |
| 1023 | */ |
| 1024 | function oci_new_descriptor($connection, int $type = \OCI_DTYPE_LOB) |
| 1025 | { |
| 1026 | error_clear_last(); |
| 1027 | $result = \oci_new_descriptor($connection, $type); |
| 1028 | if ($result === \false) { |
| 1029 | throw Oci8Exception::createFromPhpError(); |
| 1030 | } |
| 1031 | return $result; |
| 1032 | } |
| 1033 | /** |
| 1034 | * Gets the number of columns in the given statement. |
| 1035 | * |
| 1036 | * @param resource $statement A valid OCI statement identifier. |
| 1037 | * @return int Returns the number of columns as an integers. |
| 1038 | * @throws Oci8Exception |
| 1039 | * |
| 1040 | */ |
| 1041 | function oci_num_fields($statement): int |
| 1042 | { |
| 1043 | error_clear_last(); |
| 1044 | $result = \oci_num_fields($statement); |
| 1045 | if ($result === \false) { |
| 1046 | throw Oci8Exception::createFromPhpError(); |
| 1047 | } |
| 1048 | return $result; |
| 1049 | } |
| 1050 | /** |
| 1051 | * Gets the number of rows affected during statement execution. |
| 1052 | * |
| 1053 | * @param resource $statement A valid OCI statement identifier. |
| 1054 | * @return int Returns the number of rows affected as an integers. |
| 1055 | * @throws Oci8Exception |
| 1056 | * |
| 1057 | */ |
| 1058 | function oci_num_rows($statement): int |
| 1059 | { |
| 1060 | error_clear_last(); |
| 1061 | $result = \oci_num_rows($statement); |
| 1062 | if ($result === \false) { |
| 1063 | throw Oci8Exception::createFromPhpError(); |
| 1064 | } |
| 1065 | return $result; |
| 1066 | } |
| 1067 | /** |
| 1068 | * Prepares sql_text using |
| 1069 | * connection and returns the statement identifier, |
| 1070 | * which can be used with oci_bind_by_name, |
| 1071 | * oci_execute and other functions. |
| 1072 | * |
| 1073 | * Statement identifiers can be freed |
| 1074 | * with oci_free_statement or by setting the |
| 1075 | * variable to NULL. |
| 1076 | * |
| 1077 | * @param resource $connection An Oracle connection identifier, returned by |
| 1078 | * oci_connect, oci_pconnect, or oci_new_connect. |
| 1079 | * @param string $sql_text The SQL or PL/SQL statement. |
| 1080 | * |
| 1081 | * SQL statements should not end with a |
| 1082 | * semi-colon (";"). PL/SQL |
| 1083 | * statements should end with a semi-colon |
| 1084 | * (";"). |
| 1085 | * @return resource Returns a statement handle on success. |
| 1086 | * @throws Oci8Exception |
| 1087 | * |
| 1088 | */ |
| 1089 | function oci_parse($connection, string $sql_text) |
| 1090 | { |
| 1091 | error_clear_last(); |
| 1092 | $result = \oci_parse($connection, $sql_text); |
| 1093 | if ($result === \false) { |
| 1094 | throw Oci8Exception::createFromPhpError(); |
| 1095 | } |
| 1096 | return $result; |
| 1097 | } |
| 1098 | /** |
| 1099 | * Creates a persistent connection to an Oracle server and logs on. |
| 1100 | * |
| 1101 | * Persistent connections are cached and re-used between requests, resulting |
| 1102 | * in reduced overhead on each page load; a typical PHP application will have |
| 1103 | * a single persistent connection open against an Oracle server per Apache |
| 1104 | * child process (or PHP FastCGI/CGI process). See the Persistent Database |
| 1105 | * Connections section for more information. |
| 1106 | * |
| 1107 | * @param string $username The Oracle user name. |
| 1108 | * @param string $password The password for username. |
| 1109 | * @param string $connection_string Contains |
| 1110 | * the Oracle instance to connect to. It can be |
| 1111 | * an Easy Connect |
| 1112 | * string, or a Connect Name from |
| 1113 | * the tnsnames.ora file, or the name of a local |
| 1114 | * Oracle instance. |
| 1115 | * |
| 1116 | * If not specified, PHP uses |
| 1117 | * environment variables such as TWO_TASK (on Linux) |
| 1118 | * or LOCAL (on Windows) |
| 1119 | * and ORACLE_SID to determine the |
| 1120 | * Oracle instance to connect to. |
| 1121 | * |
| 1122 | * |
| 1123 | * To use the Easy Connect naming method, PHP must be linked with Oracle |
| 1124 | * 10g or greater Client libraries. The Easy Connect string for Oracle |
| 1125 | * 10g is of the form: |
| 1126 | * [//]host_name[:port][/service_name]. From Oracle |
| 1127 | * 11g, the syntax is: |
| 1128 | * [//]host_name[:port][/service_name][:server_type][/instance_name]. |
| 1129 | * Service names can be found by running the Oracle |
| 1130 | * utility lsnrctl status on the database server |
| 1131 | * machine. |
| 1132 | * |
| 1133 | * |
| 1134 | * The tnsnames.ora file can be in the Oracle Net |
| 1135 | * search path, which |
| 1136 | * includes $ORACLE_HOME/network/admin |
| 1137 | * and /etc. Alternatively |
| 1138 | * set TNS_ADMIN so |
| 1139 | * that $TNS_ADMIN/tnsnames.ora is read. Make sure |
| 1140 | * the web daemon has read access to the file. |
| 1141 | * @param string $character_set Determines |
| 1142 | * the character set used by the Oracle Client libraries. The character |
| 1143 | * set does not need to match the character set used by the database. If |
| 1144 | * it doesn't match, Oracle will do its best to convert data to and from |
| 1145 | * the database character set. Depending on the character sets this may |
| 1146 | * not give usable results. Conversion also adds some time overhead. |
| 1147 | * |
| 1148 | * If not specified, the |
| 1149 | * Oracle Client libraries determine a character set from |
| 1150 | * the NLS_LANG environment variable. |
| 1151 | * |
| 1152 | * Passing this parameter can |
| 1153 | * reduce the time taken to connect. |
| 1154 | * @param int $session_mode This |
| 1155 | * parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the |
| 1156 | * following values: OCI_DEFAULT, |
| 1157 | * OCI_SYSOPER and OCI_SYSDBA. |
| 1158 | * If either OCI_SYSOPER or |
| 1159 | * OCI_SYSDBA were specified, this function will try |
| 1160 | * to establish privileged connection using external credentials. |
| 1161 | * Privileged connections are disabled by default. To enable them you |
| 1162 | * need to set oci8.privileged_connect |
| 1163 | * to On. |
| 1164 | * |
| 1165 | * |
| 1166 | * PHP 5.3 (PECL OCI8 1.3.4) introduced the |
| 1167 | * OCI_CRED_EXT mode value. This tells Oracle to use |
| 1168 | * External or OS authentication, which must be configured in the |
| 1169 | * database. The OCI_CRED_EXT flag can only be used |
| 1170 | * with username of "/" and a empty password. |
| 1171 | * oci8.privileged_connect |
| 1172 | * may be On or Off. |
| 1173 | * |
| 1174 | * |
| 1175 | * OCI_CRED_EXT may be combined with the |
| 1176 | * OCI_SYSOPER or |
| 1177 | * OCI_SYSDBA modes. |
| 1178 | * |
| 1179 | * |
| 1180 | * OCI_CRED_EXT is not supported on Windows for |
| 1181 | * security reasons. |
| 1182 | * @return resource Returns a connection identifier. |
| 1183 | * @throws Oci8Exception |
| 1184 | * |
| 1185 | */ |
| 1186 | function oci_pconnect(string $username, string $password, string $connection_string = null, string $character_set = null, int $session_mode = null) |
| 1187 | { |
| 1188 | error_clear_last(); |
| 1189 | if ($session_mode !== null) { |
| 1190 | $result = \oci_pconnect($username, $password, $connection_string, $character_set, $session_mode); |
| 1191 | } elseif ($character_set !== null) { |
| 1192 | $result = \oci_pconnect($username, $password, $connection_string, $character_set); |
| 1193 | } elseif ($connection_string !== null) { |
| 1194 | $result = \oci_pconnect($username, $password, $connection_string); |
| 1195 | } else { |
| 1196 | $result = \oci_pconnect($username, $password); |
| 1197 | } |
| 1198 | if ($result === \false) { |
| 1199 | throw Oci8Exception::createFromPhpError(); |
| 1200 | } |
| 1201 | return $result; |
| 1202 | } |
| 1203 | /** |
| 1204 | * Returns the data from field in the current row, |
| 1205 | * fetched by oci_fetch. |
| 1206 | * |
| 1207 | * For details on the data type mapping performed by |
| 1208 | * the OCI8 extension, see the datatypes |
| 1209 | * supported by the driver |
| 1210 | * |
| 1211 | * @param resource $statement |
| 1212 | * @param mixed $field Can be either use the column number (1-based) or the column name. |
| 1213 | * The case of the column name must be the case that Oracle meta data |
| 1214 | * describes the column as, which is uppercase for columns created |
| 1215 | * case insensitively. |
| 1216 | * @return string Returns everything as strings except for abstract types (ROWIDs, LOBs and |
| 1217 | * FILEs). |
| 1218 | * @throws Oci8Exception |
| 1219 | * |
| 1220 | */ |
| 1221 | function oci_result($statement, $field): string |
| 1222 | { |
| 1223 | error_clear_last(); |
| 1224 | $result = \oci_result($statement, $field); |
| 1225 | if ($result === \false) { |
| 1226 | throw Oci8Exception::createFromPhpError(); |
| 1227 | } |
| 1228 | return $result; |
| 1229 | } |
| 1230 | /** |
| 1231 | * Reverts all uncommitted changes for the Oracle |
| 1232 | * connection and ends the transaction. It |
| 1233 | * releases all locks held. All Oracle SAVEPOINTS |
| 1234 | * are erased. |
| 1235 | * |
| 1236 | * A transaction begins when the first SQL statement that changes data |
| 1237 | * is executed with oci_execute using |
| 1238 | * the OCI_NO_AUTO_COMMIT flag. Further data |
| 1239 | * changes made by other statements become part of the same |
| 1240 | * transaction. Data changes made in a transaction are temporary |
| 1241 | * until the transaction is committed or rolled back. Other users of |
| 1242 | * the database will not see the changes until they are committed. |
| 1243 | * |
| 1244 | * When inserting or updating data, using transactions is recommended |
| 1245 | * for relational data consistency and for performance reasons. |
| 1246 | * |
| 1247 | * @param resource $connection An Oracle connection identifier, returned by |
| 1248 | * oci_connect, oci_pconnect |
| 1249 | * or oci_new_connect. |
| 1250 | * @throws Oci8Exception |
| 1251 | * |
| 1252 | */ |
| 1253 | function oci_rollback($connection): void |
| 1254 | { |
| 1255 | error_clear_last(); |
| 1256 | $result = \oci_rollback($connection); |
| 1257 | if ($result === \false) { |
| 1258 | throw Oci8Exception::createFromPhpError(); |
| 1259 | } |
| 1260 | } |
| 1261 | /** |
| 1262 | * Returns a string with the Oracle Database version and available options |
| 1263 | * |
| 1264 | * @param resource $connection |
| 1265 | * @return string Returns the version information as a string. |
| 1266 | * @throws Oci8Exception |
| 1267 | * |
| 1268 | */ |
| 1269 | function oci_server_version($connection): string |
| 1270 | { |
| 1271 | error_clear_last(); |
| 1272 | $result = \oci_server_version($connection); |
| 1273 | if ($result === \false) { |
| 1274 | throw Oci8Exception::createFromPhpError(); |
| 1275 | } |
| 1276 | return $result; |
| 1277 | } |
| 1278 | /** |
| 1279 | * Sets the action name for Oracle tracing. |
| 1280 | * |
| 1281 | * The action name is registered with the database when the next |
| 1282 | * 'round-trip' from PHP to the database occurs, typically when an SQL |
| 1283 | * statement is executed. |
| 1284 | * |
| 1285 | * The action name can subsequently be queried from database administration |
| 1286 | * views such as V$SESSION. It can be used for |
| 1287 | * tracing and monitoring such as with V$SQLAREA |
| 1288 | * and DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE. |
| 1289 | * |
| 1290 | * The value may be retained across persistent connections. |
| 1291 | * |
| 1292 | * @param resource $connection An Oracle connection identifier, |
| 1293 | * returned by oci_connect, oci_pconnect, |
| 1294 | * or oci_new_connect. |
| 1295 | * @param string $action_name User chosen string up to 32 bytes long. |
| 1296 | * @throws Oci8Exception |
| 1297 | * |
| 1298 | */ |
| 1299 | function oci_set_action($connection, string $action_name): void |
| 1300 | { |
| 1301 | error_clear_last(); |
| 1302 | $result = \oci_set_action($connection, $action_name); |
| 1303 | if ($result === \false) { |
| 1304 | throw Oci8Exception::createFromPhpError(); |
| 1305 | } |
| 1306 | } |
| 1307 | /** |
| 1308 | * Sets a timeout limiting the maxium time a database round-trip using this connection may take. |
| 1309 | * |
| 1310 | * Each OCI8 operation may make zero or more calls to Oracle's client |
| 1311 | * library. These internal calls may then may make zero or more |
| 1312 | * round-trips to Oracle Database. If any one of those round-trips |
| 1313 | * takes more than time_out milliseconds, then the |
| 1314 | * operation is cancelled and an error is returned to the application. |
| 1315 | * |
| 1316 | * The time_out value applies to each round-trip |
| 1317 | * individually, not to the sum of all round-trips. Time spent |
| 1318 | * processing in PHP OCI8 before or after the completion of each |
| 1319 | * round-trip is not counted. |
| 1320 | * |
| 1321 | * When a call is interrupted, Oracle will attempt to clean up the |
| 1322 | * connection for reuse. This operation is allowed to run for |
| 1323 | * another time_out period. Depending on the |
| 1324 | * outcome of the cleanup, the connection may or may not be reusable. |
| 1325 | * |
| 1326 | * When persistent connections are used, the timeout value will be |
| 1327 | * retained across PHP requests. |
| 1328 | * |
| 1329 | * The oci_set_call_timeout function is available |
| 1330 | * when OCI8 uses Oracle 18 (or later) Client libraries. |
| 1331 | * |
| 1332 | * @param resource $connection An Oracle connection identifier, |
| 1333 | * returned by oci_connect, oci_pconnect, |
| 1334 | * or oci_new_connect. |
| 1335 | * @param int $time_out The maximum time in milliseconds that any single round-trip between PHP and Oracle Database may take. |
| 1336 | * @throws Oci8Exception |
| 1337 | * |
| 1338 | */ |
| 1339 | function oci_set_call_timeout($connection, int $time_out): void |
| 1340 | { |
| 1341 | error_clear_last(); |
| 1342 | $result = \oci_set_call_timeout($connection, $time_out); |
| 1343 | if ($result === \false) { |
| 1344 | throw Oci8Exception::createFromPhpError(); |
| 1345 | } |
| 1346 | } |
| 1347 | /** |
| 1348 | * Sets the client identifier used by various database components to |
| 1349 | * identify lightweight application users who authenticate as the same |
| 1350 | * database user. |
| 1351 | * |
| 1352 | * The client identifier is registered with the database when the next |
| 1353 | * 'round-trip' from PHP to the database occurs, typically when an SQL |
| 1354 | * statement is executed. |
| 1355 | * |
| 1356 | * The identifier can subsequently be queried, for example |
| 1357 | * with SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') |
| 1358 | * FROM DUAL. Database administration views such |
| 1359 | * as V$SESSION will also contain the value. It |
| 1360 | * can be used with DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE |
| 1361 | * for tracing and can also be used for auditing. |
| 1362 | * |
| 1363 | * The value may be retained across page requests that use the same persistent connection. |
| 1364 | * |
| 1365 | * @param resource $connection An Oracle connection identifier, |
| 1366 | * returned by oci_connect, oci_pconnect, |
| 1367 | * or oci_new_connect. |
| 1368 | * @param string $client_identifier User chosen string up to 64 bytes long. |
| 1369 | * @throws Oci8Exception |
| 1370 | * |
| 1371 | */ |
| 1372 | function oci_set_client_identifier($connection, string $client_identifier): void |
| 1373 | { |
| 1374 | error_clear_last(); |
| 1375 | $result = \oci_set_client_identifier($connection, $client_identifier); |
| 1376 | if ($result === \false) { |
| 1377 | throw Oci8Exception::createFromPhpError(); |
| 1378 | } |
| 1379 | } |
| 1380 | /** |
| 1381 | * Sets the client information for Oracle tracing. |
| 1382 | * |
| 1383 | * The client information is registered with the database when the next |
| 1384 | * 'round-trip' from PHP to the database occurs, typically when an SQL |
| 1385 | * statement is executed. |
| 1386 | * |
| 1387 | * The client information can subsequently be queried from database |
| 1388 | * administration views such as V$SESSION. |
| 1389 | * |
| 1390 | * The value may be retained across persistent connections. |
| 1391 | * |
| 1392 | * @param resource $connection An Oracle connection identifier, |
| 1393 | * returned by oci_connect, oci_pconnect, |
| 1394 | * or oci_new_connect. |
| 1395 | * @param string $client_info User chosen string up to 64 bytes long. |
| 1396 | * @throws Oci8Exception |
| 1397 | * |
| 1398 | */ |
| 1399 | function oci_set_client_info($connection, string $client_info): void |
| 1400 | { |
| 1401 | error_clear_last(); |
| 1402 | $result = \oci_set_client_info($connection, $client_info); |
| 1403 | if ($result === \false) { |
| 1404 | throw Oci8Exception::createFromPhpError(); |
| 1405 | } |
| 1406 | } |
| 1407 | /** |
| 1408 | * Sets the DBOP for Oracle tracing. |
| 1409 | * |
| 1410 | * The database operation name is registered with the database when the next |
| 1411 | * 'round-trip' from PHP to the database occurs, typically when a SQL |
| 1412 | * statement is executed. |
| 1413 | * |
| 1414 | * The database operation can subsequently be queried from database administration |
| 1415 | * views such as V$SQL_MONITOR. |
| 1416 | * |
| 1417 | * The oci_set_db_operation function is available |
| 1418 | * when OCI8 uses Oracle 12 (or later) Client libraries and Oracle Database 12 (or later). |
| 1419 | * |
| 1420 | * @param resource $connection An Oracle connection identifier, |
| 1421 | * returned by oci_connect, oci_pconnect, |
| 1422 | * or oci_new_connect. |
| 1423 | * @param string $dbop User chosen string. |
| 1424 | * @throws Oci8Exception |
| 1425 | * |
| 1426 | */ |
| 1427 | function oci_set_db_operation($connection, string $dbop): void |
| 1428 | { |
| 1429 | error_clear_last(); |
| 1430 | $result = \oci_set_db_operation($connection, $dbop); |
| 1431 | if ($result === \false) { |
| 1432 | throw Oci8Exception::createFromPhpError(); |
| 1433 | } |
| 1434 | } |
| 1435 | /** |
| 1436 | * Sets the database "edition" of objects to be used by a subsequent |
| 1437 | * connections. |
| 1438 | * |
| 1439 | * Oracle Editions allow concurrent versions of applications to run |
| 1440 | * using the same schema and object names. This is useful for |
| 1441 | * upgrading live systems. |
| 1442 | * |
| 1443 | * Call oci_set_edition before calling |
| 1444 | * oci_connect, oci_pconnect |
| 1445 | * or oci_new_connect. |
| 1446 | * |
| 1447 | * If an edition is set that is not valid in the database, connection |
| 1448 | * will fail even if oci_set_edition returns success. |
| 1449 | * |
| 1450 | * When using persistent connections, if a connection with the |
| 1451 | * requested edition setting already exists, it is reused. Otherwise, |
| 1452 | * a different persistent connection is created |
| 1453 | * |
| 1454 | * @param string $edition Oracle Database edition name previously created with the SQL |
| 1455 | * "CREATE EDITION" command. |
| 1456 | * @throws Oci8Exception |
| 1457 | * |
| 1458 | */ |
| 1459 | function oci_set_edition(string $edition): void |
| 1460 | { |
| 1461 | error_clear_last(); |
| 1462 | $result = \oci_set_edition($edition); |
| 1463 | if ($result === \false) { |
| 1464 | throw Oci8Exception::createFromPhpError(); |
| 1465 | } |
| 1466 | } |
| 1467 | /** |
| 1468 | * Sets the module name for Oracle tracing. |
| 1469 | * |
| 1470 | * The module name is registered with the database when the next |
| 1471 | * 'round-trip' from PHP to the database occurs, typically when an SQL |
| 1472 | * statement is executed. |
| 1473 | * |
| 1474 | * The name can subsequently be queried from database administration |
| 1475 | * views such as V$SESSION. It can be used for |
| 1476 | * tracing and monitoring such as with V$SQLAREA |
| 1477 | * and DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE. |
| 1478 | * |
| 1479 | * The value may be retained across persistent connections. |
| 1480 | * |
| 1481 | * @param resource $connection An Oracle connection identifier, |
| 1482 | * returned by oci_connect, oci_pconnect, |
| 1483 | * or oci_new_connect. |
| 1484 | * @param string $module_name User chosen string up to 48 bytes long. |
| 1485 | * @throws Oci8Exception |
| 1486 | * |
| 1487 | */ |
| 1488 | function oci_set_module_name($connection, string $module_name): void |
| 1489 | { |
| 1490 | error_clear_last(); |
| 1491 | $result = \oci_set_module_name($connection, $module_name); |
| 1492 | if ($result === \false) { |
| 1493 | throw Oci8Exception::createFromPhpError(); |
| 1494 | } |
| 1495 | } |
| 1496 | /** |
| 1497 | * Sets the number of rows to be buffered by the Oracle Client |
| 1498 | * libraries after a successful query call |
| 1499 | * to oci_execute and for each subsequent |
| 1500 | * internal fetch request to the database. For queries returning a |
| 1501 | * large number of rows, performance can be significantly improved by |
| 1502 | * increasing the prefetch count above the |
| 1503 | * default oci8.default_prefetch |
| 1504 | * value. |
| 1505 | * |
| 1506 | * Prefetching is Oracle's efficient way of returning more than one |
| 1507 | * data row from the database in each network request. This can |
| 1508 | * result in better network and CPU utilization. The buffering of |
| 1509 | * rows is internal to OCI8 and the behavior of OCI8 fetching |
| 1510 | * functions is unchanged regardless of the prefetch count. For |
| 1511 | * example, oci_fetch_row will always return one |
| 1512 | * row. The prefetch buffer is per-statement and is not used by |
| 1513 | * re-executed statements or by other connections. |
| 1514 | * |
| 1515 | * Call oci_set_prefetch before |
| 1516 | * calling oci_execute. |
| 1517 | * |
| 1518 | * A tuning goal is to set the prefetch value to a reasonable size for |
| 1519 | * the network and database to handle. For queries returning a very |
| 1520 | * large number of rows, overall system efficiency might be better if |
| 1521 | * rows are retrieved from the database in several chunks (i.e set the |
| 1522 | * prefetch value smaller than the number of rows). This allows the |
| 1523 | * database to handle other users' statements while the PHP script is |
| 1524 | * processing the current set of rows. |
| 1525 | * |
| 1526 | * Query prefetching was introduced in Oracle 8i. REF CURSOR |
| 1527 | * prefetching was introduced in Oracle 11gR2 and occurs when PHP is |
| 1528 | * linked with Oracle 11gR2 (or later) Client libraries. |
| 1529 | * Nested cursor prefetching was |
| 1530 | * introduced in Oracle 11gR2 and requires both the Oracle Client |
| 1531 | * libraries and the database to be version 11gR2 or greater. |
| 1532 | * |
| 1533 | * Prefetching is not supported when queries contain LONG or LOB |
| 1534 | * columns. The prefetch value is ignored and single-row fetches will |
| 1535 | * be used in all the situations when prefetching is not supported. |
| 1536 | * |
| 1537 | * When using Oracle Database 12c, the prefetch |
| 1538 | * value set by PHP can be overridden by Oracle's |
| 1539 | * client oraaccess.xml configuration file. Refer |
| 1540 | * to Oracle documentation for more detail. |
| 1541 | * |
| 1542 | * @param resource $statement A valid OCI8 statement |
| 1543 | * identifier created by oci_parse and executed |
| 1544 | * by oci_execute, or a REF |
| 1545 | * CURSOR statement identifier. |
| 1546 | * @param int $rows The number of rows to be prefetched, >= 0 |
| 1547 | * @throws Oci8Exception |
| 1548 | * |
| 1549 | */ |
| 1550 | function oci_set_prefetch($statement, int $rows): void |
| 1551 | { |
| 1552 | error_clear_last(); |
| 1553 | $result = \oci_set_prefetch($statement, $rows); |
| 1554 | if ($result === \false) { |
| 1555 | throw Oci8Exception::createFromPhpError(); |
| 1556 | } |
| 1557 | } |
| 1558 | /** |
| 1559 | * Returns a keyword identifying the type of the |
| 1560 | * OCI8 statement. |
| 1561 | * |
| 1562 | * @param resource $statement A valid OCI8 statement identifier from oci_parse. |
| 1563 | * @return string Returns the type of statement as one of the |
| 1564 | * following strings. |
| 1565 | * |
| 1566 | * Statement type |
| 1567 | * |
| 1568 | * |
| 1569 | * |
| 1570 | * Return String |
| 1571 | * Notes |
| 1572 | * |
| 1573 | * |
| 1574 | * |
| 1575 | * |
| 1576 | * ALTER |
| 1577 | * |
| 1578 | * |
| 1579 | * |
| 1580 | * BEGIN |
| 1581 | * |
| 1582 | * |
| 1583 | * |
| 1584 | * CALL |
| 1585 | * Introduced in PHP 5.2.1 (PECL OCI8 1.2.3) |
| 1586 | * |
| 1587 | * |
| 1588 | * CREATE |
| 1589 | * |
| 1590 | * |
| 1591 | * |
| 1592 | * DECLARE |
| 1593 | * |
| 1594 | * |
| 1595 | * |
| 1596 | * DELETE |
| 1597 | * |
| 1598 | * |
| 1599 | * |
| 1600 | * DROP |
| 1601 | * |
| 1602 | * |
| 1603 | * |
| 1604 | * INSERT |
| 1605 | * |
| 1606 | * |
| 1607 | * |
| 1608 | * SELECT |
| 1609 | * |
| 1610 | * |
| 1611 | * |
| 1612 | * UPDATE |
| 1613 | * |
| 1614 | * |
| 1615 | * |
| 1616 | * UNKNOW. |
| 1617 | * @throws Oci8Exception |
| 1618 | * |
| 1619 | */ |
| 1620 | function oci_statement_type($statement): string |
| 1621 | { |
| 1622 | error_clear_last(); |
| 1623 | $result = \oci_statement_type($statement); |
| 1624 | if ($result === \false) { |
| 1625 | throw Oci8Exception::createFromPhpError(); |
| 1626 | } |
| 1627 | return $result; |
| 1628 | } |
| 1629 | /** |
| 1630 | * Unregister the user-defined callback function registered to connection |
| 1631 | * by oci_register_taf_callback. See |
| 1632 | * OCI8 Transparent Application Failover (TAF) Support |
| 1633 | * for information. |
| 1634 | * |
| 1635 | * @param resource $connection An Oracle connection identifier. |
| 1636 | * @throws Oci8Exception |
| 1637 | * |
| 1638 | */ |
| 1639 | function oci_unregister_taf_callback($connection): void |
| 1640 | { |
| 1641 | error_clear_last(); |
| 1642 | $result = \oci_unregister_taf_callback($connection); |
| 1643 | if ($result === \false) { |
| 1644 | throw Oci8Exception::createFromPhpError(); |
| 1645 | } |
| 1646 | } |
| 1647 |