| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\UodbcException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Toggles autocommit behaviour. |
| 9 |
* |
| 10 |
* By default, auto-commit is on for a connection. Disabling |
| 11 |
* auto-commit is equivalent with starting a transaction. |
| 12 |
* |
| 13 |
* @param resource $connection_id The ODBC connection identifier, |
| 14 |
* see odbc_connect for details. |
| 15 |
* @param bool $OnOff If OnOff is TRUE, auto-commit is enabled, if |
| 16 |
* it is FALSE auto-commit is disabled. |
| 17 |
* @return mixed Without the OnOff parameter, this function returns |
| 18 |
* auto-commit status for connection_id. Non-zero is |
| 19 |
* returned if auto-commit is on, 0 if it is off, or FALSE if an error |
| 20 |
* occurs. |
| 21 |
* |
| 22 |
* If OnOff is set, this function returns TRUE on |
| 23 |
* success. |
| 24 |
* @throws UodbcException |
| 25 |
* |
| 26 |
*/ |
| 27 |
function odbc_autocommit($connection_id, bool $OnOff = false) |
| 28 |
{ |
| 29 |
error_clear_last(); |
| 30 |
$result = \odbc_autocommit($connection_id, $OnOff); |
| 31 |
if ($result === false) { |
| 32 |
throw UodbcException::createFromPhpError(); |
| 33 |
} |
| 34 |
return $result; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* Controls handling of binary column data. ODBC SQL types affected are |
| 40 |
* BINARY, VARBINARY, and |
| 41 |
* LONGVARBINARY. |
| 42 |
* The default mode can be set using the |
| 43 |
* uodbc.defaultbinmode php.ini directive. |
| 44 |
* |
| 45 |
* When binary SQL data is converted to character C data (ODBC_BINMODE_CONVERT), each byte |
| 46 |
* (8 bits) of source data is represented as two ASCII characters. |
| 47 |
* These characters are the ASCII character representation of the |
| 48 |
* number in its hexadecimal form. For example, a binary |
| 49 |
* 00000001 is converted to |
| 50 |
* "01" and a binary 11111111 |
| 51 |
* is converted to "FF". |
| 52 |
* |
| 53 |
* While the handling of BINARY and VARBINARY |
| 54 |
* columns only depend on the binmode, the handling of LONGVARBINARY |
| 55 |
* columns also depends on the longreadlen as well: |
| 56 |
* |
| 57 |
* LONGVARBINARY handling |
| 58 |
* |
| 59 |
* |
| 60 |
* |
| 61 |
* binmode |
| 62 |
* longreadlen |
| 63 |
* result |
| 64 |
* |
| 65 |
* |
| 66 |
* |
| 67 |
* |
| 68 |
* ODBC_BINMODE_PASSTHRU |
| 69 |
* 0 |
| 70 |
* passthru |
| 71 |
* |
| 72 |
* |
| 73 |
* ODBC_BINMODE_RETURN |
| 74 |
* 0 |
| 75 |
* passthru |
| 76 |
* |
| 77 |
* |
| 78 |
* ODBC_BINMODE_CONVERT |
| 79 |
* 0 |
| 80 |
* passthru |
| 81 |
* |
| 82 |
* |
| 83 |
* ODBC_BINMODE_PASSTHRU |
| 84 |
* >0 |
| 85 |
* passthru |
| 86 |
* |
| 87 |
* |
| 88 |
* ODBC_BINMODE_RETURN |
| 89 |
* >0 |
| 90 |
* return as is |
| 91 |
* |
| 92 |
* |
| 93 |
* ODBC_BINMODE_CONVERT |
| 94 |
* >0 |
| 95 |
* return as char |
| 96 |
* |
| 97 |
* |
| 98 |
* |
| 99 |
* |
| 100 |
* |
| 101 |
* If odbc_fetch_into is used, passthru means that an |
| 102 |
* empty string is returned for these columns. |
| 103 |
* If odbc_result is used, passthru means that the data are |
| 104 |
* sent directly to the client (i.e. printed). |
| 105 |
* |
| 106 |
* @param int $result_id The result identifier. |
| 107 |
* |
| 108 |
* If result_id is 0, the |
| 109 |
* settings apply as default for new results. |
| 110 |
* @param int $mode Possible values for mode are: |
| 111 |
* |
| 112 |
* |
| 113 |
* |
| 114 |
* ODBC_BINMODE_PASSTHRU: Passthru BINARY data |
| 115 |
* |
| 116 |
* |
| 117 |
* |
| 118 |
* |
| 119 |
* ODBC_BINMODE_RETURN: Return as is |
| 120 |
* |
| 121 |
* |
| 122 |
* |
| 123 |
* |
| 124 |
* ODBC_BINMODE_CONVERT: Convert to char and return |
| 125 |
* |
| 126 |
* |
| 127 |
* |
| 128 |
* |
| 129 |
* |
| 130 |
* Handling of binary long |
| 131 |
* columns is also affected by odbc_longreadlen. |
| 132 |
* |
| 133 |
* |
| 134 |
* @throws UodbcException |
| 135 |
* |
| 136 |
*/ |
| 137 |
function odbc_binmode(int $result_id, int $mode): void |
| 138 |
{ |
| 139 |
error_clear_last(); |
| 140 |
$result = \odbc_binmode($result_id, $mode); |
| 141 |
if ($result === false) { |
| 142 |
throw UodbcException::createFromPhpError(); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
/** |
| 148 |
* Lists columns and associated privileges for the given table. |
| 149 |
* |
| 150 |
* @param resource $connection_id The ODBC connection identifier, |
| 151 |
* see odbc_connect for details. |
| 152 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 153 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 154 |
* This parameter accepts the following search patterns: |
| 155 |
* % to match zero or more characters, |
| 156 |
* and _ to match a single character. |
| 157 |
* @param string $table_name The table name. |
| 158 |
* This parameter accepts the following search patterns: |
| 159 |
* % to match zero or more characters, |
| 160 |
* and _ to match a single character. |
| 161 |
* @param string $column_name The column name. |
| 162 |
* This parameter accepts the following search patterns: |
| 163 |
* % to match zero or more characters, |
| 164 |
* and _ to match a single character. |
| 165 |
* @return resource Returns an ODBC result identifier. |
| 166 |
* This result identifier can be used to fetch a list of columns and |
| 167 |
* associated privileges. |
| 168 |
* |
| 169 |
* The result set has the following columns: |
| 170 |
* |
| 171 |
* TABLE_CAT |
| 172 |
* TABLE_SCHEM |
| 173 |
* TABLE_NAME |
| 174 |
* COLUMN_NAME |
| 175 |
* GRANTOR |
| 176 |
* GRANTEE |
| 177 |
* PRIVILEGE |
| 178 |
* IS_GRANTABLE |
| 179 |
* |
| 180 |
* Drivers can report additional columns. |
| 181 |
* @throws UodbcException |
| 182 |
* |
| 183 |
*/ |
| 184 |
function odbc_columnprivileges($connection_id, string $catalog, string $schema, string $table_name, string $column_name) |
| 185 |
{ |
| 186 |
error_clear_last(); |
| 187 |
$result = \odbc_columnprivileges($connection_id, $catalog, $schema, $table_name, $column_name); |
| 188 |
if ($result === false) { |
| 189 |
throw UodbcException::createFromPhpError(); |
| 190 |
} |
| 191 |
return $result; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
/** |
| 196 |
* Lists all columns in the requested range. |
| 197 |
* |
| 198 |
* @param resource $connection_id The ODBC connection identifier, |
| 199 |
* see odbc_connect for details. |
| 200 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 201 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 202 |
* This parameter accepts the following search patterns: |
| 203 |
* % to match zero or more characters, |
| 204 |
* and _ to match a single character. |
| 205 |
* @param string $table_name The table name. |
| 206 |
* This parameter accepts the following search patterns: |
| 207 |
* % to match zero or more characters, |
| 208 |
* and _ to match a single character. |
| 209 |
* @param string $column_name The column name. |
| 210 |
* This parameter accepts the following search patterns: |
| 211 |
* % to match zero or more characters, |
| 212 |
* and _ to match a single character. |
| 213 |
* @return resource Returns an ODBC result identifier. |
| 214 |
* |
| 215 |
* The result set has the following columns: |
| 216 |
* |
| 217 |
* TABLE_CAT |
| 218 |
* TABLE_SCHEM |
| 219 |
* TABLE_NAME |
| 220 |
* COLUMN_NAME |
| 221 |
* DATA_TYPE |
| 222 |
* TYPE_NAME |
| 223 |
* COLUMN_SIZE |
| 224 |
* BUFFER_LENGTH |
| 225 |
* DECIMAL_DIGITS |
| 226 |
* NUM_PREC_RADIX |
| 227 |
* NULLABLE |
| 228 |
* REMARKS |
| 229 |
* COLUMN_DEF |
| 230 |
* SQL_DATA_TYPE |
| 231 |
* SQL_DATETIME_SUB |
| 232 |
* CHAR_OCTET_LENGTH |
| 233 |
* ORDINAL_POSITION |
| 234 |
* IS_NULLABLE |
| 235 |
* |
| 236 |
* Drivers can report additional columns. |
| 237 |
* @throws UodbcException |
| 238 |
* |
| 239 |
*/ |
| 240 |
function odbc_columns($connection_id, string $catalog = null, string $schema = null, string $table_name = null, string $column_name = null) |
| 241 |
{ |
| 242 |
error_clear_last(); |
| 243 |
if ($column_name !== null) { |
| 244 |
$result = \odbc_columns($connection_id, $catalog, $schema, $table_name, $column_name); |
| 245 |
} elseif ($table_name !== null) { |
| 246 |
$result = \odbc_columns($connection_id, $catalog, $schema, $table_name); |
| 247 |
} elseif ($schema !== null) { |
| 248 |
$result = \odbc_columns($connection_id, $catalog, $schema); |
| 249 |
} elseif ($catalog !== null) { |
| 250 |
$result = \odbc_columns($connection_id, $catalog); |
| 251 |
} else { |
| 252 |
$result = \odbc_columns($connection_id); |
| 253 |
} |
| 254 |
if ($result === false) { |
| 255 |
throw UodbcException::createFromPhpError(); |
| 256 |
} |
| 257 |
return $result; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
/** |
| 262 |
* Commits all pending transactions on the connection. |
| 263 |
* |
| 264 |
* @param resource $connection_id The ODBC connection identifier, |
| 265 |
* see odbc_connect for details. |
| 266 |
* @throws UodbcException |
| 267 |
* |
| 268 |
*/ |
| 269 |
function odbc_commit($connection_id): void |
| 270 |
{ |
| 271 |
error_clear_last(); |
| 272 |
$result = \odbc_commit($connection_id); |
| 273 |
if ($result === false) { |
| 274 |
throw UodbcException::createFromPhpError(); |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
/** |
| 280 |
* This function will return the list of available DSN (after calling it |
| 281 |
* several times). |
| 282 |
* |
| 283 |
* @param resource $connection_id The ODBC connection identifier, |
| 284 |
* see odbc_connect for details. |
| 285 |
* @param int $fetch_type The fetch_type can be one of two constant types: |
| 286 |
* SQL_FETCH_FIRST, SQL_FETCH_NEXT. |
| 287 |
* Use SQL_FETCH_FIRST the first time this function is |
| 288 |
* called, thereafter use the SQL_FETCH_NEXT. |
| 289 |
* @return array Returns FALSE on error, an array upon success, and NULL after fetching |
| 290 |
* the last available DSN. |
| 291 |
* @throws UodbcException |
| 292 |
* |
| 293 |
*/ |
| 294 |
function odbc_data_source($connection_id, int $fetch_type): array |
| 295 |
{ |
| 296 |
error_clear_last(); |
| 297 |
$result = \odbc_data_source($connection_id, $fetch_type); |
| 298 |
if ($result === false) { |
| 299 |
throw UodbcException::createFromPhpError(); |
| 300 |
} |
| 301 |
return $result; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
/** |
| 306 |
* Sends an SQL statement to the database server. |
| 307 |
* |
| 308 |
* @param resource $connection_id The ODBC connection identifier, |
| 309 |
* see odbc_connect for details. |
| 310 |
* @param string $query_string The SQL statement. |
| 311 |
* @param int $flags This parameter is currently not used. |
| 312 |
* @return resource Returns an ODBC result identifier if the SQL command was executed |
| 313 |
* successfully. |
| 314 |
* @throws UodbcException |
| 315 |
* |
| 316 |
*/ |
| 317 |
function odbc_exec($connection_id, string $query_string, int $flags = null) |
| 318 |
{ |
| 319 |
error_clear_last(); |
| 320 |
if ($flags !== null) { |
| 321 |
$result = \odbc_exec($connection_id, $query_string, $flags); |
| 322 |
} else { |
| 323 |
$result = \odbc_exec($connection_id, $query_string); |
| 324 |
} |
| 325 |
if ($result === false) { |
| 326 |
throw UodbcException::createFromPhpError(); |
| 327 |
} |
| 328 |
return $result; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
/** |
| 333 |
* Executes a statement prepared with odbc_prepare. |
| 334 |
* |
| 335 |
* @param resource $result_id The result id resource, from odbc_prepare. |
| 336 |
* @param array $parameters_array Parameters in parameter_array will be |
| 337 |
* substituted for placeholders in the prepared statement in order. |
| 338 |
* Elements of this array will be converted to strings by calling this |
| 339 |
* function. |
| 340 |
* |
| 341 |
* Any parameters in parameter_array which |
| 342 |
* start and end with single quotes will be taken as the name of a |
| 343 |
* file to read and send to the database server as the data for the |
| 344 |
* appropriate placeholder. |
| 345 |
* @throws UodbcException |
| 346 |
* |
| 347 |
*/ |
| 348 |
function odbc_execute($result_id, array $parameters_array = null): void |
| 349 |
{ |
| 350 |
error_clear_last(); |
| 351 |
if ($parameters_array !== null) { |
| 352 |
$result = \odbc_execute($result_id, $parameters_array); |
| 353 |
} else { |
| 354 |
$result = \odbc_execute($result_id); |
| 355 |
} |
| 356 |
if ($result === false) { |
| 357 |
throw UodbcException::createFromPhpError(); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
/** |
| 363 |
* Fetch one result row into array. |
| 364 |
* |
| 365 |
* @param resource $result_id The result resource. |
| 366 |
* @param array|null $result_array The result array |
| 367 |
* that can be of any type since it will be converted to type |
| 368 |
* array. The array will contain the column values starting at array |
| 369 |
* index 0. |
| 370 |
* @param int $rownumber The row number. |
| 371 |
* @return int Returns the number of columns in the result; |
| 372 |
* FALSE on error. |
| 373 |
* @throws UodbcException |
| 374 |
* |
| 375 |
*/ |
| 376 |
function odbc_fetch_into($result_id, ?array &$result_array, int $rownumber = null): int |
| 377 |
{ |
| 378 |
error_clear_last(); |
| 379 |
if ($rownumber !== null) { |
| 380 |
$result = \odbc_fetch_into($result_id, $result_array, $rownumber); |
| 381 |
} else { |
| 382 |
$result = \odbc_fetch_into($result_id, $result_array); |
| 383 |
} |
| 384 |
if ($result === false) { |
| 385 |
throw UodbcException::createFromPhpError(); |
| 386 |
} |
| 387 |
return $result; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
/** |
| 392 |
* Gets the length of the field referenced by number in the given result |
| 393 |
* identifier. |
| 394 |
* |
| 395 |
* @param resource $result_id The result identifier. |
| 396 |
* @param int $field_number The field number. Field numbering starts at 1. |
| 397 |
* @return int Returns the field length. |
| 398 |
* @throws UodbcException |
| 399 |
* |
| 400 |
*/ |
| 401 |
function odbc_field_len($result_id, int $field_number): int |
| 402 |
{ |
| 403 |
error_clear_last(); |
| 404 |
$result = \odbc_field_len($result_id, $field_number); |
| 405 |
if ($result === false) { |
| 406 |
throw UodbcException::createFromPhpError(); |
| 407 |
} |
| 408 |
return $result; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
/** |
| 413 |
* Gets the name of the field occupying the given column number in the given |
| 414 |
* result identifier. |
| 415 |
* |
| 416 |
* @param resource $result_id The result identifier. |
| 417 |
* @param int $field_number The field number. Field numbering starts at 1. |
| 418 |
* @return string Returns the field name as a string. |
| 419 |
* @throws UodbcException |
| 420 |
* |
| 421 |
*/ |
| 422 |
function odbc_field_name($result_id, int $field_number): string |
| 423 |
{ |
| 424 |
error_clear_last(); |
| 425 |
$result = \odbc_field_name($result_id, $field_number); |
| 426 |
if ($result === false) { |
| 427 |
throw UodbcException::createFromPhpError(); |
| 428 |
} |
| 429 |
return $result; |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
/** |
| 434 |
* Gets the number of the column slot that corresponds to the named field in |
| 435 |
* the given result identifier. |
| 436 |
* |
| 437 |
* @param resource $result_id The result identifier. |
| 438 |
* @param string $field_name The field name. |
| 439 |
* @return int Returns the field number as a integer. |
| 440 |
* Field numbering starts at 1. |
| 441 |
* @throws UodbcException |
| 442 |
* |
| 443 |
*/ |
| 444 |
function odbc_field_num($result_id, string $field_name): int |
| 445 |
{ |
| 446 |
error_clear_last(); |
| 447 |
$result = \odbc_field_num($result_id, $field_name); |
| 448 |
if ($result === false) { |
| 449 |
throw UodbcException::createFromPhpError(); |
| 450 |
} |
| 451 |
return $result; |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
/** |
| 456 |
* Gets the scale of the field referenced by number in the given result |
| 457 |
* identifier. |
| 458 |
* |
| 459 |
* @param resource $result_id The result identifier. |
| 460 |
* @param int $field_number The field number. Field numbering starts at 1. |
| 461 |
* @return int Returns the field scale as a integer. |
| 462 |
* @throws UodbcException |
| 463 |
* |
| 464 |
*/ |
| 465 |
function odbc_field_scale($result_id, int $field_number): int |
| 466 |
{ |
| 467 |
error_clear_last(); |
| 468 |
$result = \odbc_field_scale($result_id, $field_number); |
| 469 |
if ($result === false) { |
| 470 |
throw UodbcException::createFromPhpError(); |
| 471 |
} |
| 472 |
return $result; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
/** |
| 477 |
* Gets the SQL type of the field referenced by number in the given result |
| 478 |
* identifier. |
| 479 |
* |
| 480 |
* @param resource $result_id The result identifier. |
| 481 |
* @param int $field_number The field number. Field numbering starts at 1. |
| 482 |
* @return string Returns the field type as a string. |
| 483 |
* @throws UodbcException |
| 484 |
* |
| 485 |
*/ |
| 486 |
function odbc_field_type($result_id, int $field_number): string |
| 487 |
{ |
| 488 |
error_clear_last(); |
| 489 |
$result = \odbc_field_type($result_id, $field_number); |
| 490 |
if ($result === false) { |
| 491 |
throw UodbcException::createFromPhpError(); |
| 492 |
} |
| 493 |
return $result; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
/** |
| 498 |
* Retrieves a list of foreign keys in the specified table or a list of |
| 499 |
* foreign keys in other tables that refer to the primary key in the |
| 500 |
* specified table |
| 501 |
* |
| 502 |
* @param resource $connection_id The ODBC connection identifier, |
| 503 |
* see odbc_connect for details. |
| 504 |
* @param string $pk_catalog The catalog ('qualifier' in ODBC 2 parlance) of the primary key table. |
| 505 |
* @param string $pk_schema The schema ('owner' in ODBC 2 parlance) of the primary key table. |
| 506 |
* @param string $pk_table The primary key table. |
| 507 |
* @param string $fk_catalog The catalog ('qualifier' in ODBC 2 parlance) of the foreign key table. |
| 508 |
* @param string $fk_schema The schema ('owner' in ODBC 2 parlance) of the foreign key table. |
| 509 |
* @param string $fk_table The foreign key table. |
| 510 |
* @return resource Returns an ODBC result identifier. |
| 511 |
* |
| 512 |
* The result set has the following columns: |
| 513 |
* |
| 514 |
* PKTABLE_CAT |
| 515 |
* PKTABLE_SCHEM |
| 516 |
* PKTABLE_NAME |
| 517 |
* PKCOLUMN_NAME |
| 518 |
* FKTABLE_CAT |
| 519 |
* FKTABLE_SCHEM |
| 520 |
* FKTABLE_NAME |
| 521 |
* FKCOLUMN_NAME |
| 522 |
* KEY_SEQ |
| 523 |
* UPDATE_RULE |
| 524 |
* DELETE_RULE |
| 525 |
* FK_NAME |
| 526 |
* PK_NAME |
| 527 |
* DEFERRABILITY |
| 528 |
* |
| 529 |
* Drivers can report additional columns. |
| 530 |
* @throws UodbcException |
| 531 |
* |
| 532 |
*/ |
| 533 |
function odbc_foreignkeys($connection_id, string $pk_catalog, string $pk_schema, string $pk_table, string $fk_catalog, string $fk_schema, string $fk_table) |
| 534 |
{ |
| 535 |
error_clear_last(); |
| 536 |
$result = \odbc_foreignkeys($connection_id, $pk_catalog, $pk_schema, $pk_table, $fk_catalog, $fk_schema, $fk_table); |
| 537 |
if ($result === false) { |
| 538 |
throw UodbcException::createFromPhpError(); |
| 539 |
} |
| 540 |
return $result; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
/** |
| 545 |
* Retrieves information about data types supported by the data source. |
| 546 |
* |
| 547 |
* @param resource $connection_id The ODBC connection identifier, |
| 548 |
* see odbc_connect for details. |
| 549 |
* @param int $data_type The data type, which can be used to restrict the information to a |
| 550 |
* single data type. |
| 551 |
* @return resource Returns an ODBC result identifier. |
| 552 |
* |
| 553 |
* The result set has the following columns: |
| 554 |
* |
| 555 |
* TYPE_NAME |
| 556 |
* DATA_TYPE |
| 557 |
* PRECISION |
| 558 |
* LITERAL_PREFIX |
| 559 |
* LITERAL_SUFFIX |
| 560 |
* CREATE_PARAMS |
| 561 |
* NULLABLE |
| 562 |
* CASE_SENSITIVE |
| 563 |
* SEARCHABLE |
| 564 |
* UNSIGNED_ATTRIBUTE |
| 565 |
* MONEY |
| 566 |
* AUTO_INCREMENT |
| 567 |
* LOCAL_TYPE_NAME |
| 568 |
* MINIMUM_SCALE |
| 569 |
* MAXIMUM_SCALE |
| 570 |
* |
| 571 |
* |
| 572 |
* The result set is ordered by DATA_TYPE and TYPE_NAME. |
| 573 |
* @throws UodbcException |
| 574 |
* |
| 575 |
*/ |
| 576 |
function odbc_gettypeinfo($connection_id, int $data_type = null) |
| 577 |
{ |
| 578 |
error_clear_last(); |
| 579 |
if ($data_type !== null) { |
| 580 |
$result = \odbc_gettypeinfo($connection_id, $data_type); |
| 581 |
} else { |
| 582 |
$result = \odbc_gettypeinfo($connection_id); |
| 583 |
} |
| 584 |
if ($result === false) { |
| 585 |
throw UodbcException::createFromPhpError(); |
| 586 |
} |
| 587 |
return $result; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
/** |
| 592 |
* Controls handling of LONG, LONGVARCHAR and LONGVARBINARY columns. |
| 593 |
* The default length can be set using the |
| 594 |
* uodbc.defaultlrl php.ini directive. |
| 595 |
* |
| 596 |
* @param resource $result_id The result identifier. |
| 597 |
* @param int $length The number of bytes returned to PHP is controlled by the parameter |
| 598 |
* length. If it is set to 0, long column data is passed through to the |
| 599 |
* client (i.e. printed) when retrieved with odbc_result. |
| 600 |
* @throws UodbcException |
| 601 |
* |
| 602 |
*/ |
| 603 |
function odbc_longreadlen($result_id, int $length): void |
| 604 |
{ |
| 605 |
error_clear_last(); |
| 606 |
$result = \odbc_longreadlen($result_id, $length); |
| 607 |
if ($result === false) { |
| 608 |
throw UodbcException::createFromPhpError(); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
/** |
| 614 |
* Prepares a statement for execution. The result identifier can be used |
| 615 |
* later to execute the statement with odbc_execute. |
| 616 |
* |
| 617 |
* Some databases (such as IBM DB2, MS SQL Server, and Oracle) support |
| 618 |
* stored procedures that accept parameters of type IN, INOUT, and OUT as |
| 619 |
* defined by the ODBC specification. However, the Unified ODBC driver |
| 620 |
* currently only supports parameters of type IN to stored procedures. |
| 621 |
* |
| 622 |
* @param resource $connection_id The ODBC connection identifier, |
| 623 |
* see odbc_connect for details. |
| 624 |
* @param string $query_string The query string statement being prepared. |
| 625 |
* @return resource Returns an ODBC result identifier if the SQL command was prepared |
| 626 |
* successfully. |
| 627 |
* @throws UodbcException |
| 628 |
* |
| 629 |
*/ |
| 630 |
function odbc_prepare($connection_id, string $query_string) |
| 631 |
{ |
| 632 |
error_clear_last(); |
| 633 |
$result = \odbc_prepare($connection_id, $query_string); |
| 634 |
if ($result === false) { |
| 635 |
throw UodbcException::createFromPhpError(); |
| 636 |
} |
| 637 |
return $result; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
/** |
| 642 |
* Returns a result identifier that can be used to fetch the column names |
| 643 |
* that comprise the primary key for a table. |
| 644 |
* |
| 645 |
* @param resource $connection_id The ODBC connection identifier, |
| 646 |
* see odbc_connect for details. |
| 647 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 648 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 649 |
* @param string $table |
| 650 |
* @return resource Returns an ODBC result identifier. |
| 651 |
* |
| 652 |
* The result set has the following columns: |
| 653 |
* |
| 654 |
* TABLE_CAT |
| 655 |
* TABLE_SCHEM |
| 656 |
* TABLE_NAME |
| 657 |
* COLUMN_NAME |
| 658 |
* KEY_SEQ |
| 659 |
* PK_NAME |
| 660 |
* |
| 661 |
* Drivers can report additional columns. |
| 662 |
* @throws UodbcException |
| 663 |
* |
| 664 |
*/ |
| 665 |
function odbc_primarykeys($connection_id, string $catalog, string $schema, string $table) |
| 666 |
{ |
| 667 |
error_clear_last(); |
| 668 |
$result = \odbc_primarykeys($connection_id, $catalog, $schema, $table); |
| 669 |
if ($result === false) { |
| 670 |
throw UodbcException::createFromPhpError(); |
| 671 |
} |
| 672 |
return $result; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
/** |
| 677 |
* Prints all rows from a result identifier produced by |
| 678 |
* odbc_exec. The result is printed in HTML table format. |
| 679 |
* The data is not escaped. |
| 680 |
* |
| 681 |
* This function is not supposed to be used in production environments; it is |
| 682 |
* merely meant for development purposes, to get a result set quickly rendered. |
| 683 |
* |
| 684 |
* @param resource $result_id The result identifier. |
| 685 |
* @param string $format Additional overall table formatting. |
| 686 |
* @return int Returns the number of rows in the result. |
| 687 |
* @throws UodbcException |
| 688 |
* |
| 689 |
*/ |
| 690 |
function odbc_result_all($result_id, string $format = null): int |
| 691 |
{ |
| 692 |
error_clear_last(); |
| 693 |
if ($format !== null) { |
| 694 |
$result = \odbc_result_all($result_id, $format); |
| 695 |
} else { |
| 696 |
$result = \odbc_result_all($result_id); |
| 697 |
} |
| 698 |
if ($result === false) { |
| 699 |
throw UodbcException::createFromPhpError(); |
| 700 |
} |
| 701 |
return $result; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
/** |
| 706 |
* Get result data |
| 707 |
* |
| 708 |
* @param resource $result_id The ODBC resource. |
| 709 |
* @param mixed $field The field name being retrieved. It can either be an integer containing |
| 710 |
* the column number of the field you want; or it can be a string |
| 711 |
* containing the name of the field. |
| 712 |
* @return mixed Returns the string contents of the field, FALSE on error, NULL for |
| 713 |
* NULL data, or TRUE for binary data. |
| 714 |
* @throws UodbcException |
| 715 |
* |
| 716 |
*/ |
| 717 |
function odbc_result($result_id, $field) |
| 718 |
{ |
| 719 |
error_clear_last(); |
| 720 |
$result = \odbc_result($result_id, $field); |
| 721 |
if ($result === false) { |
| 722 |
throw UodbcException::createFromPhpError(); |
| 723 |
} |
| 724 |
return $result; |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
/** |
| 729 |
* Rolls back all pending statements on the connection. |
| 730 |
* |
| 731 |
* @param resource $connection_id The ODBC connection identifier, |
| 732 |
* see odbc_connect for details. |
| 733 |
* @throws UodbcException |
| 734 |
* |
| 735 |
*/ |
| 736 |
function odbc_rollback($connection_id): void |
| 737 |
{ |
| 738 |
error_clear_last(); |
| 739 |
$result = \odbc_rollback($connection_id); |
| 740 |
if ($result === false) { |
| 741 |
throw UodbcException::createFromPhpError(); |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
/** |
| 747 |
* This function allows fiddling with the ODBC options for a |
| 748 |
* particular connection or query result. It was written to help |
| 749 |
* find work around to problems in quirky ODBC drivers. You should |
| 750 |
* probably only use this function if you are an ODBC programmer and |
| 751 |
* understand the effects the various options will have. You will |
| 752 |
* certainly need a good ODBC reference to explain all the different |
| 753 |
* options and values that can be used. Different driver versions |
| 754 |
* support different options. |
| 755 |
* |
| 756 |
* Because the effects may vary depending on the ODBC driver, use of |
| 757 |
* this function in scripts to be made publicly available is |
| 758 |
* strongly discouraged. Also, some ODBC options are not available |
| 759 |
* to this function because they must be set before the connection |
| 760 |
* is established or the query is prepared. However, if on a |
| 761 |
* particular job it can make PHP work so your boss doesn't tell you |
| 762 |
* to use a commercial product, that's all that really |
| 763 |
* matters. |
| 764 |
* |
| 765 |
* @param resource $id Is a connection id or result id on which to change the settings. |
| 766 |
* For SQLSetConnectOption(), this is a connection id. |
| 767 |
* For SQLSetStmtOption(), this is a result id. |
| 768 |
* @param int $function Is the ODBC function to use. The value should be |
| 769 |
* 1 for SQLSetConnectOption() and |
| 770 |
* 2 for SQLSetStmtOption(). |
| 771 |
* @param int $option The option to set. |
| 772 |
* @param int $param The value for the given option. |
| 773 |
* @throws UodbcException |
| 774 |
* |
| 775 |
*/ |
| 776 |
function odbc_setoption($id, int $function, int $option, int $param): void |
| 777 |
{ |
| 778 |
error_clear_last(); |
| 779 |
$result = \odbc_setoption($id, $function, $option, $param); |
| 780 |
if ($result === false) { |
| 781 |
throw UodbcException::createFromPhpError(); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
/** |
| 787 |
* Retrieves either the optimal set of columns that uniquely identifies a |
| 788 |
* row in the table, or columns that are automatically updated when any |
| 789 |
* value in the row is updated by a transaction. |
| 790 |
* |
| 791 |
* @param resource $connection_id The ODBC connection identifier, |
| 792 |
* see odbc_connect for details. |
| 793 |
* @param int $type |
| 794 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 795 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 796 |
* @param string $table The table. |
| 797 |
* @param int $scope The scope, which orders the result set. |
| 798 |
* One of SQL_SCOPE_CURROW, SQL_SCOPE_TRANSACTION |
| 799 |
* or SQL_SCOPE_SESSION. |
| 800 |
* @param int $nullable Determines whether to return special columns that can have a NULL value. |
| 801 |
* One of SQL_NO_NULLS or SQL_NULLABLE . |
| 802 |
* @return resource Returns an ODBC result identifier. |
| 803 |
* |
| 804 |
* The result set has the following columns: |
| 805 |
* |
| 806 |
* SCOPE |
| 807 |
* COLUMN_NAME |
| 808 |
* DATA_TYPE |
| 809 |
* TYPE_NAME |
| 810 |
* COLUMN_SIZE |
| 811 |
* BUFFER_LENGTH |
| 812 |
* DECIMAL_DIGITS |
| 813 |
* PSEUDO_COLUMN |
| 814 |
* |
| 815 |
* Drivers can report additional columns. |
| 816 |
* @throws UodbcException |
| 817 |
* |
| 818 |
*/ |
| 819 |
function odbc_specialcolumns($connection_id, int $type, string $catalog, string $schema, string $table, int $scope, int $nullable) |
| 820 |
{ |
| 821 |
error_clear_last(); |
| 822 |
$result = \odbc_specialcolumns($connection_id, $type, $catalog, $schema, $table, $scope, $nullable); |
| 823 |
if ($result === false) { |
| 824 |
throw UodbcException::createFromPhpError(); |
| 825 |
} |
| 826 |
return $result; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
/** |
| 831 |
* Get statistics about a table and its indexes. |
| 832 |
* |
| 833 |
* @param resource $connection_id The ODBC connection identifier, |
| 834 |
* see odbc_connect for details. |
| 835 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 836 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 837 |
* @param string $table_name The table name. |
| 838 |
* @param int $unique The type of the index. |
| 839 |
* One of SQL_INDEX_UNIQUE or SQL_INDEX_ALL. |
| 840 |
* @param int $accuracy One of SQL_ENSURE or SQL_QUICK. |
| 841 |
* The latter requests that the driver retrieve the CARDINALITY and |
| 842 |
* PAGES only if they are readily available from the server. |
| 843 |
* @return resource Returns an ODBC result identifier. |
| 844 |
* |
| 845 |
* The result set has the following columns: |
| 846 |
* |
| 847 |
* TABLE_CAT |
| 848 |
* TABLE_SCHEM |
| 849 |
* TABLE_NAME |
| 850 |
* NON_UNIQUE |
| 851 |
* INDEX_QUALIFIER |
| 852 |
* INDEX_NAME |
| 853 |
* TYPE |
| 854 |
* ORDINAL_POSITION |
| 855 |
* COLUMN_NAME |
| 856 |
* ASC_OR_DESC |
| 857 |
* CARDINALITY |
| 858 |
* PAGES |
| 859 |
* FILTER_CONDITION |
| 860 |
* |
| 861 |
* Drivers can report additional columns. |
| 862 |
* @throws UodbcException |
| 863 |
* |
| 864 |
*/ |
| 865 |
function odbc_statistics($connection_id, string $catalog, string $schema, string $table_name, int $unique, int $accuracy) |
| 866 |
{ |
| 867 |
error_clear_last(); |
| 868 |
$result = \odbc_statistics($connection_id, $catalog, $schema, $table_name, $unique, $accuracy); |
| 869 |
if ($result === false) { |
| 870 |
throw UodbcException::createFromPhpError(); |
| 871 |
} |
| 872 |
return $result; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
/** |
| 877 |
* Lists tables in the requested range and the privileges associated |
| 878 |
* with each table. |
| 879 |
* |
| 880 |
* @param resource $connection_id The ODBC connection identifier, |
| 881 |
* see odbc_connect for details. |
| 882 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 883 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 884 |
* This parameter accepts the following search patterns: |
| 885 |
* % to match zero or more characters, |
| 886 |
* and _ to match a single character. |
| 887 |
* @param string $name The name. |
| 888 |
* This parameter accepts the following search patterns: |
| 889 |
* % to match zero or more characters, |
| 890 |
* and _ to match a single character. |
| 891 |
* @return resource An ODBC result identifier. |
| 892 |
* |
| 893 |
* The result set has the following columns: |
| 894 |
* |
| 895 |
* TABLE_CAT |
| 896 |
* TABLE_SCHEM |
| 897 |
* TABLE_NAME |
| 898 |
* GRANTOR |
| 899 |
* GRANTEE |
| 900 |
* PRIVILEGE |
| 901 |
* IS_GRANTABLE |
| 902 |
* |
| 903 |
* Drivers can report additional columns. |
| 904 |
* @throws UodbcException |
| 905 |
* |
| 906 |
*/ |
| 907 |
function odbc_tableprivileges($connection_id, string $catalog, string $schema, string $name) |
| 908 |
{ |
| 909 |
error_clear_last(); |
| 910 |
$result = \odbc_tableprivileges($connection_id, $catalog, $schema, $name); |
| 911 |
if ($result === false) { |
| 912 |
throw UodbcException::createFromPhpError(); |
| 913 |
} |
| 914 |
return $result; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
/** |
| 919 |
* Lists all tables in the requested range. |
| 920 |
* |
| 921 |
* To support enumeration of qualifiers, owners, and table types, |
| 922 |
* the following special semantics for the |
| 923 |
* catalog, schema, |
| 924 |
* name, and |
| 925 |
* table_type are available: |
| 926 |
* |
| 927 |
* |
| 928 |
* |
| 929 |
* If catalog is a single percent |
| 930 |
* character (%) and schema and |
| 931 |
* name are empty strings, then the result |
| 932 |
* set contains a list of valid qualifiers for the data |
| 933 |
* source. (All columns except the TABLE_QUALIFIER column contain |
| 934 |
* NULLs.) |
| 935 |
* |
| 936 |
* |
| 937 |
* |
| 938 |
* |
| 939 |
* If schema is a single percent character |
| 940 |
* (%) and catalog and |
| 941 |
* name are empty strings, then the result |
| 942 |
* set contains a list of valid owners for the data source. (All |
| 943 |
* columns except the TABLE_OWNER column contain |
| 944 |
* NULLs.) |
| 945 |
* |
| 946 |
* |
| 947 |
* |
| 948 |
* |
| 949 |
* If table_type is a single percent |
| 950 |
* character (%) and catalog, |
| 951 |
* schema and name |
| 952 |
* are empty strings, then the result set contains a list of |
| 953 |
* valid table types for the data source. (All columns except the |
| 954 |
* TABLE_TYPE column contain NULLs.) |
| 955 |
* |
| 956 |
* |
| 957 |
* |
| 958 |
* |
| 959 |
* @param resource $connection_id The ODBC connection identifier, |
| 960 |
* see odbc_connect for details. |
| 961 |
* @param string $catalog The catalog ('qualifier' in ODBC 2 parlance). |
| 962 |
* @param string $schema The schema ('owner' in ODBC 2 parlance). |
| 963 |
* This parameter accepts the following search patterns: |
| 964 |
* % to match zero or more characters, |
| 965 |
* and _ to match a single character. |
| 966 |
* @param string $name The name. |
| 967 |
* This parameter accepts the following search patterns: |
| 968 |
* % to match zero or more characters, |
| 969 |
* and _ to match a single character. |
| 970 |
* @param string $types If table_type is not an empty string, it |
| 971 |
* must contain a list of comma-separated values for the types of |
| 972 |
* interest; each value may be enclosed in single quotes (') or |
| 973 |
* unquoted. For example, 'TABLE','VIEW' or TABLE, VIEW. If the |
| 974 |
* data source does not support a specified table type, |
| 975 |
* odbc_tables does not return any results for |
| 976 |
* that type. |
| 977 |
* @return resource Returns an ODBC result identifier containing the information. |
| 978 |
* |
| 979 |
* The result set has the following columns: |
| 980 |
* |
| 981 |
* TABLE_CAT |
| 982 |
* TABLE_SCHEM |
| 983 |
* TABLE_NAME |
| 984 |
* TABLE_TYPE |
| 985 |
* REMARKS |
| 986 |
* |
| 987 |
* Drivers can report additional columns. |
| 988 |
* @throws UodbcException |
| 989 |
* |
| 990 |
*/ |
| 991 |
function odbc_tables($connection_id, string $catalog = null, string $schema = null, string $name = null, string $types = null) |
| 992 |
{ |
| 993 |
error_clear_last(); |
| 994 |
if ($types !== null) { |
| 995 |
$result = \odbc_tables($connection_id, $catalog, $schema, $name, $types); |
| 996 |
} elseif ($name !== null) { |
| 997 |
$result = \odbc_tables($connection_id, $catalog, $schema, $name); |
| 998 |
} elseif ($schema !== null) { |
| 999 |
$result = \odbc_tables($connection_id, $catalog, $schema); |
| 1000 |
} elseif ($catalog !== null) { |
| 1001 |
$result = \odbc_tables($connection_id, $catalog); |
| 1002 |
} else { |
| 1003 |
$result = \odbc_tables($connection_id); |
| 1004 |
} |
| 1005 |
if ($result === false) { |
| 1006 |
throw UodbcException::createFromPhpError(); |
| 1007 |
} |
| 1008 |
return $result; |
| 1009 |
} |
| 1010 |
|