├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CREDITS ├── LICENSE ├── README.md ├── config.m4 ├── config.w32 ├── ibm_driver.c ├── ibm_statement.c ├── package.xml ├── pdo_ibm.c ├── php_pdo_ibm.h ├── php_pdo_ibm_int.h └── tests ├── README400.txt ├── TESTMATRIX ├── clob.dat ├── fvt.inc ├── fvt400.inc ├── fvt_001_DbConn.phpt ├── fvt_002_CountRowsAffected.phpt ├── fvt_003_ConnWrongUserPwd_01.phpt ├── fvt_004_ConnWrongUserPwd_02.phpt ├── fvt_005_DrvVersion.phpt ├── fvt_006_ErrConditions_01.phpt ├── fvt_006_V5V6_ErrConditions_01.phpt ├── fvt_007_ErrConditions_02.phpt ├── fvt_007_V5V6_ErrConditions_02.phpt ├── fvt_008_ErrNonExistentTables.phpt ├── fvt_008_V5_ErrNonExistentTables.phpt ├── fvt_008_V6_ErrNonExistentTables.phpt ├── fvt_009_ErrFaultySQL.phpt ├── fvt_009_V5V6_ErrFaultySQL.phpt ├── fvt_010_UpdateRowCount.phpt ├── fvt_011_DeleteRowCount.phpt ├── fvt_012_SelectRowCount.phpt ├── fvt_013_ScrollableCursorNegativeRow.phpt ├── fvt_013_V5V6_ScrollableCursorNegativeRow.phpt ├── fvt_014_InsertDeleteRowCount.phpt ├── fvt_015_InsertSelectClobBlobColumns.phpt ├── fvt_015_V5V6_InsertSelectClobBlobColumns.phpt ├── fvt_016_InsertIntegerBindingString.phpt ├── fvt_017_InsertRetrieveLargeClobFile_01.phpt ├── fvt_017_V5V6_InsertRetrieveLargeClobFile_01.phpt ├── fvt_017b_InsertRetrieveLargeClobFile_02.phpt ├── fvt_017b_V5V6_InsertRetrieveLargeClobFile_02.phpt ├── fvt_017c_SelectLOBs.phpt ├── fvt_018_QuoteString.phpt ├── fvt_020_Rollback.phpt ├── fvt_021_Commit.phpt ├── fvt_022_RollbackAutocommitOFF.phpt ├── fvt_023_CommitAutocommitOFF.phpt ├── fvt_023_V5V6_CommitAutocommitOFF.phpt ├── fvt_024_ChangeFetchModes.phpt ├── fvt_024_V5V6_ChangeFetchModes.phpt ├── fvt_025_ColumnMetaData.phpt ├── fvt_025_V5V6_ColumnMetaData.phpt ├── fvt_026_ErrCode.phpt ├── fvt_026_V5V6_ErrCode.phpt ├── fvt_027_FetchColModeOptions.phpt ├── fvt_028_ExecutBasicSP.phpt ├── fvt_028_V5V6_ExecutBasicSP.phpt ├── fvt_030_PDOStatement_fetch.phpt ├── fvt_031_FetchOrientations.phpt ├── fvt_031_V5V6_FetchOrientations.phpt ├── fvt_032_FailureErrCodes.phpt ├── fvt_032_V5V6_FailureErrCodes.phpt ├── fvt_033_ErrNullConnParams.phpt ├── fvt_033_V5V6_ErrNullConnParams.phpt ├── fvt_034_ErrNonExistentTableInsert.phpt ├── fvt_034_V5V6_ErrNonExistentTableInsert.phpt ├── fvt_035_ExecReturnVal.phpt ├── fvt_036_SettingDiffOpt.phpt ├── fvt_036_V5V6_SettingDiffOpt.phpt ├── fvt_038_LastInsertID.phpt ├── fvt_038_V5V6_LastInsertID.phpt ├── fvt_040_ServerInfo.phpt ├── fvt_040_V5V6_ServerInfo.phpt ├── fvt_49872_ClearingErrCodes.phpt ├── fvt_49872_V5V6_ClearingErrCodes.phpt ├── fvt_66610_V6_stored_proc_io_char.phpt ├── fvt_66620_V6_stored_proc_io_int.phpt ├── fvt_66630_V6_stored_proc_io_real.phpt ├── fvt_66640_V6_stored_proc_io_dec.phpt ├── fvt_66699_V6_xmlservice.phpt ├── fvt_77710_V6_system_naming_libchar.phpt ├── fvt_77720_V6_system_naming_libint.phpt ├── fvt_77730_V6_system_naming_libreal.phpt ├── fvt_77740_V6_system_naming_libdec.phpt ├── fvt_V5V6_SQLParamData_fail.phpt ├── fvt_V5V6_isam_error.phpt ├── fvt_boolean.phpt ├── fvt_client_info.phpt ├── fvt_handle_empty_parameter.phpt ├── fvt_isam_error.phpt ├── fvt_trusted_context.phpt ├── large_blob.dat ├── large_clob.dat ├── skipif.PASE ├── skipif.inc └── spook.png /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | jobs: 10 | # XXX: macOS 11 | ubuntu: 12 | strategy: 13 | matrix: 14 | version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] 15 | runs-on: ubuntu-latest 16 | services: 17 | ibm_db2: 18 | image: "icr.io/db2_community/db2:11.5.8.0" 19 | env: 20 | DB2INST1_PASSWORD: "password" 21 | LICENSE: "accept" 22 | DBNAME: "sample" 23 | options: "--privileged=true" 24 | ports: 25 | - "60000:50000" 26 | volumes: 27 | - database:/database 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v2 31 | - name: Cache DB2 library 32 | id: cache-clidriver 33 | uses: actions/cache@v2 34 | with: 35 | path: clidriver 36 | key: ${{ runner.os }}-clidriver 37 | - name: Install DB2 library 38 | if: steps.cache-clidriver.outputs.cache-hit != 'true' 39 | run: | 40 | wget https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz 41 | tar xvzf linuxx64_odbc_cli.tar.gz 42 | - name: Setup PHP 43 | uses: shivammathur/setup-php@v2 44 | with: 45 | php-version: ${{matrix.version}} 46 | extensions: pdo 47 | - name: phpize 48 | run: phpize 49 | - name: configure 50 | run: ./configure --with-pdo-ibm=$PWD/clidriver 51 | - name: make 52 | run: make V=1 53 | - name: Set up Db2 LUW in Docker 54 | run: | 55 | set -x 56 | cat < db2cli.ini 57 | [SAMPLE] 58 | Hostname=localhost 59 | Protocol=TCPIP 60 | Port=60000 61 | Database=sample 62 | EOF 63 | mkdir database 64 | - name: "Perform healthcheck on db2 service" 65 | run: "docker logs -f ${{ job.services.ibm_db2.id }} | sed '/(*) Setup has completed./ q'" 66 | - name: Tests 67 | # make test is insufficient to load PDO 68 | # Most of these are either cribbed from the old Travis configuration, 69 | # or required for the tests to use the DSN. 70 | run: | 71 | export TEST_PHP_ARGS="-n -d extension=pdo.so -d extension=modules/pdo_ibm.so" 72 | export DISABLE_SKIP_CACHE=1 73 | export IBM_DB2_TEST_SKIP_CONNECT_FAILURE=0 74 | export DB2CLIINIPATH=$PWD 75 | export REPORT_EXIT_STATUS=1 76 | export PDOTEST_DSN=ibm:DSN=SAMPLE 77 | export PDOTEST_USER=db2inst1 78 | export PDOTEST_PASS=password 79 | php run-tests.php -P --show-diff tests 80 | - name: Verify package 81 | run: pecl package-validate 82 | windows: 83 | defaults: 84 | run: 85 | shell: cmd 86 | strategy: 87 | matrix: 88 | version: ["8.1", "8.2", "8.3", "8.4"] 89 | arch: [x64] 90 | ts: [ts] 91 | runs-on: windows-latest 92 | steps: 93 | - name: Checkout 94 | uses: actions/checkout@v2 95 | - name: Cache DB2 library 96 | id: cache-clidriver 97 | uses: actions/cache@v2 98 | with: 99 | path: clidriver 100 | key: ${{ runner.os }}-clidriver 101 | - name: Install DB2 library 102 | if: steps.cache-clidriver.outputs.cache-hit != 'true' 103 | shell: pwsh 104 | run: | 105 | Invoke-WebRequest -Uri 'https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/ntx64_odbc_cli.zip' -OutFile 'ntx64_odbc_cli.zip' 106 | Expand-Archive 'ntx64_odbc_cli.zip' -DestinationPath '.\' 107 | - name: Setup PHP 108 | id: setup-php 109 | uses: php/setup-php-sdk@v0.9 110 | with: 111 | version: ${{matrix.version}} 112 | arch: ${{matrix.arch}} 113 | ts: ${{matrix.ts}} 114 | - name: Enable Developer Command Prompt 115 | uses: ilammy/msvc-dev-cmd@v1 116 | with: 117 | arch: ${{matrix.arch}} 118 | toolset: ${{steps.setup-php.outputs.toolset}} 119 | - name: phpize 120 | run: phpize 121 | - name: configure 122 | run: configure --with-pdo-ibm=%cd%\clidriver --with-prefix=${{steps.setup-php.outputs.prefix}} 123 | - name: make 124 | run: nmake 125 | # XXX: Can we run Docker containers in a Windows runner? That'll be required for tests 126 | #- name: test 127 | # run: nmake test TESTS=tests 128 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # phpize stuff 2 | .libs 3 | Makefile* 4 | *.m4 5 | autom4te.cache 6 | build 7 | config.* 8 | configure* 9 | ibm_db2.la 10 | ibm_db2.lo 11 | install-sh 12 | libtool 13 | ltmain.sh 14 | missing 15 | mkinstalldirs 16 | modules 17 | run-tests.php 18 | tmp-php.ini 19 | 20 | # autotools sludge 21 | *.la 22 | *.lo 23 | 24 | # phpt generated files 25 | tests/*.diff 26 | tests/*.exp 27 | tests/*.log 28 | tests/*.out 29 | tests/*.sh 30 | tests/*.php 31 | 32 | # downloaded cli driver 33 | clidriver 34 | 35 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | pdo_ibm 2 | Rick McGuire, Dan Scott, Krishna Raman, Kellen Bombardier, Ambrish Bhargava, Rahul Priyadarshi 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 12 | 13 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 14 | 15 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 16 | 17 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 18 | 19 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 20 | 21 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 22 | 23 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 24 | 25 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 26 | 27 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 28 | 29 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 30 | 31 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 32 | 33 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 34 | 35 | 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and 36 | 37 | 2. You must cause any modified files to carry prominent notices stating that You changed the files; and 38 | 39 | 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 40 | 41 | 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 42 | 43 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 44 | 45 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 46 | 47 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 48 | 49 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 50 | 51 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 52 | 53 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 54 | 55 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDO_IBM 2 | 3 | Interface for PHP to DB2 for z/OS, DB2 for LUW, DB2 for i. 4 | 5 | ## Pre-requisites 6 | 7 | The minimum PHP version supported by driver is PHP 7.3 and the latest version supported is PHP 8.2. 8 | 9 | ## IBM i users 10 | 11 | When running on IBM i, `PDO_IBM` doesn't link with the Db2 LUW client library, 12 | but instead with libdb400, which provides a PASE wrapper for SQL/CLI. The 13 | differences between SQL/CLI in IBM i and the LUW driver are wrapped for you. 14 | You don't need Db2 Connect on IBM i as a result. 15 | 16 | To install, make sure you have the new Yum-based OSS environment. Install PHP, 17 | plus any dependencies like so: 18 | 19 | ```shell 20 | yum install sqlcli-devel gcc make-gnu 21 | ``` 22 | 23 | Tony Cairns' [replacement libdb400](https://bitbucket.org/litmis/db2sock/src/master/db2/) 24 | is not yet tested, but may be desirable due to its greater debugging features. 25 | 26 | IBM i users should read `tests/README400.txt` in order to set up prequisites 27 | for unit tests. 28 | 29 | ## LUW/z/Db2 Connect users 30 | 31 | CLIDRIVER should be installed in your system. 32 | If not installed Download from the below link. 33 | 34 | [DOWNLOAD CLI DRIVER](https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/) 35 | 36 | PHP should be installed in your system. 37 | 38 | ## How to install php pdo_ibm extension in Linux/Mac 39 | 40 | If `IBM_DB_HOME` and `LD_LIBRARY_PATH` environment variables are not set, then set them with installed CLIDRIVER. 41 | (say CLIDRIVER installed at `/home/user/clidriver`) 42 | 43 | ```shell 44 | export IBM_DB_HOME=/home/user/clidriver 45 | export LD_LIBRARY_PATH="${IBM_DB_HOME}/lib" 46 | ``` 47 | 48 | 1. Install this extension: 49 | 50 | ```shell 51 | pecl install pdo_ibm 52 | ``` 53 | 54 | 2. Open the `php.ini` file in an editor of your choice. Edit the extension entry in the 55 | `php.ini` file in the `/php/lib` directory to reference the PHP driver: 56 | 57 | ```ini 58 | extension=pdo_ibm.so 59 | ``` 60 | 61 | 3. Ensure that the PHP driver can access the `libdb2.so` CLI driver file by 62 | setting the `LD_LIBRARY_PATH` variable for Linux and UNIX operating systems 63 | other than the AIX® operating system. For AIX operating system, you must set `LIBPATH` variable. 64 | 65 | 4. Optionally, if the PHP application that is connecting to an IBM database server is running in 66 | the HTTP server environment, add the `LD_LIBRARY_PATH` variable in the `httpd.conf` file. 67 | 68 | ## Prebuilt binaries for Windows 69 | 70 | 1. Add the `CLIDRIVER\bin` path to the `PATH` environment variable like so (for a batch file): 71 | 72 | ```shell 73 | set PATH=\bin;%PATH% 74 | ``` 75 | 76 | 2. Download the DLLs for PHP 7.x and 8.x from [the ibmdb repository](https://github.com/ibmdb/php_ibm_db2). 77 | Select the build for the PHP that matches the version, architecture, and thread model. 78 | 79 | 3. Open the `php.ini` file in an editor of your choice. Edit the extension entry in the 80 | `php.ini` file in the `\php\lib` directory to reference the driver: 81 | 82 | ```ini 83 | extension=php_pdo_ibm 84 | ``` 85 | 86 | ## How to run sample program 87 | 88 | Create a `connect.php` script with the following content: 89 | 90 | ```php 91 | '; 94 | $user = ''; 95 | $pass = ''; 96 | 97 | $pdo = new \PDO($dsn, $user, $pass); 98 | ``` 99 | 100 | To run the sample: 101 | 102 | ``` 103 | php connect.php 104 | ``` 105 | 106 | ## Contributing: 107 | 108 | The developer sign-off should include the reference to the DCO in defect remarks, like in this example: 109 | 110 | ``` 111 | DCO 1.1 Signed-off-by: Random J Developer 112 | ``` 113 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | if test "$PHP_PDO" != "no"; then 2 | 3 | PHP_ARG_WITH(pdo-ibm, for DB2 driver for PDO, 4 | [ --with-pdo-ibm[=DIR] Include PDO DB2 support, DIR is the base 5 | DB2 install directory, defaults to ${DB2DIR:-nothing}. 6 | Set the PHP_PDO_IBM_LIB environment variable to set 7 | the specific location of the DB2 libraries]) 8 | 9 | if test "$PHP_PDO_IBM" != "no"; then 10 | SEARCH_PATH="$PHP_PDO_IBM_LIB $PHP_PDO_IBM $DB2PATH $DB2DIR" 11 | 12 | dnl Scan the library path for LUW, clidriver, and libdb400 in the usual 13 | dnl places, also assuming include/ is in the directory too. 14 | for i in $SEARCH_PATH ; do 15 | dnl XXX: The messages kinda suck and don't indicate which path 16 | dnl (combined with AC_MSG_* spew from AC_CHECK_LIB) 17 | dnl XXX: Macros for this? Can these be merged? 18 | 19 | dnl LUW ships its client libraries in lib64/32 (at least on amd64 linux) 20 | AC_CHECK_SIZEOF([long]) 21 | AC_MSG_CHECKING([if we're on a 64-bit platform]) 22 | AS_IF([test "$ac_cv_sizeof_long" -eq 4],[ 23 | AC_MSG_RESULT([no]) 24 | PHP_CHECK_LIBRARY(db2, SQLDriverConnect, [ 25 | PHP_ADD_LIBPATH($i/lib32, PDO_IBM_SHARED_LIBADD) 26 | PHP_ADD_LIBRARY(db2, 1, PDO_IBM_SHARED_LIBADD) 27 | PHP_ADD_INCLUDE($i/include) 28 | break 29 | ], [], "-L$i/lib32" ) 30 | ],[ 31 | AC_MSG_RESULT([yes]) 32 | PHP_CHECK_LIBRARY(db2, SQLDriverConnect, [ 33 | PHP_ADD_LIBPATH($i/lib64, PDO_IBM_SHARED_LIBADD) 34 | PHP_ADD_LIBRARY(db2, 1, PDO_IBM_SHARED_LIBADD) 35 | PHP_ADD_INCLUDE($i/include) 36 | break 37 | ], [], "-L$i/lib64" ) 38 | ]) 39 | dnl The standalone clidriver package uses lib/ 40 | PHP_CHECK_LIBRARY(db2, SQLDriverConnect, [ 41 | PHP_ADD_LIBPATH($i/lib, PDO_IBM_SHARED_LIBADD) 42 | PHP_ADD_LIBRARY(db2, 1, PDO_IBM_SHARED_LIBADD) 43 | PHP_ADD_INCLUDE($i/include) 44 | break 45 | ], [ 46 | ], "-L$i/lib" ) 47 | dnl Special cases for PASE 48 | dnl SG ships a custom libdb400 (with renamed funcs to co-exist w/ ODBC) 49 | dnl it requires some special handling for headers too 50 | PHP_CHECK_LIBRARY(db400sg, LDBDriverConnect, [ 51 | PDO_IBM_PASE=yes 52 | dnl from RPMs libdb400sg-devel and sqlcli-devel 53 | dnl as IBM i doesn't ship SQL/CLI headers w/ PASE (and RPM's in subdir) 54 | PHP_ADD_LIBPATH($i/lib, PDO_IBM_SHARED_LIBADD) 55 | PHP_ADD_LIBRARY(db400sg, 1, PDO_IBM_SHARED_LIBADD) 56 | PHP_ADD_INCLUDE(/QOpenSys/pkgs/include/cli-sg) 57 | PHP_ADD_INCLUDE(/QOpenSys/pkgs/include/cli) 58 | break 59 | ], [ 60 | ], "-L$i/lib" ) 61 | dnl Probably vanilla libdb400 62 | dnl XXX: For PASE, libdb400 is likely on the default path 63 | PHP_CHECK_LIBRARY(db400, SQLDriverConnect, [ 64 | PDO_IBM_PASE=yes 65 | dnl from RPM sqlcli-devel 66 | PHP_ADD_LIBPATH($i/lib, PDO_IBM_SHARED_LIBADD) 67 | PHP_ADD_LIBRARY(db400, 1, PDO_IBM_SHARED_LIBADD) 68 | PHP_ADD_INCLUDE(/QOpenSys/pkgs/include/cli) 69 | break 70 | ], [ 71 | ], "-L$i/lib" ) 72 | done 73 | 74 | PHP_CHECK_PDO_INCLUDES 75 | 76 | dnl Don't forget to add additional source files here 77 | php_pdo_ibm_sources_core="pdo_ibm.c ibm_driver.c ibm_statement.c" 78 | 79 | dnl Convert the includes to __PASE__ (for IBM-shipped GCC) or use AC_DEFINE 80 | if test "$PDO_IBM_PASE" = "yes" ; then 81 | PHP_NEW_EXTENSION(pdo_ibm, $php_pdo_ibm_sources_core, $ext_shared,,-I$pdo_cv_inc_path -DPASE) 82 | else 83 | PHP_NEW_EXTENSION(pdo_ibm, $php_pdo_ibm_sources_core, $ext_shared,,-I$pdo_cv_inc_path) 84 | fi 85 | 86 | PHP_ADD_EXTENSION_DEP(pdo_ibm, pdo) 87 | 88 | PHP_SUBST(PDO_IBM_SHARED_LIBADD) 89 | 90 | fi 91 | 92 | fi 93 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | ARG_WITH("pdo-ibm", "DB2 support for PDO. Pass the location of the DB2 installation, for example, --with-pdo-ibm=C:\\SQLLIB", "no"); 2 | 3 | if (PHP_PDO_IBM != "no") 4 | { 5 | /* amd64 version is different name */ 6 | if (CHECK_LIB("db2cli.lib", "pdo_ibm", PHP_PDO_IBM) || CHECK_LIB("db2cli64.lib", "pdo_ibm", PHP_PDO_IBM)) 7 | { 8 | CHECK_HEADER_ADD_INCLUDE('sql.h', 'CFLAGS_PDO_IBM', PHP_PDO_IBM + '\\include;' + PHP_PHP_BUILD + '\\include\\db2'); 9 | CHECK_HEADER_ADD_INCLUDE('sqlext.h', 'CFLAGS_PDO_IBM', PHP_PDO_IBM + '\\include;' + PHP_PHP_BUILD + '\\include\\db2'); 10 | ADD_FLAG( 'CFLAGS_PDO_IBM' , '/I "' + PHP_PDO_IBM + '\\include" '); 11 | ADD_FLAG( 'LDFLAGS_PDO_IBM' , '/libpath:"' + PHP_PDO_IBM + '\\lib" ' ); 12 | EXTENSION('pdo_ibm', "pdo_ibm.c ibm_driver.c ibm_statement.c"); 13 | } 14 | else 15 | { 16 | WARNING("pdo_ibm not enabled; libraries and headers not found"); 17 | } 18 | ADD_EXTENSION_DEP("pdo_ibm", "pdo"); 19 | } 20 | -------------------------------------------------------------------------------- /pdo_ibm.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | (C) Copyright IBM Corporation 2006. | 4 | +----------------------------------------------------------------------+ 5 | | | 6 | | Licensed under the Apache License, Version 2.0 (the "License"); you | 7 | | may not use this file except in compliance with the License. You may | 8 | | obtain a copy of the License at | 9 | | http://www.apache.org/licenses/LICENSE-2.0 | 10 | | | 11 | | Unless required by applicable law or agreed to in writing, software | 12 | | distributed under the License is distributed on an "AS IS" BASIS, | 13 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | 14 | | implied. See the License for the specific language governing | 15 | | permissions and limitations under the License. | 16 | +----------------------------------------------------------------------+ 17 | | Authors: Rick McGuire, Dan Scott, Krishna Raman, Kellen Bombardier, | 18 | | Ambrish Bhargava, Rahul Priyadarshi | 19 | +----------------------------------------------------------------------+ 20 | */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "php.h" 27 | #include "php_ini.h" 28 | #include "ext/standard/info.h" 29 | #include "pdo/php_pdo_driver.h" 30 | #include "php_pdo_ibm.h" 31 | #include "php_pdo_ibm_int.h" 32 | 33 | /* If you declare any globals in php_pdo_ibm.h uncomment this: 34 | */ 35 | #ifdef PASE 36 | ZEND_DECLARE_MODULE_GLOBALS(pdo_ibm) 37 | #endif 38 | 39 | /* True global resources - no need for thread safety here */ 40 | static int le_pdo_ibm; 41 | extern pdo_driver_t pdo_ibm_driver; /* the registration table */ 42 | 43 | 44 | #ifdef PASE /* PASE i5/OS start-up */ 45 | #include 46 | #endif /* PASE */ 47 | 48 | /* {{{ pdo_ibm_deps 49 | */ 50 | #if ZEND_MODULE_API_NO >= 20041225 51 | static zend_module_dep pdo_ibm_deps[] = { 52 | ZEND_MOD_REQUIRED("pdo") 53 | {NULL, NULL, NULL} 54 | }; 55 | #endif 56 | /* }}} */ 57 | 58 | /* {{{ pdo_ibm_module_entry 59 | */ 60 | zend_module_entry pdo_ibm_module_entry = 61 | { 62 | #if ZEND_MODULE_API_NO >= 20041225 63 | STANDARD_MODULE_HEADER_EX, NULL, 64 | pdo_ibm_deps, 65 | #else 66 | STANDARD_MODULE_HEADER, 67 | #endif 68 | "pdo_ibm", 69 | NULL, 70 | PHP_MINIT(pdo_ibm), 71 | PHP_MSHUTDOWN(pdo_ibm), 72 | PHP_RINIT(pdo_ibm), /* Replace with NULL if there's nothing to do at request start */ 73 | PHP_RSHUTDOWN(pdo_ibm), /* Replace with NULL if there's nothing to do at request end */ 74 | PHP_MINFO(pdo_ibm), 75 | PDO_IBM_VERSION, /* Replace with version number for your extension */ 76 | STANDARD_MODULE_PROPERTIES 77 | }; 78 | /* }}} */ 79 | 80 | #ifdef COMPILE_DL_PDO_IBM 81 | ZEND_GET_MODULE(pdo_ibm) 82 | #endif 83 | 84 | /* {{{ PHP_INI 85 | */ 86 | #ifdef PASE /* i5/OS specific functions */ 87 | PHP_INI_BEGIN() 88 | STD_PHP_INI_ENTRY("pdo_ibm.i5_override_ccsid", "0", PHP_INI_SYSTEM, OnUpdateLong, 89 | i5_override_ccsid, zend_pdo_ibm_globals, pdo_ibm_globals) 90 | STD_PHP_INI_ENTRY("pdo_ibm.i5_dbcs_alloc", "0", PHP_INI_SYSTEM, OnUpdateLong, 91 | i5_dbcs_alloc, zend_pdo_ibm_globals, pdo_ibm_globals) 92 | PHP_INI_END() 93 | #endif /* PASE */ 94 | 95 | 96 | #ifdef PASE /* prior any CLI routine override ascii ccsid */ 97 | /* {{{ php_pdo_ibm_init_globals 98 | */ 99 | static void php_pdo_ibm_init_globals(zend_pdo_ibm_globals *pdo_ibm_globals) 100 | { 101 | if (pdo_ibm_globals->i5_override_ccsid) { 102 | /* This routine should be called by the application prior 103 | * to any other CLI routine to override the ascii ccsid 104 | * being retrieved from the Qp2RunPase() routine. If this 105 | * routine is called after any CLI routine is called in 106 | * the process it will have no effect. 107 | */ 108 | SQLOverrideCCSID400(pdo_ibm_globals->i5_override_ccsid); 109 | } 110 | } 111 | /* }}} */ 112 | #endif /* PASE */ 113 | 114 | /* {{{ PHP_MINIT_FUNCTION 115 | */ 116 | PHP_MINIT_FUNCTION(pdo_ibm) 117 | { 118 | #ifdef PASE 119 | /* Only PASE has INI entries right now. */ 120 | ZEND_INIT_MODULE_GLOBALS(pdo_ibm, php_pdo_ibm_init_globals, NULL); 121 | REGISTER_INI_ENTRIES(); 122 | #endif 123 | 124 | #ifndef PASE /* i5/OS no support trusted */ 125 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_USE_TRUSTED_CONTEXT", (long) PDO_SQL_ATTR_USE_TRUSTED_CONTEXT); 126 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_TRUSTED_CONTEXT_USERID", (long) PDO_SQL_ATTR_TRUSTED_CONTEXT_USERID); 127 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_TRUSTED_CONTEXT_PASSWORD", (long) PDO_SQL_ATTR_TRUSTED_CONTEXT_PASSWORD); 128 | #else /* PASE i5/OS introduced (1.3.4) */ 129 | REGISTER_PDO_CLASS_CONST_LONG("I5_ATTR_DBC_SYS_NAMING", (long)PDO_I5_ATTR_DBC_SYS_NAMING); 130 | 131 | REGISTER_PDO_CLASS_CONST_LONG("I5_ATTR_COMMIT", (long)PDO_I5_ATTR_COMMIT); 132 | REGISTER_PDO_CLASS_CONST_LONG("I5_TXN_NO_COMMIT", (long)PDO_I5_TXN_NO_COMMIT); 133 | REGISTER_PDO_CLASS_CONST_LONG("I5_TXN_READ_UNCOMMITTED", (long)PDO_I5_TXN_READ_UNCOMMITTED); 134 | REGISTER_PDO_CLASS_CONST_LONG("I5_TXN_READ_COMMITTED", (long)PDO_I5_TXN_READ_COMMITTED); 135 | REGISTER_PDO_CLASS_CONST_LONG("I5_TXN_REPEATABLE_READ", (long)PDO_I5_TXN_REPEATABLE_READ); 136 | REGISTER_PDO_CLASS_CONST_LONG("I5_TXN_SERIALIZABLE", (long)PDO_I5_TXN_SERIALIZABLE); 137 | 138 | REGISTER_PDO_CLASS_CONST_LONG("I5_ATTR_JOB_SORT", (long)PDO_I5_ATTR_JOB_SORT); 139 | REGISTER_PDO_CLASS_CONST_LONG("I5_ATTR_DBC_LIBL", (long)PDO_I5_ATTR_DBC_LIBL); 140 | REGISTER_PDO_CLASS_CONST_LONG("I5_ATTR_DBC_CURLIB", (long)PDO_I5_ATTR_DBC_CURLIB); 141 | #endif /* PASE */ 142 | 143 | /* Client information variables */ 144 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_INFO_USERID", (long) PDO_SQL_ATTR_INFO_USERID); 145 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_INFO_ACCTSTR", (long) PDO_SQL_ATTR_INFO_ACCTSTR); 146 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_INFO_APPLNAME", (long) PDO_SQL_ATTR_INFO_APPLNAME); 147 | REGISTER_PDO_CLASS_CONST_LONG("SQL_ATTR_INFO_WRKSTNNAME", (long) PDO_SQL_ATTR_INFO_WRKSTNNAME); 148 | 149 | php_pdo_register_driver(&pdo_ibm_driver); 150 | return TRUE; 151 | } 152 | /* }}} */ 153 | 154 | /* {{{ PHP_MSHUTDOWN_FUNCTION 155 | */ 156 | PHP_MSHUTDOWN_FUNCTION(pdo_ibm) 157 | { 158 | /* uncomment this line if you have INI entries 159 | UNREGISTER_INI_ENTRIES(); 160 | */ 161 | 162 | php_pdo_unregister_driver(&pdo_ibm_driver); 163 | return TRUE; 164 | } 165 | /* }}} */ 166 | 167 | /* Remove if there's nothing to do at request start */ 168 | /* {{{ PHP_RINIT_FUNCTION 169 | */ 170 | PHP_RINIT_FUNCTION(pdo_ibm) 171 | { 172 | return TRUE; 173 | } 174 | /* }}} */ 175 | 176 | /* Remove if there's nothing to do at request end */ 177 | /* {{{ PHP_RSHUTDOWN_FUNCTION 178 | */ 179 | PHP_RSHUTDOWN_FUNCTION(pdo_ibm) 180 | { 181 | return TRUE; 182 | } 183 | /* }}} */ 184 | 185 | /* {{{ PHP_MINFO_FUNCTION 186 | */ 187 | PHP_MINFO_FUNCTION(pdo_ibm) 188 | { 189 | php_info_print_table_start(); 190 | php_info_print_table_header(2, "pdo_ibm support", "enabled"); 191 | php_info_print_table_row(2, "Module release", PDO_IBM_VERSION); 192 | php_info_print_table_end(); 193 | 194 | #ifdef PASE 195 | DISPLAY_INI_ENTRIES(); 196 | #endif 197 | } 198 | /* }}} */ 199 | 200 | /* }}} */ 201 | -------------------------------------------------------------------------------- /php_pdo_ibm.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | (C) Copyright IBM Corporation 2006. | 4 | +----------------------------------------------------------------------+ 5 | | | 6 | | Licensed under the Apache License, Version 2.0 (the "License"); you | 7 | | may not use this file except in compliance with the License. You may | 8 | | obtain a copy of the License at | 9 | | http://www.apache.org/licenses/LICENSE-2.0 | 10 | | | 11 | | Unless required by applicable law or agreed to in writing, software | 12 | | distributed under the License is distributed on an "AS IS" BASIS, | 13 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | 14 | | implied. See the License for the specific language governing | 15 | | permissions and limitations under the License. | 16 | +----------------------------------------------------------------------+ 17 | | Authors: Rick McGuire, Dan Scott, Krishna Raman, Kellen Bombardier, | 18 | | Ambrish Bhargava | 19 | +----------------------------------------------------------------------+ 20 | */ 21 | 22 | #ifndef PHP_PDO_IBM_H 23 | #define PHP_PDO_IBM_H 24 | 25 | #define PDO_IBM_VERSION "1.6.1" 26 | 27 | extern zend_module_entry pdo_ibm_module_entry; 28 | #define phpext_pdo_ibm_ptr &pdo_ibm_module_entry 29 | 30 | #ifdef PHP_WIN32 31 | #define PHP_PDO_IBM_API __declspec(dllexport) 32 | #else 33 | #define PHP_PDO_IBM_API 34 | #endif 35 | 36 | #ifdef ZTS 37 | #include "TSRM.h" 38 | #endif 39 | 40 | PHP_MINIT_FUNCTION(pdo_ibm); 41 | PHP_MSHUTDOWN_FUNCTION(pdo_ibm); 42 | PHP_RINIT_FUNCTION(pdo_ibm); 43 | PHP_RSHUTDOWN_FUNCTION(pdo_ibm); 44 | PHP_MINFO_FUNCTION(pdo_ibm); 45 | 46 | /* 47 | Declare any global variables you may need between the BEGIN 48 | and END macros here: 49 | */ 50 | #ifdef PASE /* i5/OS ease of use turn off/on */ 51 | ZEND_BEGIN_MODULE_GLOBALS(pdo_ibm) 52 | long i5_ignore_userid; /* blank userid, possible no qsqsrvr */ 53 | long i5_override_ccsid; /* prior any CLI routine override ascii ccsid */ 54 | long i5_dbcs_alloc; /* if to overallocate buffers for unpredictable conversions */ 55 | ZEND_END_MODULE_GLOBALS(pdo_ibm) 56 | #endif /* PASE */ 57 | 58 | 59 | /* 60 | In every utility function you add that needs to use variables 61 | in php_pdo_ibm_globals, call TSRMLS_FETCH(); after declaring other 62 | variables used by that function, or better yet, pass in TSRMLS_CC 63 | after the last function argument and declare your utility function 64 | with TSRMLS_DC after the last declared argument. Always refer to 65 | the globals in your function as PDO_IBM_G(variable). You are 66 | encouraged to rename these macros something shorter, see 67 | examples in any other php module directory. 68 | */ 69 | 70 | #ifdef ZTS 71 | #define PDO_IBM_G(v) TSRMG(pdo_ibm_globals_id, zend_pdo_ibm_globals *, v) 72 | #else 73 | #define PDO_IBM_G(v) (pdo_ibm_globals.v) 74 | #endif 75 | 76 | #ifdef PASE /* i5/OS ease of use turn off/on */ 77 | ZEND_EXTERN_MODULE_GLOBALS(pdo_ibm) 78 | #endif /* PASE */ 79 | 80 | #endif /* PHP_PDO_IBM_H */ 81 | -------------------------------------------------------------------------------- /tests/README400.txt: -------------------------------------------------------------------------------- 1 | To run on IBM i: 2 | - fvt.inc - no *LIBL (no system naming) 3 | - fvt400.inc - enable *LIBL (system naming) 4 | 5 | 0) set-up libraries 6 | strsql 7 | create schema DB2 8 | create schema DB2LIBL 9 | 10 | 11 | 1) set env vars: 12 | PDOTEST_DSN=ibm:*LOCAL 13 | PDOTEST_USER=DB2 14 | PDOTEST_PASS=(password) 15 | PDOTEST_LIBL=DB2LIBL QTEMP 16 | PDOTEST_CURLIB=DB2LIBL 17 | 18 | 2) run tests 19 | > cd tests 20 | > pear run-tests *.phpt 21 | 22 | Note: 23 | - library DB2 is example user profile for non-*LIBL tests (SQL naming). 24 | - library DB2LIBL is example for *LIBL tests (system naming). 25 | - isolation PDO::I5_TXN_READ_UNCOMMITTED 'create schema lib' sets journaling required (default IBM i) 26 | - isolation PDO::I5_TXN_NO_COMMIT works with CRTLIB (no journaling) 27 | -------------------------------------------------------------------------------- /tests/TESTMATRIX: -------------------------------------------------------------------------------- 1 | Driver exposed function Purpose FVT's 2 | --------------------------------+-----------------------------------+-------------------- 3 | ibm_handle_closer | close connection | 4 | ibm_handle_preparer | prepare statement | fvt_031 5 | -> bind column | | pdo_015 6 | -> bind param | | pdo_021,pdo_024 7 | -> bind value | | pdo_028 8 | ibm_handle_doer | query / execute / #rows affected | fvt_002,fvt_010,fvt_011,fvt_012,fvt_014 9 | ibm_handle_begin | begin transaction | pdo_017 10 | ibm_handle_commit | commit transaction | 11 | -> with AUTOCOMMIT = 0 | | fvt_023 12 | -> with AUTOCOMMIT = 1,begin| | fvt_020 13 | -+- -+- 14 | ibm_handle_rollback | rollback transaction | 15 | -> with AUTOCOMMIT = 0 | | fvt_021 16 | -> with AUTOCOMMIT = 1,begin| | pdo_017 17 | -+- -+- 18 | ibm_handle_get_attribute | get attributes | fvt_020,fvt_021 19 | -> ATTR_AUTOCOMMIT | | 20 | -> ATTR_PREFETCH | (NO IMPL) | 21 | -> ATTR_TIMEOUT | (NO IMPL) | 22 | -> ATTR_SERVER_VERSION | (NO IMPL) <-- | 23 | -> ATTR_CLIENT_VERSION | | 24 | -> ATTR_SERVER_INFO | (NO IMPL) | 25 | -> ATTR_CONNECTION_STATUS | (NO IMPL) | 26 | -> ATTR_PERSISTENT | (NO IMPL) | 27 | -> ATTR_FETCH_CATALOG_NAMES | (NO IMPL) | 28 | -> ATTR_FETCH_TABLE_NAMES | (NO IMPL) | 29 | -+- -+- 30 | ibm_handle_set_attribute | set attributes (NO IMPL) | fvt_020,fvt_021 31 | -> ATTR_AUTOCOMMIT | | 32 | -> ATTR_PREFETCH | | 33 | -> ATTR_TIMEOUT | | 34 | -> ATTR_PERSISTENT | | 35 | -> ATTR_FETCH_CATALOG_NAMES | | 36 | -> ATTR_FETCH_TABLE_NAMES | | 37 | -+- -+- 38 | ibm_handle_factory | open connection | fvt_001,fvt_003,fvt_004 39 | ================================|===================================|================== 40 | ibm_stmt_dtor | close statement | 41 | ibm_stmt_executer | execute | fvt_031 42 | -> LOB as stream | | bug_34630 43 | -> LOB as string | | 44 | -> other simple datatypes | | pdo_021,pdo_024 45 | -+- -+- 46 | ibm_stmt_fetcher | fetch | 47 | -> Forward Only | | pdo_020,fvt_031 48 | -> FETCH_ORI_FIRST | | fvt_031 49 | -> FETCH_ORI_LAST | | fvt_031 50 | -> FETCH_ORI_NEXT | | fvt_031 51 | -> FETCH_ORI_PRIOR | | fvt_031 52 | -> FETCH_ORI_ABS | | fvt_013,fvt_031 53 | -> FETCH_ORI_REL | | fvt_031 54 | -+- -+- 55 | ibm_stmt_describer | fetch | 56 | ibm_stmt_get_col | fetch | pdo_012,pdo_013,pdo_019 57 | -> FETCH_BOUND | | pdo_016,pdo_016a 58 | -> FETCH_ASSOC | | pdo_001 59 | -> FETCH_NAMED | | 60 | -> FETCH_NUM | | pdo_002 61 | -> FETCH_BOTH | | pdo_003,fvt_030 62 | -> FETCH_OBJ | | pdo_004 63 | -> FETCH_COLUMN | | pdo_015 64 | -> FETCH_CLASS | | pdo_005 65 | -> FETCH_GROUP | | pdo_006 66 | -> FETCH_UNIQUE | | pdo_007,pdo_008 67 | -> FETCH_CLASSTYPE | | pdo_009,pdo_010 68 | -> FETCH_FUNC | | pdo_011 69 | -> FETCH_INTO | | pdo_025 70 | -> FETCH_LAZY | | pdo_027 71 | -+- -+- 72 | ibm_stmt_param_hook | bound parameters/columns | 73 | ibm_stmt_set_attribute | sets attributes | 74 | -> ATTR_CURSOR_NAME | | 75 | -> ATTR_CURSOR | | 76 | -+- -+- 77 | ibm_stmt_get_attribute | gets attributes | 78 | -> ATTR_CURSOR_NAME | | 79 | -> ATTR_CURSOR | | 80 | -+- -+- 81 | ibm_stmt_get_column_meta | column meta data | pdo_022(skip) 82 | ibm_stmt_next_rowset | next row set | 83 | 84 | -------------------------------------------------------------------------------- /tests/clob.dat: -------------------------------------------------------------------------------- 1 | this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. 2 | this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. 3 | this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. 4 | this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. 5 | this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. this iss clob data. 6 | -------------------------------------------------------------------------------- /tests/fvt.inc: -------------------------------------------------------------------------------- 1 | dsn = getenv('PDOTEST_DSN'); 14 | } 15 | else 16 | { 17 | $this->dsn = $_dsn; 18 | } 19 | 20 | if( $_user == null ) 21 | { 22 | $this->user = getenv('PDOTEST_USER'); 23 | } 24 | else 25 | { 26 | $this->user = $_user; 27 | } 28 | 29 | if( $_pass == null ) 30 | { 31 | $this->pass = getenv('PDOTEST_PASS'); 32 | } 33 | else 34 | { 35 | $this->pass = $_pass; 36 | } 37 | } 38 | 39 | public function connect($autoCommit=true, $useLibl=false, $useIsolation=false) 40 | { 41 | $options = array(PDO::ATTR_AUTOCOMMIT=>$autoCommit); 42 | $this->db = new PDO($this->dsn, $this->user, $this->pass, $options); 43 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 44 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); 45 | $this->db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 46 | return $this->db; 47 | } 48 | 49 | public function prepareDB() 50 | { 51 | try { 52 | /* Drop the test table, in case it exists */ 53 | $drop = 'DROP TABLE animals'; 54 | $result = $this->db->exec( $drop ); 55 | } catch( Exception $e ){} 56 | 57 | /* Create the test table */ 58 | $create = 'CREATE TABLE animals (id INTEGER, breed VARCHAR(32), name CHAR(16), weight DECIMAL(7,2))'; 59 | $result = $this->db->exec( $create ); 60 | 61 | /* Populate the test table */ 62 | $animals = array( 63 | array(0, 'cat', 'Pook', 3.2), 64 | array(1, 'dog', 'Peaches', 12.3), 65 | array(2, 'horse', 'Smarty', 350.0), 66 | array(3, 'gold fish', 'Bubbles', 0.1), 67 | array(4, 'budgerigar', 'Gizmo', 0.2), 68 | array(5, 'goat', 'Rickety Ride', 9.7), 69 | array(6, 'llama', 'Sweater', 150) 70 | ); 71 | 72 | $insert = 'INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)'; 73 | $stmt = $this->db->prepare( $insert ); 74 | if ($stmt) 75 | { 76 | foreach ($animals as $animal) 77 | { 78 | $result = $stmt->execute($animal); 79 | } 80 | } 81 | } 82 | 83 | public function allowViperXML() { 84 | $server_info = $this->db->getAttribute( PDO::ATTR_SERVER_INFO ); 85 | // DB2 LUW returns "DB2" (maybe?) 86 | // i5/OS DB2 returns "AS." or "QSQ" (AS400?) 87 | if(strncmp($server_info,"DB2",3)==0) { 88 | return True; 89 | } 90 | return False; 91 | } 92 | 93 | abstract public function runTest(); 94 | } 95 | 96 | ?> 97 | -------------------------------------------------------------------------------- /tests/fvt400.inc: -------------------------------------------------------------------------------- 1 | dsn = getenv('PDOTEST_DSN'); 16 | } 17 | else 18 | { 19 | $this->dsn = $_dsn; 20 | } 21 | 22 | if( $_user == null ) 23 | { 24 | $this->user = getenv('PDOTEST_USER'); 25 | } 26 | else 27 | { 28 | $this->user = $_user; 29 | } 30 | 31 | if( $_pass == null ) 32 | { 33 | $this->pass = getenv('PDOTEST_PASS'); 34 | } 35 | else 36 | { 37 | $this->pass = $_pass; 38 | } 39 | 40 | /* IBM i settings */ 41 | if( $_libl == null ) 42 | { 43 | $this->libl = getenv('PDOTEST_LIBL'); 44 | } 45 | else 46 | { 47 | $this->libl = $_libl; 48 | } 49 | 50 | if( $_curlib == null ) 51 | { 52 | $this->curlib = getenv('PDOTEST_CURLIB'); 53 | } 54 | else 55 | { 56 | $this->curlib = $_curlib; 57 | } 58 | } 59 | 60 | public function connect($autoCommit=true, $useLibl=false, $useIsolation=false) 61 | { 62 | $options = array(PDO::ATTR_AUTOCOMMIT=>$autoCommit); 63 | 64 | /* IBM i settings */ 65 | if ($useLibl) { 66 | $options[PDO::I5_ATTR_DBC_SYS_NAMING] = true; 67 | if ($this->libl) { 68 | $options[PDO::I5_ATTR_DBC_LIBL] = $this->libl; 69 | } 70 | if ($this->curlib) { 71 | $options[PDO::I5_ATTR_DBC_CURLIB] = $this->curlib; 72 | } 73 | /* Isolation modes 74 | PDO::I5_ATTR_COMMIT 75 | PDO::I5_TXN_NO_COMMIT 76 | PDO::I5_TXN_READ_UNCOMMITTED 77 | PDO::I5_TXN_READ_COMMITTED 78 | PDO::I5_TXN_REPEATABLE_READ 79 | PDO::I5_TXN_SERIALIZABLE 80 | */ 81 | if ($useIsolation !== false) { 82 | $options[PDO::I5_ATTR_COMMIT] = $useIsolation; 83 | } 84 | } 85 | $this->db = new PDO($this->dsn, $this->user, $this->pass, $options); 86 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 87 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); 88 | $this->db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 89 | return $this->db; 90 | } 91 | 92 | abstract public function runTest(); 93 | } 94 | 95 | ?> 96 | -------------------------------------------------------------------------------- /tests/fvt_001_DbConn.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Connect to database 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | print "Connection succeeded.\n"; 15 | } 16 | } 17 | 18 | $testcase = new Test(); 19 | $testcase->runTest(); 20 | ?> 21 | --EXPECT-- 22 | Attempting to connect.. 23 | Connection succeeded. 24 | -------------------------------------------------------------------------------- /tests/fvt_002_CountRowsAffected.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Count number of affected rows 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | $sql = 'UPDATE animals SET id = 9'; 15 | $res = $this->db->exec($sql); 16 | print "Number of affected rows: " . $res; 17 | } 18 | } 19 | 20 | $testcase = new Test(); 21 | $testcase->runTest(); 22 | ?> 23 | --EXPECT-- 24 | Number of affected rows: 7 25 | -------------------------------------------------------------------------------- /tests/fvt_003_ConnWrongUserPwd_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Connection attempt with wrong user/pwd 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 20 | print "Connection succeeded.\n"; 21 | }catch( PDOException $e ){ 22 | print "Connection failed.\n"; 23 | } 24 | } 25 | } 26 | 27 | $testcase = new Test(); 28 | $testcase->runTest(); 29 | ?> 30 | --EXPECT-- 31 | Attempting to connect.. 32 | Connection failed. 33 | -------------------------------------------------------------------------------- /tests/fvt_004_ConnWrongUserPwd_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Connection attempt with wrong user/pwd 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | dsn .= "UID=not_a_user;PWD=invalid_pass"; 14 | $this->user = ""; 15 | $this->pass = ""; 16 | } 17 | 18 | public function runTest() 19 | { 20 | print "Attempting to connect..\n"; 21 | try{ 22 | $this->connect(); 23 | print "Connection succeeded.\n"; 24 | }catch( PDOException $e ){ 25 | print "Connection failed.\n"; 26 | } 27 | } 28 | } 29 | 30 | $testcase = new Test(); 31 | $testcase->runTest(); 32 | ?> 33 | --EXPECT-- 34 | Attempting to connect.. 35 | Connection failed. 36 | -------------------------------------------------------------------------------- /tests/fvt_005_DrvVersion.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Get the driver version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | $result = $this->db->getAttribute(PDO::ATTR_CLIENT_VERSION); 15 | echo "Version is: $result\n"; 16 | if ($result = NULL) { 17 | echo "Result is NULL...bad\n"; 18 | } 19 | } 20 | } 21 | 22 | $testcase = new Test(); 23 | $testcase->runTest(); 24 | ?> 25 | --EXPECTF-- 26 | Version is: %d.%d.%d 27 | -------------------------------------------------------------------------------- /tests/fvt_006_ErrConditions_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | try { 14 | $stmt1 = $this->db->prepare("SELECT id FROM animals WHERE colnotexist = 1 " ) ; 15 | print("Error Code: ".$this->db->errorCode()."\n"); 16 | print_r($this->db->errorInfo()); 17 | print("\n"); 18 | $stmt2 = $this->db->prepare("SELECT id FROM animals WHERE id = 1 " ) ; 19 | print("Error Code: ".$this->db->errorCode()."\n"); 20 | print_r($this->db->errorInfo()); 21 | print("\n"); 22 | } catch (PDOException $pe) { 23 | print("Error Code: ".$this->db->errorCode()."\n"); 24 | print_r($this->db->errorInfo()); 25 | print("\n"); 26 | $stmt2 = $this->db->prepare("SELECT id FROM animals WHERE id = 1 " ) ; 27 | print("Error Code: ".$this->db->errorCode()."\n"); 28 | print_r($this->db->errorInfo()); 29 | print("\n"); 30 | } 31 | } 32 | } 33 | 34 | $testcase = new Test(); 35 | $testcase->runTest(); 36 | ?> 37 | --EXPECTREGEX-- 38 | (Error Code: 42S22 39 | Array 40 | \( 41 | \[0\] => 42S22 42 | \[1\] => -206 43 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] SQL0206N "COLNOTEXIST" is not valid in the context where it is used\. SQLSTATE=42703 44 | \(.+\) 45 | \) 46 | 47 | Error Code: 00000 48 | Array 49 | \( 50 | \[0\] => 00000 51 | \[1\] => 52 | \[2\] => 53 | \)|Error Code: IX000 54 | Array 55 | \( 56 | \[0\] => IX000 57 | \[1\] => -217 58 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] Column \(colnotexist\) not found in any table in the query \(or SLV is undefined\)\. \(.+ 59 | \) 60 | 61 | Error Code: 00000 62 | Array 63 | \( 64 | \[0\] => 00000 65 | \[1\] => 66 | \[2\] => 67 | \)) 68 | 69 | -------------------------------------------------------------------------------- /tests/fvt_006_V5V6_ErrConditions_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | try { 14 | $stmt1 = $this->db->prepare("SELECT id FROM animals WHERE colnotexist = 1 " ) ; 15 | print("Error Code 1: ".$this->db->errorCode()."\n"); 16 | print_r($this->db->errorInfo()); 17 | print("\n"); 18 | $stmt2 = $this->db->prepare("SELECT id FROM animals WHERE id = 1 " ) ; 19 | print("Error Code 2: ".$this->db->errorCode()."\n"); 20 | print_r($this->db->errorInfo()); 21 | print("\n"); 22 | } catch (PDOException $pe) { 23 | print("Error Code 3: ".$this->db->errorCode()."\n"); 24 | print_r($this->db->errorInfo()); 25 | print("\n"); 26 | $stmt2 = $this->db->prepare("SELECT id FROM animals WHERE id = 1 " ) ; 27 | print("Error Code 4: ".$this->db->errorCode()."\n"); 28 | // print_r($this->db->errorInfo()); 29 | print("\n"); 30 | } 31 | } 32 | } 33 | 34 | $testcase = new Test(); 35 | $testcase->runTest(); 36 | ?> 37 | --EXPECTF-- 38 | Error Code 3: 42703 39 | Array 40 | ( 41 | [0] => 42703 42 | [1] => -206 43 | [2] => Column or global variable COLNOTEXIST not found. (SQLPrepare[-206] at %s 44 | ) 45 | 46 | Error Code 4: 00000 47 | 48 | -------------------------------------------------------------------------------- /tests/fvt_007_ErrConditions_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | $sql = "DROP table testFloat"; 16 | $stmt = $this->db->exec($sql); 17 | } catch( Exception $e ){} 18 | 19 | $sql = "CREATE table testFloat (data FLOAT)"; 20 | $stmt = $this->db->exec($sql); 21 | 22 | $sql = "INSERT INTO testFloat (data) values (0.058290369626395423)"; 23 | $stmt = $this->db->exec($sql); 24 | 25 | $sql = "SELECT data FROM testFloat"; 26 | $stmt = $this->db->query($sql); 27 | 28 | while ( $row = $stmt->fetch() ) { 29 | print_r($row); 30 | } 31 | } 32 | } 33 | 34 | $testcase = new Test(); 35 | $testcase->runTest(); 36 | ?> 37 | --EXPECT-- 38 | Array 39 | ( 40 | [DATA] => 5.82903696263954E-002 41 | [0] => 5.82903696263954E-002 42 | ) 43 | 44 | -------------------------------------------------------------------------------- /tests/fvt_007_V5V6_ErrConditions_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | $sql = "DROP table testFloat"; 16 | $stmt = $this->db->exec($sql); 17 | } catch( Exception $e ){} 18 | 19 | $sql = "CREATE table testFloat (data FLOAT)"; 20 | $stmt = $this->db->exec($sql); 21 | 22 | $sql = "INSERT INTO testFloat (data) values (0.058290369626395423)"; 23 | $stmt = $this->db->exec($sql); 24 | 25 | $sql = "SELECT data FROM testFloat"; 26 | $stmt = $this->db->query($sql); 27 | 28 | while ( $row = $stmt->fetch() ) { 29 | print_r($row); 30 | } 31 | } 32 | } 33 | 34 | $testcase = new Test(); 35 | $testcase->runTest(); 36 | ?> 37 | --EXPECT-- 38 | Array 39 | ( 40 | [DATA] => 0.0582904 41 | [0] => 0.0582904 42 | ) 43 | -------------------------------------------------------------------------------- /tests/fvt_008_ErrNonExistentTables.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions through non-existent tables 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $sql = "CREATE TABLE testError(" . 14 | "id INTEGER," . 15 | "data VARCHAR(50)," . 16 | "attachment VARCHAR(50)," . 17 | "about VARCHAR(50))"; 18 | 19 | try { 20 | $stmt = $this->db->prepare($sql); 21 | $stmt->execute(); 22 | } catch (PDOException $pe) { 23 | echo $pe->getMessage(); 24 | } 25 | 26 | $this->db->exec("DROP TABLE testError"); 27 | $sql = "SELECT id FROM FINAL TABLE(INSERT INTO testError(data,about,attachment)values(?,?,?))"; 28 | 29 | try { 30 | $stmt = $this->db->prepare($sql); 31 | $stmt->execute(); 32 | } catch (PDOException $pe) { 33 | echo "Error code:\n"; 34 | print_r($this->db->errorCode()); 35 | echo "\n"; 36 | echo "Error info:\n"; 37 | print_r($this->db->errorInfo()); 38 | } 39 | } 40 | } 41 | 42 | $testcase = new Test(); 43 | $testcase->runTest(); 44 | ?> 45 | --EXPECTREGEX-- 46 | (Error code: 47 | 42S02 48 | Error info: 49 | Array 50 | \( 51 | \[0\] => 42S02 52 | \[1\] => -204 53 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] SQL0204N ".+" is an undefined name\. SQLSTATE=42704 54 | \(.+\[-204\] at .+\) 55 | \))|(Error code: 56 | 42S22 57 | Error info: 58 | Array 59 | \( 60 | \[0\] => 42S22 61 | \[1\] => -206 62 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] The specified table \(informix\.testerror\) is not in the database\. \(.+\[-206\] at .+\) 63 | \)) 64 | 65 | -------------------------------------------------------------------------------- /tests/fvt_008_V5_ErrNonExistentTables.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions through non-existent tables 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $sql = "CREATE TABLE testError(" . 14 | "id INTEGER," . 15 | "data VARCHAR(50)," . 16 | "attachment VARCHAR(50)," . 17 | "about VARCHAR(50))"; 18 | 19 | try { 20 | $stmt = $this->db->prepare($sql); 21 | $stmt->execute(); 22 | } catch (PDOException $pe) { 23 | echo $pe->getMessage(); 24 | } 25 | 26 | $this->db->exec("DROP TABLE testError"); 27 | $sql = "SELECT id FROM FINAL TABLE(INSERT INTO testError(data,about,attachment)values(?,?,?))"; 28 | 29 | try { 30 | $stmt = $this->db->prepare($sql); 31 | $stmt->execute(); 32 | } catch (PDOException $pe) { 33 | echo "Error code:\n"; 34 | print_r($this->db->errorCode()); 35 | echo "\n"; 36 | echo "Error info:\n"; 37 | print_r($this->db->errorInfo()); 38 | } 39 | } 40 | } 41 | 42 | $testcase = new Test(); 43 | $testcase->runTest(); 44 | ?> 45 | --EXPECTF-- 46 | Error code: 47 | 42601 48 | Error info: 49 | Array 50 | ( 51 | [0] => 42601 52 | [1] => -199 53 | [2] => Keyword TABLE not expected. %s (SQLPrepare[-199] %s 54 | ) 55 | -------------------------------------------------------------------------------- /tests/fvt_008_V6_ErrNonExistentTables.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions through non-existent tables 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $sql = "CREATE TABLE testError(" . 14 | "id INTEGER," . 15 | "data VARCHAR(50)," . 16 | "attachment VARCHAR(50)," . 17 | "about VARCHAR(50))"; 18 | 19 | try { 20 | $stmt = $this->db->prepare($sql); 21 | $stmt->execute(); 22 | } catch (PDOException $pe) { 23 | echo $pe->getMessage(); 24 | } 25 | 26 | $this->db->exec("DROP TABLE testError"); 27 | $sql = "SELECT id FROM FINAL TABLE(INSERT INTO testError(data,about,attachment)values(?,?,?))"; 28 | 29 | try { 30 | $stmt = $this->db->prepare($sql); 31 | $stmt->execute(); 32 | } catch (PDOException $pe) { 33 | echo "Error code:\n"; 34 | print_r($this->db->errorCode()); 35 | echo "\n"; 36 | echo "Error info:\n"; 37 | print_r($this->db->errorInfo()); 38 | } 39 | } 40 | } 41 | 42 | $testcase = new Test(); 43 | $testcase->runTest(); 44 | ?> 45 | --EXPECTF-- 46 | Error code: 47 | 42704 48 | Error info: 49 | Array 50 | ( 51 | [0] => 42704 52 | [1] => -204 53 | [2] => TESTERROR in DB2 type *FILE not found. (SQLPrepare[-204] %s 54 | ) 55 | 56 | -------------------------------------------------------------------------------- /tests/fvt_009_ErrFaultySQL.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions through faulty SQL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $parmno = "200010"; 14 | try { 15 | $stmt = $this->db->prepare("SELECT empno, lastname, bonus, FROM employee WHERE empno > ?"); 16 | $stmt->execute( array( $parmno )); 17 | while ($row = $stmt->fetch()) { 18 | print_r($row); 19 | } 20 | } catch (PDOException $pe) { 21 | echo "Error code:\n"; 22 | print_r($this->db->errorCode()); 23 | echo "\n"; 24 | echo "Error info:\n"; 25 | print_r($this->db->errorInfo()); 26 | } 27 | } 28 | } 29 | 30 | $testcase = new Test(); 31 | $testcase->runTest(); 32 | ?> 33 | --EXPECTREGEX-- 34 | (Error code: 35 | 42601 36 | Error info: 37 | Array 38 | \( 39 | \[0\] => 42601 40 | \[1\] => -104 41 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] SQL0104N An unexpected token "employee" was found following "astname, bonus, FROM"\. Expected tokens may include: "FROM"\. SQLSTATE=42601 42 | \(.+\[-104\] at .+\) 43 | \)|Error code: 44 | 42000 45 | Error info: 46 | Array 47 | \( 48 | \[0\] => 42000 49 | \[1\] => -201 50 | \[2\] => \[IBM\]\[CLI Driver\]\[.+\] A syntax error has occurred\. \(.+\[-201\] at .+\) 51 | \)) 52 | -------------------------------------------------------------------------------- /tests/fvt_009_V5V6_ErrFaultySQL.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test error conditions through faulty SQL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $parmno = "200010"; 14 | try { 15 | $stmt = $this->db->prepare("SELECT empno, lastname, bonus, FROM employee WHERE empno > ?"); 16 | $stmt->execute( array( $parmno )); 17 | while ($row = $stmt->fetch()) { 18 | print_r($row); 19 | } 20 | } catch (PDOException $pe) { 21 | echo "Error code:\n"; 22 | print_r($this->db->errorCode()); 23 | echo "\n"; 24 | echo "Error info:\n"; 25 | print_r($this->db->errorInfo()); 26 | } 27 | } 28 | } 29 | 30 | $testcase = new Test(); 31 | $testcase->runTest(); 32 | ?> 33 | --EXPECTF-- 34 | Error code: 35 | 42601 36 | Error info: 37 | Array 38 | ( 39 | [0] => 42601 40 | [1] => -199 41 | [2] => Keyword WHERE not expected. %s (SQLPrepare[-199] %s 42 | ) 43 | -------------------------------------------------------------------------------- /tests/fvt_010_UpdateRowCount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Count number of affected rows - Update 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->query( "UPDATE animals SET name = 'flyweight' WHERE weight < 10.0" ); 16 | echo "Number of affected rows: " . $stmt->rowCount(); 17 | } 18 | } 19 | 20 | $testcase = new Test(); 21 | $testcase->runTest(); 22 | ?> 23 | --EXPECT-- 24 | Number of affected rows: 4 25 | -------------------------------------------------------------------------------- /tests/fvt_011_DeleteRowCount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Count number of affected rows - Delete 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->query( "DELETE FROM animals WHERE weight > 10.0" ); 16 | echo "Number of affected rows: " . $stmt->rowCount(); 17 | } 18 | } 19 | 20 | $testcase = new Test(); 21 | $testcase->runTest(); 22 | ?> 23 | --EXPECT-- 24 | Number of affected rows: 3 25 | -------------------------------------------------------------------------------- /tests/fvt_012_SelectRowCount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Count number of affected rows - Select 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->query( "SELECT name FROM animals WHERE weight < 10.0" ); 16 | print $stmt->rowCount() . "\n"; 17 | echo "Number of rows: " . count( $stmt->fetchAll() ) . "\n"; 18 | } 19 | } 20 | 21 | $testcase = new Test(); 22 | $testcase->runTest(); 23 | ?> 24 | --EXPECT-- 25 | -1 26 | Number of rows: 4 27 | 28 | -------------------------------------------------------------------------------- /tests/fvt_013_ScrollableCursorNegativeRow.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Scrollable cursor; retrieve negative row 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->prepare( "SELECT * FROM animals" , array(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL) ); 16 | $stmt->execute(); 17 | var_dump( $stmt->fetchAll() ); 18 | $stmt->execute(); 19 | try{ 20 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_ABS , -1 ); 21 | var_dump( $row ); 22 | }catch( PDOException $e ){ 23 | $info = $stmt->errorInfo(); 24 | if( $info[1] == -99999 ) 25 | { 26 | print "Cannot retrieve negative row\n"; 27 | } 28 | else 29 | { 30 | print $e . "\n"; 31 | } 32 | } 33 | } 34 | } 35 | 36 | $testcase = new Test(); 37 | $testcase->runTest(); 38 | ?> 39 | --EXPECT-- 40 | array(7) { 41 | [0]=> 42 | array(8) { 43 | ["ID"]=> 44 | string(1) "0" 45 | [0]=> 46 | string(1) "0" 47 | ["BREED"]=> 48 | string(3) "cat" 49 | [1]=> 50 | string(3) "cat" 51 | ["NAME"]=> 52 | string(16) "Pook " 53 | [2]=> 54 | string(16) "Pook " 55 | ["WEIGHT"]=> 56 | string(4) "3.20" 57 | [3]=> 58 | string(4) "3.20" 59 | } 60 | [1]=> 61 | array(8) { 62 | ["ID"]=> 63 | string(1) "1" 64 | [0]=> 65 | string(1) "1" 66 | ["BREED"]=> 67 | string(3) "dog" 68 | [1]=> 69 | string(3) "dog" 70 | ["NAME"]=> 71 | string(16) "Peaches " 72 | [2]=> 73 | string(16) "Peaches " 74 | ["WEIGHT"]=> 75 | string(5) "12.30" 76 | [3]=> 77 | string(5) "12.30" 78 | } 79 | [2]=> 80 | array(8) { 81 | ["ID"]=> 82 | string(1) "2" 83 | [0]=> 84 | string(1) "2" 85 | ["BREED"]=> 86 | string(5) "horse" 87 | [1]=> 88 | string(5) "horse" 89 | ["NAME"]=> 90 | string(16) "Smarty " 91 | [2]=> 92 | string(16) "Smarty " 93 | ["WEIGHT"]=> 94 | string(6) "350.00" 95 | [3]=> 96 | string(6) "350.00" 97 | } 98 | [3]=> 99 | array(8) { 100 | ["ID"]=> 101 | string(1) "3" 102 | [0]=> 103 | string(1) "3" 104 | ["BREED"]=> 105 | string(9) "gold fish" 106 | [1]=> 107 | string(9) "gold fish" 108 | ["NAME"]=> 109 | string(16) "Bubbles " 110 | [2]=> 111 | string(16) "Bubbles " 112 | ["WEIGHT"]=> 113 | string(4) "0.10" 114 | [3]=> 115 | string(4) "0.10" 116 | } 117 | [4]=> 118 | array(8) { 119 | ["ID"]=> 120 | string(1) "4" 121 | [0]=> 122 | string(1) "4" 123 | ["BREED"]=> 124 | string(10) "budgerigar" 125 | [1]=> 126 | string(10) "budgerigar" 127 | ["NAME"]=> 128 | string(16) "Gizmo " 129 | [2]=> 130 | string(16) "Gizmo " 131 | ["WEIGHT"]=> 132 | string(4) "0.20" 133 | [3]=> 134 | string(4) "0.20" 135 | } 136 | [5]=> 137 | array(8) { 138 | ["ID"]=> 139 | string(1) "5" 140 | [0]=> 141 | string(1) "5" 142 | ["BREED"]=> 143 | string(4) "goat" 144 | [1]=> 145 | string(4) "goat" 146 | ["NAME"]=> 147 | string(16) "Rickety Ride " 148 | [2]=> 149 | string(16) "Rickety Ride " 150 | ["WEIGHT"]=> 151 | string(4) "9.70" 152 | [3]=> 153 | string(4) "9.70" 154 | } 155 | [6]=> 156 | array(8) { 157 | ["ID"]=> 158 | string(1) "6" 159 | [0]=> 160 | string(1) "6" 161 | ["BREED"]=> 162 | string(5) "llama" 163 | [1]=> 164 | string(5) "llama" 165 | ["NAME"]=> 166 | string(16) "Sweater " 167 | [2]=> 168 | string(16) "Sweater " 169 | ["WEIGHT"]=> 170 | string(6) "150.00" 171 | [3]=> 172 | string(6) "150.00" 173 | } 174 | } 175 | Cannot retrieve negative row 176 | -------------------------------------------------------------------------------- /tests/fvt_013_V5V6_ScrollableCursorNegativeRow.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Scrollable cursor; retrieve negative row 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->prepare( "SELECT * FROM animals" , array(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL) ); 16 | $stmt->execute(); 17 | var_dump( $stmt->fetchAll() ); 18 | $stmt->execute(); 19 | try{ 20 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_ABS , -1 ); 21 | var_dump( $row ); 22 | }catch( PDOException $e ){ 23 | $info = $stmt->errorInfo(); 24 | if( $info[1] == -99999 || $info[1] == -225 ) 25 | { 26 | print "Cannot retrieve negative row\n"; 27 | } 28 | else 29 | { 30 | // print $e . "\n"; 31 | print $info[1]; 32 | } 33 | } 34 | } 35 | } 36 | 37 | $testcase = new Test(); 38 | $testcase->runTest(); 39 | ?> 40 | --EXPECTF-- 41 | array(7) { 42 | [0]=> 43 | array(8) { 44 | ["ID"]=> 45 | string(1) "0" 46 | [0]=> 47 | string(1) "0" 48 | ["BREED"]=> 49 | string(3) "cat" 50 | [1]=> 51 | string(3) "cat" 52 | ["NAME"]=> 53 | string(16) "Pook " 54 | [2]=> 55 | string(16) "Pook " 56 | ["WEIGHT"]=> 57 | string(4) "3.20" 58 | [3]=> 59 | string(4) "3.20" 60 | } 61 | [1]=> 62 | array(8) { 63 | ["ID"]=> 64 | string(1) "1" 65 | [0]=> 66 | string(1) "1" 67 | ["BREED"]=> 68 | string(3) "dog" 69 | [1]=> 70 | string(3) "dog" 71 | ["NAME"]=> 72 | string(16) "Peaches " 73 | [2]=> 74 | string(16) "Peaches " 75 | ["WEIGHT"]=> 76 | string(5) "12.30" 77 | [3]=> 78 | string(5) "12.30" 79 | } 80 | [2]=> 81 | array(8) { 82 | ["ID"]=> 83 | string(1) "2" 84 | [0]=> 85 | string(1) "2" 86 | ["BREED"]=> 87 | string(5) "horse" 88 | [1]=> 89 | string(5) "horse" 90 | ["NAME"]=> 91 | string(16) "Smarty " 92 | [2]=> 93 | string(16) "Smarty " 94 | ["WEIGHT"]=> 95 | string(6) "350.00" 96 | [3]=> 97 | string(6) "350.00" 98 | } 99 | [3]=> 100 | array(8) { 101 | ["ID"]=> 102 | string(1) "3" 103 | [0]=> 104 | string(1) "3" 105 | ["BREED"]=> 106 | string(9) "gold fish" 107 | [1]=> 108 | string(9) "gold fish" 109 | ["NAME"]=> 110 | string(16) "Bubbles " 111 | [2]=> 112 | string(16) "Bubbles " 113 | ["WEIGHT"]=> 114 | string(3) ".10" 115 | [3]=> 116 | string(3) ".10" 117 | } 118 | [4]=> 119 | array(8) { 120 | ["ID"]=> 121 | string(1) "4" 122 | [0]=> 123 | string(1) "4" 124 | ["BREED"]=> 125 | string(10) "budgerigar" 126 | [1]=> 127 | string(10) "budgerigar" 128 | ["NAME"]=> 129 | string(16) "Gizmo " 130 | [2]=> 131 | string(16) "Gizmo " 132 | ["WEIGHT"]=> 133 | string(3) ".20" 134 | [3]=> 135 | string(3) ".20" 136 | } 137 | [5]=> 138 | array(8) { 139 | ["ID"]=> 140 | string(1) "5" 141 | [0]=> 142 | string(1) "5" 143 | ["BREED"]=> 144 | string(4) "goat" 145 | [1]=> 146 | string(4) "goat" 147 | ["NAME"]=> 148 | string(16) "Rickety Ride " 149 | [2]=> 150 | string(16) "Rickety Ride " 151 | ["WEIGHT"]=> 152 | string(4) "9.70" 153 | [3]=> 154 | string(4) "9.70" 155 | } 156 | [6]=> 157 | array(8) { 158 | ["ID"]=> 159 | string(1) "6" 160 | [0]=> 161 | string(1) "6" 162 | ["BREED"]=> 163 | string(5) "llama" 164 | [1]=> 165 | string(5) "llama" 166 | ["NAME"]=> 167 | string(16) "Sweater " 168 | [2]=> 169 | string(16) "Sweater " 170 | ["WEIGHT"]=> 171 | string(6) "150.00" 172 | [3]=> 173 | string(6) "150.00" 174 | } 175 | } 176 | Cannot retrieve negative row 177 | -------------------------------------------------------------------------------- /tests/fvt_014_InsertDeleteRowCount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: rowCount - insert, delete 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->query( "INSERT INTO animals VALUES ( 7 , 'monkey' , 'Evil Monkey' , 10.0 )" ); 16 | print "Num rows affected (Ins): " . $stmt->rowCount() . ", Column count: " . $stmt->columnCount() . "\n"; 17 | $stmt = null; 18 | 19 | $stmt = $this->db->query( "DELETE FROM animals WHERE id=7" ); 20 | print "Num rows affected (Del): " . $stmt->rowCount() . ", Column count: " . $stmt->columnCount() . "\n"; 21 | $stmt = null; 22 | } 23 | } 24 | 25 | $testcase = new Test(); 26 | $testcase->runTest(); 27 | ?> 28 | --EXPECT-- 29 | Num rows affected (Ins): 1, Column count: 0 30 | Num rows affected (Del): 1, Column count: 0 31 | -------------------------------------------------------------------------------- /tests/fvt_016_InsertIntegerBindingString.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Insert integer by binding an empty string, a NULL, and an integer string to column 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $null = NULL; 25 | $empty_string0 = ""; 26 | $empty_string1 = ""; 27 | $int_string = "0"; 28 | 29 | $sql = "INSERT INTO animals VALUES ( :mynull0 ) "; 30 | $stmt = $this->db->prepare ( $sql ); 31 | $stmt->bindParam ( ":mynull0" , $null ); 32 | $stmt->execute(); 33 | $stmt = $this->db->query( "SELECT * FROM animals" ); 34 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 35 | $rows = $res[0]; 36 | print "Null contents: $rows\n"; 37 | 38 | $delete = 'DELETE FROM animals'; 39 | $result = $this->db->exec( $delete ); 40 | 41 | $sql = "INSERT INTO animals VALUES ( :mynull1 ) "; 42 | $stmt = $this->db->prepare ( $sql ); 43 | $stmt->bindParam ( ":mynull1" , $null, PDO::PARAM_INT ); 44 | $stmt->execute(); 45 | $stmt = $this->db->query( "SELECT * FROM animals" ); 46 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 47 | $rows = $res[0]; 48 | print "Null contents with int specified: $rows\n"; 49 | 50 | $delete = 'DELETE FROM animals'; 51 | $result = $this->db->exec( $delete ); 52 | 53 | $sql = "INSERT INTO animals VALUES ( :myemptystring0 ) "; 54 | $stmt = $this->db->prepare ( $sql ); 55 | $stmt->bindParam ( ":myemptystring0" , $empty_string0); 56 | $stmt->execute(); 57 | $stmt = $this->db->query( "SELECT * FROM animals" ); 58 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 59 | $rows = $res[0]; 60 | print "Empty string contents: $rows\n"; 61 | 62 | $delete = 'DELETE FROM animals'; 63 | $result = $this->db->exec( $delete ); 64 | 65 | $sql = "INSERT INTO animals VALUES ( :myemptystring1 ) "; 66 | $stmt = $this->db->prepare ( $sql ); 67 | $stmt->bindParam ( ":myemptystring1" , $empty_string1, PDO::PARAM_INT ); 68 | $stmt->execute(); 69 | $stmt = $this->db->query( "SELECT * FROM animals" ); 70 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 71 | $rows = $res[0]; 72 | print "Empty string contents with int specified: $rows\n"; 73 | 74 | $delete = 'DELETE FROM animals'; 75 | $result = $this->db->exec( $delete ); 76 | 77 | $sql = "INSERT INTO animals VALUES ( :myintstring0 ) "; 78 | $stmt = $this->db->prepare ( $sql ); 79 | $stmt->bindParam ( ":myintstring0" , $int_string ); 80 | $stmt->execute(); 81 | $stmt = $this->db->query( "SELECT * FROM animals" ); 82 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 83 | $rows = $res[0]; 84 | print "Int string contents: $rows\n"; 85 | 86 | $delete = 'DELETE FROM animals'; 87 | $result = $this->db->exec( $delete ); 88 | 89 | $sql = "INSERT INTO animals VALUES ( :myintstring1 ) "; 90 | $stmt = $this->db->prepare ( $sql ); 91 | $stmt->bindParam ( ":myintstring1" , $int_string, PDO::PARAM_INT ); 92 | $stmt->execute(); 93 | $stmt = $this->db->query( "SELECT * FROM animals" ); 94 | $res = $stmt->fetch( PDO::FETCH_BOTH ); 95 | $rows = $res[0]; 96 | print "Int string contents with int specified: $rows\n"; 97 | 98 | print "done\n"; 99 | } 100 | } 101 | 102 | $testcase = new Test(); 103 | $testcase->runTest(); 104 | ?> 105 | --EXPECT-- 106 | Null contents: 107 | Null contents with int specified: 108 | Empty string contents: 109 | Empty string contents with int specified: 110 | Int string contents: 0 111 | Int string contents with int specified: 0 112 | done 113 | 114 | -------------------------------------------------------------------------------- /tests/fvt_017_InsertRetrieveLargeClobFile_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Insert and retrieve a very large file. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER, my_blob blob)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $fp = fopen( dirname(__FILE__) . "/large_blob.dat" , "rb" ); 25 | $stmt = $this->db->prepare('insert into animals (id,my_blob) values (:id,:my_blob)'); 26 | print "inserting from file stream\n"; 27 | $stmt->bindValue( ':id' , 0 ); 28 | $stmt->bindParam( ':my_blob' , $fp , PDO::PARAM_LOB ); 29 | $stmt->execute(); 30 | print "succesful\n"; 31 | 32 | print "runnign query\n"; 33 | $stmt = $this->db->prepare( 'select id,my_blob from animals' ); 34 | 35 | $stmt->bindColumn( 'ID' , $id ); 36 | $stmt->bindColumn( 'MY_BLOB' , $blob , PDO::PARAM_LOB ); 37 | $rs = $stmt->execute(); 38 | while ($stmt->fetch(PDO::FETCH_BOUND)) { 39 | var_dump( $id ); 40 | var_dump( $blob ); 41 | $fp = fopen( dirname(__FILE__) . "/large_blob_out.dat" , "wb" ); 42 | echo "datalength: " . fwrite($fp, $blob) . "\n"; 43 | system( "diff large_blob.dat large_blob_out.dat" ); 44 | } 45 | print "done\n"; 46 | } 47 | } 48 | 49 | $testcase = new Test(); 50 | $testcase->runTest(); 51 | ?> 52 | --EXPECTF-- 53 | inserting from file stream 54 | succesful 55 | runnign query 56 | string(1) "0" 57 | string(4966) %a 58 | done 59 | -------------------------------------------------------------------------------- /tests/fvt_017_V5V6_InsertRetrieveLargeClobFile_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Insert and retrieve a very large file. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER, my_blob blob)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $fp = fopen( dirname(__FILE__) . "/large_blob.dat" , "rb" ); 25 | //$fp = fopen("large_blob.dat" , "rb" ); // Test Tool 26 | $stmt = $this->db->prepare('insert into animals (id,my_blob) values (:id,:my_blob)'); 27 | print "inserting from file stream\n"; 28 | $stmt->bindValue( ':id' , 0 ); 29 | $stmt->bindParam( ':my_blob' , $fp , PDO::PARAM_LOB ); 30 | $stmt->execute(); 31 | print "succesful\n"; 32 | 33 | print "runnign query\n"; 34 | $stmt = $this->db->prepare( 'select id,my_blob from animals' ); 35 | 36 | 37 | $rs = $stmt->execute(); // Must execute before bind by column name 38 | $stmt->bindColumn( 'ID' , $id ); 39 | $stmt->bindColumn( 'MY_BLOB' , $blob , PDO::PARAM_LOB ); 40 | while ($stmt->fetch(PDO::FETCH_BOUND)){ 41 | var_dump( $id ); 42 | //var_dump( $blob ); 43 | $fp = fopen( dirname(__FILE__) . "/large_blob_out.dat" , "wb" ); 44 | //$fp = fopen("large_blob_out.dat" , "wb" ); // Test Tool 45 | //echo "datalength: " . stream_copy_to_stream( $blob , $fp ) . "\n"; 46 | echo "datalength: " . fwrite($fp, $blob) . "\n"; 47 | system( "diff " . dirname(__FILE__) . "/large_blob.dat " . dirname(__FILE__) . "/large_blob_out.dat" ); 48 | } 49 | print "done\n"; 50 | } 51 | } 52 | 53 | $testcase = new Test(); 54 | $testcase->runTest(); 55 | ?> 56 | --EXPECTF-- 57 | inserting from file stream 58 | succesful 59 | runnign query 60 | string(1) "0" 61 | datalength: 4966 62 | done 63 | -------------------------------------------------------------------------------- /tests/fvt_017b_InsertRetrieveLargeClobFile_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Insert and retrieve a very large clob file. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER, my_clob clob)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $fp = fopen( dirname(__FILE__) . "/large_clob.dat" , "r" ); 25 | $stmt = $this->db->prepare('insert into animals (id,my_clob) values (:id,:my_clob)'); 26 | print "inserting from file stream\n"; 27 | $stmt->bindValue( ':id' , 0 ); 28 | $stmt->bindParam( ':my_clob' , $fp , PDO::PARAM_LOB ); 29 | $stmt->execute(); 30 | print "succesful\n"; 31 | 32 | print "runnign query\n"; 33 | $stmt = $this->db->prepare( 'select id,my_clob from animals' ); 34 | 35 | $stmt->bindColumn( 'ID' , $id ); 36 | $stmt->bindColumn( 'MY_CLOB' , $clob , PDO::PARAM_LOB ); 37 | $rs = $stmt->execute(); 38 | while ($stmt->fetch(PDO::FETCH_BOUND)) { 39 | var_dump( $id ); 40 | var_dump( $clob ); 41 | $fp = fopen( dirname(__FILE__) . "/large_clob_out.dat" , "w" ); 42 | fwrite($fp , $clob); 43 | system( "diff large_clob.dat large_clob_out.dat" ); 44 | } 45 | print "done\n"; 46 | } 47 | } 48 | 49 | $testcase = new Test(); 50 | $testcase->runTest(); 51 | ?> 52 | --EXPECTF-- 53 | inserting from file stream 54 | succesful 55 | runnign query 56 | string(1) "0" 57 | string(%d) %a 58 | done 59 | -------------------------------------------------------------------------------- /tests/fvt_017b_V5V6_InsertRetrieveLargeClobFile_02.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Insert and retrieve a very large clob file. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* 21 | * Create the test table. We use UTF-8 because the 22 | * input is UTF-8, but has an invalid character; 23 | * converting will cause it to fail (silently, because 24 | * SQLParamData errors are not checked as of 20230614). 25 | * 26 | * XXX: Set i5_override_ccsid=1208 in case? 27 | */ 28 | $create = 'CREATE TABLE animals (id INTEGER, my_clob clob ccsid 1208)'; 29 | $result = $this->db->exec( $create ); 30 | 31 | $fp = fopen( dirname(__FILE__) . "/large_clob.dat" , "r" ); 32 | //$fp = fopen("large_clob.dat" , "r" ); // Test Tool 33 | $stmt = $this->db->prepare('insert into animals (id,my_clob) values (:id,:my_clob)'); 34 | print "inserting from file stream\n"; 35 | $stmt->bindValue( ':id' , 0 ); 36 | $stmt->bindParam( ':my_clob' , $fp , PDO::PARAM_LOB ); 37 | $stmt->execute(); 38 | print "succesful\n"; 39 | 40 | print "runnign query\n"; 41 | $stmt = $this->db->prepare( 'select id,my_clob from animals' ); 42 | 43 | $rs = $stmt->execute(); 44 | $stmt->bindColumn( 'ID' , $id ); 45 | $stmt->bindColumn( 'MY_CLOB' , $clob , PDO::PARAM_LOB ); 46 | 47 | while ($stmt->fetch(PDO::FETCH_BOUND)) { 48 | var_dump( $id ); 49 | //var_dump( $clob ); 50 | $fp = fopen( dirname(__FILE__) . "/large_clob_out.dat" , "w" ); 51 | //$fp = fopen("large_clob_out.dat" , "w" ); // Test Tool 52 | fwrite($fp , $clob); 53 | system( "diff " . dirname(__FILE__) . "/large_clob.dat " . dirname(__FILE__) . "/large_clob_out.dat" ); 54 | } 55 | print "done\n"; 56 | } 57 | } 58 | 59 | $testcase = new Test(); 60 | $testcase->runTest(); 61 | ?> 62 | --EXPECTF-- 63 | inserting from file stream 64 | succesful 65 | runnign query 66 | string(1) "0" 67 | done 68 | -------------------------------------------------------------------------------- /tests/fvt_017c_SelectLOBs.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Select LOBs, including null and 0-length 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | try { 16 | /* Drop the test table, in case it exists */ 17 | $drop = 'DROP TABLE animals'; 18 | $result = $this->db->exec( $drop ); 19 | } catch( Exception $e ){} 20 | 21 | /* Create the test table */ 22 | $create = 'CREATE TABLE animals (id INTEGER, my_clob clob, my_blob blob)'; 23 | $result = $this->db->exec( $create ); 24 | 25 | $data = array ( 26 | array(1, 'this is the clob that never ends...', 27 | 'this is the blob that never ends...') 28 | , 29 | array(2, null,null) 30 | , 31 | array(3,'','') 32 | ); 33 | 34 | $stmt = $this->db->prepare('insert into animals (id,my_clob,my_blob) values (?,?,?)'); 35 | 36 | print "inserting\n"; 37 | foreach ($data as $row) { 38 | $stmt->execute($row); 39 | } 40 | 41 | print "succesful\n"; 42 | print "running query\n"; 43 | 44 | $stmt = $this->db->prepare( 'select id,my_clob,my_blob from animals' ); 45 | 46 | $rs = $stmt->execute(); 47 | 48 | $count = 0; 49 | while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 50 | var_dump( $row['ID'] ); 51 | 52 | // this is a temporary workaround 53 | // until zero-length/lob stream 54 | // issue is fixed 55 | if ($count < 2) { 56 | var_dump( $row['MY_CLOB'] ); 57 | var_dump( $row['MY_BLOB'] ); 58 | } 59 | // suppressed deprecation message for NULL on 8.1 60 | var_dump(@strpos($row['MY_CLOB'], 'lob')); 61 | $count++; 62 | } 63 | 64 | print "done\n"; 65 | } 66 | } 67 | 68 | $testcase = new Test(); 69 | $testcase->runTest(); 70 | ?> 71 | 72 | --EXPECTF-- 73 | inserting 74 | succesful 75 | running query 76 | string(1) "1" 77 | string(35) "this is the clob that never ends..." 78 | string(35) "this is the blob that never ends..." 79 | int(13) 80 | string(1) "2" 81 | NULL 82 | NULL 83 | bool(false) 84 | string(1) "3" 85 | bool(false) 86 | done 87 | 88 | -------------------------------------------------------------------------------- /tests/fvt_018_QuoteString.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Quote a string. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | print "Connection succeeded.\n"; 14 | $string = 'Nice'; 15 | print "Unquoted string: $string\n"; 16 | print "Quoted string: " . $this->db->quote($string) . "\n"; 17 | $string = 'Naughty \' string'; 18 | print "Unquoted string: $string\n"; 19 | print "Quoted string: " . $this->db->quote($string) . "\n"; 20 | $string = "Co'mpl''ex \"st'\"ring"; 21 | print "Unquoted string: $string\n"; 22 | print "Quoted string: " . $this->db->quote($string) . "\n"; 23 | $string = "''''"; 24 | print "Unquoted string: $string\n"; 25 | print "Quoted string: " . $this->db->quote($string) . "\n"; 26 | $string = ""; 27 | print "Unquoted string: $string\n"; 28 | print "Quoted string: " . $this->db->quote($string) . "\n"; 29 | $string = NULL; 30 | print "Unquoted string: $string\n"; 31 | // PHP 8.1 makes this deprecated 32 | print "Quoted string: " . @$this->db->quote($string) . "\n"; 33 | $string = "'"; 34 | print "Unquoted string: $string\n"; 35 | print "Quoted string: " . $this->db->quote($string) . "\n"; 36 | $string = "'quoted'"; 37 | print "Unquoted string: $string\n"; 38 | print "Quoted string: " . $this->db->quote($string) . "\n"; 39 | } 40 | } 41 | 42 | $testcase = new Test(); 43 | $testcase->runTest(); 44 | ?> 45 | --EXPECT-- 46 | Connection succeeded. 47 | Unquoted string: Nice 48 | Quoted string: 'Nice' 49 | Unquoted string: Naughty ' string 50 | Quoted string: 'Naughty '' string' 51 | Unquoted string: Co'mpl''ex "st'"ring 52 | Quoted string: 'Co''mpl''''ex "st''"ring' 53 | Unquoted string: '''' 54 | Quoted string: '''''''''' 55 | Unquoted string: 56 | Quoted string: '' 57 | Unquoted string: 58 | Quoted string: '' 59 | Unquoted string: ' 60 | Quoted string: '''' 61 | Unquoted string: 'quoted' 62 | Quoted string: '''quoted''' 63 | -------------------------------------------------------------------------------- /tests/fvt_020_Rollback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: rollback 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 15 | $res = $stmt->fetch( PDO::FETCH_NUM ); 16 | $rows = $res[0]; 17 | echo $rows."\n"; 18 | 19 | $this->db->beginTransaction(); 20 | $this->db->exec( "DELETE FROM animals" ); 21 | 22 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 23 | $res = $stmt->fetch( PDO::FETCH_NUM ); 24 | $rows = $res[0]; 25 | echo $rows."\n"; 26 | 27 | $this->db->rollBack(); 28 | 29 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | $rows = $res[0]; 32 | echo $rows."\n"; 33 | } 34 | } 35 | 36 | $testcase = new Test(); 37 | $testcase->runTest(); 38 | ?> 39 | --EXPECTF-- 40 | 7 41 | 0 42 | 7 43 | -------------------------------------------------------------------------------- /tests/fvt_021_Commit.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: commit 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 15 | $res = $stmt->fetch( PDO::FETCH_NUM ); 16 | $rows = $res[0]; 17 | echo $rows."\n"; 18 | 19 | $this->db->beginTransaction(); 20 | $this->db->exec( "DELETE FROM animals" ); 21 | 22 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 23 | $res = $stmt->fetch( PDO::FETCH_NUM ); 24 | $rows = $res[0]; 25 | echo $rows."\n"; 26 | 27 | $this->db->commit(); 28 | 29 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | $rows = $res[0]; 32 | echo $rows."\n"; 33 | } 34 | } 35 | 36 | $testcase = new Test(); 37 | $testcase->runTest(); 38 | ?> 39 | --EXPECTF-- 40 | 7 41 | 0 42 | 0 43 | -------------------------------------------------------------------------------- /tests/fvt_022_RollbackAutocommitOFF.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: rollback with autocommit off 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(false); 18 | $this->prepareDB(); 19 | $stmt = $this->db->exec( "commit work" ); 20 | 21 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 22 | $res = $stmt->fetch( PDO::FETCH_NUM ); 23 | $rows = $res[0]; 24 | echo $rows."\n"; 25 | 26 | $this->db->exec( "DELETE FROM animals" ); 27 | 28 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 29 | $res = $stmt->fetch( PDO::FETCH_NUM ); 30 | $rows = $res[0]; 31 | echo $rows."\n"; 32 | 33 | $stmt = $this->db->exec( "rollback work" ); 34 | /* $this->db->rollBack(); */ 35 | 36 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 37 | $res = $stmt->fetch( PDO::FETCH_NUM ); 38 | $rows = $res[0]; 39 | echo $rows."\n"; 40 | } 41 | } 42 | 43 | $testcase = new Test(); 44 | $testcase->runTest(); 45 | ?> 46 | --EXPECTF-- 47 | 7 48 | 0 49 | 7 50 | -------------------------------------------------------------------------------- /tests/fvt_023_CommitAutocommitOFF.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: commit with autocommit off 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | dsn .= ";OptimizeAutoCommit=0;"; 14 | } 15 | 16 | public function runTest() 17 | { 18 | $this->connect(false); 19 | $this->prepareDB(); 20 | $stmt = $this->db->exec( "commit work" ); 21 | 22 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 23 | $res = $stmt->fetch( PDO::FETCH_NUM ); 24 | $rows = $res[0]; 25 | echo $rows."\n"; 26 | 27 | $this->db->exec( "DELETE FROM animals" ); 28 | 29 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | $rows = $res[0]; 32 | echo $rows."\n"; 33 | 34 | $stmt = $this->db->exec( "commit work" ); 35 | /* $this->db->commit(); */ 36 | 37 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 38 | $res = $stmt->fetch( PDO::FETCH_NUM ); 39 | $rows = $res[0]; 40 | echo $rows."\n"; 41 | } 42 | } 43 | 44 | $testcase = new Test(); 45 | $testcase->runTest(); 46 | ?> 47 | --EXPECTF-- 48 | 7 49 | 0 50 | 0 51 | -------------------------------------------------------------------------------- /tests/fvt_023_V5V6_CommitAutocommitOFF.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: commit with autocommit off 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | dsn .= ";OptimizeAutoCommit=0;"; 14 | } 15 | 16 | public function runTest() 17 | { 18 | $this->connect(false); 19 | $this->prepareDB(); 20 | $stmt = $this->db->exec( "commit work" ); 21 | 22 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 23 | $res = $stmt->fetch( PDO::FETCH_NUM ); 24 | $rows = $res[0]; 25 | echo $rows."\n"; 26 | 27 | $this->db->exec( "DELETE FROM animals" ); 28 | 29 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | $rows = $res[0]; 32 | echo $rows."\n"; 33 | 34 | $stmt = $this->db->exec( "commit work" ); 35 | /* $this->db->commit(); */ 36 | 37 | $stmt = $this->db->query( "SELECT count(*) FROM animals" ); 38 | $res = $stmt->fetch( PDO::FETCH_NUM ); 39 | $rows = $res[0]; 40 | echo $rows."\n"; 41 | } 42 | } 43 | 44 | $testcase = new Test(); 45 | $testcase->runTest(); 46 | ?> 47 | --EXPECTF-- 48 | 7 49 | 0 50 | 0 51 | -------------------------------------------------------------------------------- /tests/fvt_024_ChangeFetchModes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Change fetch modes. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 18 | $this->prepareDB(); 19 | $sql = "SELECT * FROM animals"; 20 | $stmt = $this->db->query($sql); 21 | $result = $stmt->setFetchMode(PDO::FETCH_NUM); 22 | $row = $stmt->fetch(); 23 | print "As row column numbers: " . $row[0] . " " . $row[1] . " " . $row[2] . "\n"; 24 | 25 | $stmt = $this->db->query($sql); 26 | $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 27 | $row = $stmt->fetch(); 28 | print "As row column names: " . $row["ID"] . "\n" ; 29 | 30 | $stmt = $this->db->query($sql); 31 | $result = $stmt->setFetchMode(PDO::FETCH_BOTH); 32 | $row = $stmt->fetch(); 33 | print "As row column numbers: " . $row[0] . " " . $row[1] . " " . $row[2] . "\n"; 34 | 35 | $stmt = $this->db->query($sql); 36 | $result = $stmt->setFetchMode(PDO::FETCH_BOTH); 37 | $row = $stmt->fetch(); 38 | print "As row column names: " . $row["ID"] . "\n" ; 39 | 40 | $stmt = $this->db->query($sql); 41 | $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 42 | $row = $stmt->fetch(); 43 | print "Rows not available: " . $row[1] . "\n" ; 44 | 45 | $stmt = $this->db->query($sql); 46 | $result = $stmt->setFetchMode(PDO::FETCH_COLUMN, 0); 47 | $row = $stmt->fetch(); 48 | print "As row column number: " . $row[0] . "\n" ; 49 | 50 | $stmt = $this->db->query($sql); 51 | $result = $stmt->setFetchMode(PDO::FETCH_COLUMN, 0); 52 | $row = $stmt->fetch(); 53 | print "Rows not available: " . $row[1] . "\n" ; 54 | 55 | $sth = $this->db->prepare('SELECT id, breed FROM animals' ); 56 | $sth->bindColumn(1, $id); 57 | $sth->bindColumn(2, $breed); 58 | $sth->execute(); 59 | 60 | $result = $sth->setFetchMode(PDO::FETCH_BOUND); 61 | while( $row = $sth->fetch() ) { 62 | print "The id is: " . $id . " Breed is: " . $breed . "\n"; 63 | print "Result in row : " . $row . "\n" ; 64 | } 65 | 66 | $sth = $this->db->prepare('SELECT id, breed FROM animals WHERE id > 2' ); 67 | $sth->setFetchMode(PDO::FETCH_INTO, new animalObj ); 68 | $sth->execute(); 69 | foreach($sth as $obj) { 70 | var_dump($obj); 71 | } 72 | 73 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 74 | $stmt->setFetchMode(PDO::FETCH_CLASS, 'animalObj', array(0)); 75 | $stmt->execute(); 76 | foreach($stmt as $obj) { 77 | var_dump($obj); 78 | } 79 | 80 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 81 | $stmt->setFetchMode(PDO::FETCH_OBJ); 82 | $data = $stmt->execute(); 83 | foreach($stmt as $obj) { 84 | var_dump($obj); 85 | } 86 | 87 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 88 | $stmt->setFetchMode(PDO::FETCH_LAZY); 89 | $data = $stmt->execute(); 90 | try { 91 | foreach($stmt as $obj) { 92 | var_dump($obj); 93 | } 94 | } catch( Exception $e) { 95 | print "Error: " . $stmt->errorCode() . "\n"; 96 | } 97 | } 98 | } 99 | 100 | $testcase = new Test(); 101 | $testcase->runTest(); 102 | ?> 103 | --EXPECTF-- 104 | As row column numbers: 0 cat Pook 105 | As row column names: 0 106 | As row column numbers: 0 cat Pook 107 | As row column names: 0 108 | 109 | %s 1 in %s 110 | Rows not available: 111 | As row column number: 0 112 | 113 | %s 1 in %s 114 | Rows not available: 115 | The id is: 0 Breed is: cat 116 | Result in row : 1 117 | The id is: 1 Breed is: dog 118 | Result in row : 1 119 | The id is: 2 Breed is: horse 120 | Result in row : 1 121 | The id is: 3 Breed is: gold fish 122 | Result in row : 1 123 | The id is: 4 Breed is: budgerigar 124 | Result in row : 1 125 | The id is: 5 Breed is: goat 126 | Result in row : 1 127 | The id is: 6 Breed is: llama 128 | Result in row : 1 129 | object(animalObj)#%d (4) { 130 | ["id"]=> 131 | NULL 132 | ["breed"]=> 133 | NULL 134 | ["ID"]=> 135 | string(1) "3" 136 | ["BREED"]=> 137 | string(9) "gold fish" 138 | } 139 | object(animalObj)#%d (4) { 140 | ["id"]=> 141 | NULL 142 | ["breed"]=> 143 | NULL 144 | ["ID"]=> 145 | string(1) "4" 146 | ["BREED"]=> 147 | string(10) "budgerigar" 148 | } 149 | object(animalObj)#%d (4) { 150 | ["id"]=> 151 | NULL 152 | ["breed"]=> 153 | NULL 154 | ["ID"]=> 155 | string(1) "5" 156 | ["BREED"]=> 157 | string(4) "goat" 158 | } 159 | object(animalObj)#%d (4) { 160 | ["id"]=> 161 | NULL 162 | ["breed"]=> 163 | NULL 164 | ["ID"]=> 165 | string(1) "6" 166 | ["BREED"]=> 167 | string(5) "llama" 168 | } 169 | object(animalObj)#%d (4) { 170 | ["id"]=> 171 | NULL 172 | ["breed"]=> 173 | NULL 174 | ["ID"]=> 175 | string(1) "0" 176 | ["BREED"]=> 177 | string(3) "cat" 178 | } 179 | object(animalObj)#%d (4) { 180 | ["id"]=> 181 | NULL 182 | ["breed"]=> 183 | NULL 184 | ["ID"]=> 185 | string(1) "1" 186 | ["BREED"]=> 187 | string(3) "dog" 188 | } 189 | object(animalObj)#%d (4) { 190 | ["id"]=> 191 | NULL 192 | ["breed"]=> 193 | NULL 194 | ["ID"]=> 195 | string(1) "2" 196 | ["BREED"]=> 197 | string(5) "horse" 198 | } 199 | object(animalObj)#%d (4) { 200 | ["id"]=> 201 | NULL 202 | ["breed"]=> 203 | NULL 204 | ["ID"]=> 205 | string(1) "3" 206 | ["BREED"]=> 207 | string(9) "gold fish" 208 | } 209 | object(animalObj)#%d (4) { 210 | ["id"]=> 211 | NULL 212 | ["breed"]=> 213 | NULL 214 | ["ID"]=> 215 | string(1) "4" 216 | ["BREED"]=> 217 | string(10) "budgerigar" 218 | } 219 | object(animalObj)#%d (4) { 220 | ["id"]=> 221 | NULL 222 | ["breed"]=> 223 | NULL 224 | ["ID"]=> 225 | string(1) "5" 226 | ["BREED"]=> 227 | string(4) "goat" 228 | } 229 | object(animalObj)#%d (4) { 230 | ["id"]=> 231 | NULL 232 | ["breed"]=> 233 | NULL 234 | ["ID"]=> 235 | string(1) "6" 236 | ["BREED"]=> 237 | string(5) "llama" 238 | } 239 | object(stdClass)#%d (2) { 240 | ["ID"]=> 241 | string(1) "0" 242 | ["BREED"]=> 243 | string(3) "cat" 244 | } 245 | object(stdClass)#%d (2) { 246 | ["ID"]=> 247 | string(1) "1" 248 | ["BREED"]=> 249 | string(3) "dog" 250 | } 251 | object(stdClass)#%d (2) { 252 | ["ID"]=> 253 | string(1) "2" 254 | ["BREED"]=> 255 | string(5) "horse" 256 | } 257 | object(stdClass)#%d (2) { 258 | ["ID"]=> 259 | string(1) "3" 260 | ["BREED"]=> 261 | string(9) "gold fish" 262 | } 263 | object(stdClass)#%d (2) { 264 | ["ID"]=> 265 | string(1) "4" 266 | ["BREED"]=> 267 | string(10) "budgerigar" 268 | } 269 | object(stdClass)#%d (2) { 270 | ["ID"]=> 271 | string(1) "5" 272 | ["BREED"]=> 273 | string(4) "goat" 274 | } 275 | object(stdClass)#%d (2) { 276 | ["ID"]=> 277 | string(1) "6" 278 | ["BREED"]=> 279 | string(5) "llama" 280 | } 281 | object(PDORow)#%d (3) { 282 | ["queryString"]=> 283 | string(29) "SELECT id, breed FROM animals" 284 | ["ID"]=> 285 | string(1) "0" 286 | ["BREED"]=> 287 | string(3) "cat" 288 | } 289 | object(PDORow)#%d (3) { 290 | ["queryString"]=> 291 | string(29) "SELECT id, breed FROM animals" 292 | ["ID"]=> 293 | string(1) "1" 294 | ["BREED"]=> 295 | string(3) "dog" 296 | } 297 | object(PDORow)#%d (3) { 298 | ["queryString"]=> 299 | string(29) "SELECT id, breed FROM animals" 300 | ["ID"]=> 301 | string(1) "2" 302 | ["BREED"]=> 303 | string(5) "horse" 304 | } 305 | object(PDORow)#%d (3) { 306 | ["queryString"]=> 307 | string(29) "SELECT id, breed FROM animals" 308 | ["ID"]=> 309 | string(1) "3" 310 | ["BREED"]=> 311 | string(9) "gold fish" 312 | } 313 | object(PDORow)#%d (3) { 314 | ["queryString"]=> 315 | string(29) "SELECT id, breed FROM animals" 316 | ["ID"]=> 317 | string(1) "4" 318 | ["BREED"]=> 319 | string(10) "budgerigar" 320 | } 321 | object(PDORow)#%d (3) { 322 | ["queryString"]=> 323 | string(29) "SELECT id, breed FROM animals" 324 | ["ID"]=> 325 | string(1) "5" 326 | ["BREED"]=> 327 | string(4) "goat" 328 | } 329 | object(PDORow)#%d (3) { 330 | ["queryString"]=> 331 | string(29) "SELECT id, breed FROM animals" 332 | ["ID"]=> 333 | string(1) "6" 334 | ["BREED"]=> 335 | string(5) "llama" 336 | } 337 | -------------------------------------------------------------------------------- /tests/fvt_024_V5V6_ChangeFetchModes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Change fetch modes. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 18 | $this->prepareDB(); 19 | $sql = "SELECT * FROM animals"; 20 | $stmt = $this->db->query($sql); 21 | $result = $stmt->setFetchMode(PDO::FETCH_NUM); 22 | $row = $stmt->fetch(); 23 | print "As row column numbers: " . $row[0] . " " . $row[1] . " " . $row[2] . "\n"; 24 | 25 | $stmt = $this->db->query($sql); 26 | $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 27 | $row = $stmt->fetch(); 28 | print "As row column names: " . $row["ID"] . "\n" ; 29 | 30 | $stmt = $this->db->query($sql); 31 | $result = $stmt->setFetchMode(PDO::FETCH_BOTH); 32 | $row = $stmt->fetch(); 33 | print "As row column numbers: " . $row[0] . " " . $row[1] . " " . $row[2] . "\n"; 34 | 35 | $stmt = $this->db->query($sql); 36 | $result = $stmt->setFetchMode(PDO::FETCH_BOTH); 37 | $row = $stmt->fetch(); 38 | print "As row column names: " . $row["ID"] . "\n" ; 39 | 40 | $stmt = $this->db->query($sql); 41 | $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 42 | $row = $stmt->fetch(); 43 | print "Rows not available: " . $row[1] . "\n" ; 44 | 45 | $stmt = $this->db->query($sql); 46 | $result = $stmt->setFetchMode(PDO::FETCH_COLUMN, 0); 47 | $row = $stmt->fetch(); 48 | print "As row column number: " . $row[0] . "\n" ; 49 | 50 | $stmt = $this->db->query($sql); 51 | $result = $stmt->setFetchMode(PDO::FETCH_COLUMN, 0); 52 | $row = $stmt->fetch(); 53 | print "Rows not available: " . $row[1] . "\n" ; 54 | 55 | $sth = $this->db->prepare('SELECT id, breed FROM animals' ); 56 | $sth->bindColumn(1, $id); 57 | $sth->bindColumn(2, $breed); 58 | $sth->execute(); 59 | 60 | $result = $sth->setFetchMode(PDO::FETCH_BOUND); 61 | while( $row = $sth->fetch() ) { 62 | print "The id is: " . $id . " Breed is: " . $breed . "\n"; 63 | print "Result in row : " . $row . "\n" ; 64 | } 65 | 66 | $sth = $this->db->prepare('SELECT id, breed FROM animals WHERE id > 2' ); 67 | $sth->setFetchMode(PDO::FETCH_INTO, new animalObj ); 68 | $sth->execute(); 69 | foreach($sth as $obj) { 70 | var_dump($obj); 71 | } 72 | 73 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 74 | $stmt->setFetchMode(PDO::FETCH_CLASS, 'animalObj', array(0)); 75 | $stmt->execute(); 76 | foreach($stmt as $obj) { 77 | var_dump($obj); 78 | } 79 | 80 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 81 | $stmt->setFetchMode(PDO::FETCH_OBJ); 82 | $data = $stmt->execute(); 83 | foreach($stmt as $obj) { 84 | var_dump($obj); 85 | } 86 | 87 | $stmt = $this->db->prepare('SELECT id, breed FROM animals' ); 88 | $stmt->setFetchMode(PDO::FETCH_LAZY); 89 | $data = $stmt->execute(); 90 | try { 91 | foreach($stmt as $obj) { 92 | var_dump($obj); 93 | } 94 | } catch( Exception $e) { 95 | print "Error: " . $stmt->errorCode() . "\n"; 96 | } 97 | } 98 | } 99 | 100 | $testcase = new Test(); 101 | $testcase->runTest(); 102 | ?> 103 | --EXPECTF-- 104 | As row column numbers: 0 cat Pook 105 | As row column names: 0 106 | As row column numbers: 0 cat Pook 107 | As row column names: 0 108 | 109 | %s: Undefined %s 110 | Rows not available: 111 | As row column number: 0 112 | 113 | %s: Uninitialized string offset%s 114 | Rows not available: 115 | The id is: 0 Breed is: cat 116 | Result in row : 1 117 | The id is: 1 Breed is: dog 118 | Result in row : 1 119 | The id is: 2 Breed is: horse 120 | Result in row : 1 121 | The id is: 3 Breed is: gold fish 122 | Result in row : 1 123 | The id is: 4 Breed is: budgerigar 124 | Result in row : 1 125 | The id is: 5 Breed is: goat 126 | Result in row : 1 127 | The id is: 6 Breed is: llama 128 | Result in row : 1 129 | object(animalObj)%s (4) { 130 | ["id"]=> 131 | NULL 132 | ["breed"]=> 133 | NULL 134 | ["ID"]=> 135 | string(1) "3" 136 | ["BREED"]=> 137 | string(9) "gold fish" 138 | } 139 | object(animalObj)%s (4) { 140 | ["id"]=> 141 | NULL 142 | ["breed"]=> 143 | NULL 144 | ["ID"]=> 145 | string(1) "4" 146 | ["BREED"]=> 147 | string(10) "budgerigar" 148 | } 149 | object(animalObj)%s (4) { 150 | ["id"]=> 151 | NULL 152 | ["breed"]=> 153 | NULL 154 | ["ID"]=> 155 | string(1) "5" 156 | ["BREED"]=> 157 | string(4) "goat" 158 | } 159 | object(animalObj)%s (4) { 160 | ["id"]=> 161 | NULL 162 | ["breed"]=> 163 | NULL 164 | ["ID"]=> 165 | string(1) "6" 166 | ["BREED"]=> 167 | string(5) "llama" 168 | } 169 | object(animalObj)%s (4) { 170 | ["id"]=> 171 | NULL 172 | ["breed"]=> 173 | NULL 174 | ["ID"]=> 175 | string(1) "0" 176 | ["BREED"]=> 177 | string(3) "cat" 178 | } 179 | object(animalObj)%s (4) { 180 | ["id"]=> 181 | NULL 182 | ["breed"]=> 183 | NULL 184 | ["ID"]=> 185 | string(1) "1" 186 | ["BREED"]=> 187 | string(3) "dog" 188 | } 189 | object(animalObj)%s (4) { 190 | ["id"]=> 191 | NULL 192 | ["breed"]=> 193 | NULL 194 | ["ID"]=> 195 | string(1) "2" 196 | ["BREED"]=> 197 | string(5) "horse" 198 | } 199 | object(animalObj)%s (4) { 200 | ["id"]=> 201 | NULL 202 | ["breed"]=> 203 | NULL 204 | ["ID"]=> 205 | string(1) "3" 206 | ["BREED"]=> 207 | string(9) "gold fish" 208 | } 209 | object(animalObj)%s (4) { 210 | ["id"]=> 211 | NULL 212 | ["breed"]=> 213 | NULL 214 | ["ID"]=> 215 | string(1) "4" 216 | ["BREED"]=> 217 | string(10) "budgerigar" 218 | } 219 | object(animalObj)%s (4) { 220 | ["id"]=> 221 | NULL 222 | ["breed"]=> 223 | NULL 224 | ["ID"]=> 225 | string(1) "5" 226 | ["BREED"]=> 227 | string(4) "goat" 228 | } 229 | object(animalObj)%s (4) { 230 | ["id"]=> 231 | NULL 232 | ["breed"]=> 233 | NULL 234 | ["ID"]=> 235 | string(1) "6" 236 | ["BREED"]=> 237 | string(5) "llama" 238 | } 239 | object(stdClass)%s (2) { 240 | ["ID"]=> 241 | string(1) "0" 242 | ["BREED"]=> 243 | string(3) "cat" 244 | } 245 | object(stdClass)%s (2) { 246 | ["ID"]=> 247 | string(1) "1" 248 | ["BREED"]=> 249 | string(3) "dog" 250 | } 251 | object(stdClass)%s (2) { 252 | ["ID"]=> 253 | string(1) "2" 254 | ["BREED"]=> 255 | string(5) "horse" 256 | } 257 | object(stdClass)%s (2) { 258 | ["ID"]=> 259 | string(1) "3" 260 | ["BREED"]=> 261 | string(9) "gold fish" 262 | } 263 | object(stdClass)%s (2) { 264 | ["ID"]=> 265 | string(1) "4" 266 | ["BREED"]=> 267 | string(10) "budgerigar" 268 | } 269 | object(stdClass)%s (2) { 270 | ["ID"]=> 271 | string(1) "5" 272 | ["BREED"]=> 273 | string(4) "goat" 274 | } 275 | object(stdClass)%s (2) { 276 | ["ID"]=> 277 | string(1) "6" 278 | ["BREED"]=> 279 | string(5) "llama" 280 | } 281 | object(PDORow)%s (3) { 282 | ["queryString"]=> 283 | string(29) "SELECT id, breed FROM animals" 284 | ["ID"]=> 285 | string(1) "0" 286 | ["BREED"]=> 287 | string(3) "cat" 288 | } 289 | object(PDORow)%s (3) { 290 | ["queryString"]=> 291 | string(29) "SELECT id, breed FROM animals" 292 | ["ID"]=> 293 | string(1) "1" 294 | ["BREED"]=> 295 | string(3) "dog" 296 | } 297 | object(PDORow)%s (3) { 298 | ["queryString"]=> 299 | string(29) "SELECT id, breed FROM animals" 300 | ["ID"]=> 301 | string(1) "2" 302 | ["BREED"]=> 303 | string(5) "horse" 304 | } 305 | object(PDORow)%s (3) { 306 | ["queryString"]=> 307 | string(29) "SELECT id, breed FROM animals" 308 | ["ID"]=> 309 | string(1) "3" 310 | ["BREED"]=> 311 | string(9) "gold fish" 312 | } 313 | object(PDORow)%s (3) { 314 | ["queryString"]=> 315 | string(29) "SELECT id, breed FROM animals" 316 | ["ID"]=> 317 | string(1) "4" 318 | ["BREED"]=> 319 | string(10) "budgerigar" 320 | } 321 | object(PDORow)%s (3) { 322 | ["queryString"]=> 323 | string(29) "SELECT id, breed FROM animals" 324 | ["ID"]=> 325 | string(1) "5" 326 | ["BREED"]=> 327 | string(4) "goat" 328 | } 329 | object(PDORow)%s (3) { 330 | ["queryString"]=> 331 | string(29) "SELECT id, breed FROM animals" 332 | ["ID"]=> 333 | string(1) "6" 334 | ["BREED"]=> 335 | string(5) "llama" 336 | } 337 | -------------------------------------------------------------------------------- /tests/fvt_025_ColumnMetaData.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Get Column meta data. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | $sql = "SELECT * FROM animals"; 13 | $stmt = $this->db->query($sql); 14 | $meta = $stmt->getColumnMeta(0); 15 | var_dump( $meta ); 16 | $meta = $stmt->getColumnMeta(1); 17 | var_dump( $meta ); 18 | $meta = $stmt->getColumnMeta(2); 19 | var_dump( $meta ); 20 | $meta = $stmt->getColumnMeta(3); 21 | var_dump( $meta ); 22 | try { 23 | $meta = $stmt->getColumnMeta(6); 24 | var_dump( $meta ); 25 | } catch( Exception $e ) { 26 | print "Error: " . $stmt->errorCode() . "\n"; 27 | } 28 | try{ 29 | $meta = $stmt->getColumnMeta(-1); 30 | var_dump( $meta ); 31 | } catch( ValueError $e ) { 32 | /* 33 | * PHP 8 makes PDO catch negative column 34 | * references, so it'll never reach the driver. 35 | * It won't mutate the SQL error, so it'll just 36 | * return the same value it had last time. As 37 | * such, just consider getting a ValueError 38 | * good enough for this part of the test. 39 | */ 40 | print "ValueError\n"; 41 | } catch( Exception $e ) { 42 | print "Error: " . $stmt->errorCode() . "\n"; 43 | } 44 | } 45 | } 46 | 47 | $testcase = new Test(); 48 | $testcase->runTest(); 49 | ?> 50 | --EXPECTREGEX-- 51 | array\(8\) \{ 52 | \["scale"\]=> 53 | int\(0\) 54 | \["table"\]=> 55 | string\(7\) ("ANIMALS")|("animals") 56 | \["native_type"\]=> 57 | string\(7\) "INTEGER" 58 | \["flags"\]=> 59 | array\(3\) { 60 | \["not_null"\]=> 61 | bool\(false\) 62 | \["unsigned"\]=> 63 | bool\(false\) 64 | \["auto_increment"\]=> 65 | bool\(false\) 66 | \} 67 | \["name"\]=> 68 | string\(2\) "ID" 69 | \["len"\]=> 70 | int\(11\) 71 | \["precision"\]=> 72 | int\(0\) 73 | \["pdo_type"\]=> 74 | int\(2\) 75 | \} 76 | array\(8\) \{ 77 | \["scale"\]=> 78 | int\(0\) 79 | \["table"\]=> 80 | string\(7\) ("ANIMALS")|("animals") 81 | \["native_type"\]=> 82 | string\(7\) "VARCHAR" 83 | \["flags"\]=> 84 | array\(3\) \{ 85 | \["not_null"\]=> 86 | bool\(false\) 87 | \["unsigned"\]=> 88 | bool\(true\) 89 | \["auto_increment"\]=> 90 | bool\(false\) 91 | \} 92 | \["name"\]=> 93 | string\(5\) "BREED" 94 | \["len"\]=> 95 | int\(32\) 96 | \["precision"\]=> 97 | int\(0\) 98 | \["pdo_type"\]=> 99 | int\(2\) 100 | \} 101 | array\(8\) \{ 102 | \["scale"\]=> 103 | int\(0\) 104 | \["table"\]=> 105 | string\(7\) ("ANIMALS")|("animals") 106 | \["native_type"\]=> 107 | string\(4\) "CHAR" 108 | \["flags"\]=> 109 | array\(3\) { 110 | \["not_null"\]=> 111 | bool\(false\) 112 | \["unsigned"\]=> 113 | bool\(true\) 114 | \["auto_increment"\]=> 115 | bool\(false\) 116 | \} 117 | \["name"\]=> 118 | string\(4\) "NAME" 119 | \["len"\]=> 120 | int\(16\) 121 | \["precision"\]=> 122 | int\(0\) 123 | \["pdo_type"\]=> 124 | int\(2\) 125 | \} 126 | array\(8\) \{ 127 | \["scale"\]=> 128 | int\(2\) 129 | \["table"\]=> 130 | string\(7\) ("ANIMALS")|("animals") 131 | \["native_type"\]=> 132 | string\(7\) "DECIMAL" 133 | \["flags"\]=> 134 | array\(3\) { 135 | \["not_null"\]=> 136 | bool\(false\) 137 | \["unsigned"\]=> 138 | bool\(false\) 139 | \["auto_increment"\]=> 140 | bool\(false\) 141 | \} 142 | \["name"\]=> 143 | string\(6\) "WEIGHT" 144 | \["len"\]=> 145 | int\(9\) 146 | \["precision"\]=> 147 | int\(2\) 148 | \["pdo_type"\]=> 149 | int\(2\) 150 | \} 151 | Error: HY097 152 | (Error: 42P10)|(ValueError) 153 | 154 | -------------------------------------------------------------------------------- /tests/fvt_025_V5V6_ColumnMetaData.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Get Column meta data. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | $sql = "SELECT * FROM animals"; 13 | $stmt = $this->db->query($sql); 14 | $meta = $stmt->getColumnMeta(0); 15 | var_dump( $meta ); 16 | $meta = $stmt->getColumnMeta(1); 17 | var_dump( $meta ); 18 | $meta = $stmt->getColumnMeta(2); 19 | var_dump( $meta ); 20 | $meta = $stmt->getColumnMeta(3); 21 | var_dump( $meta ); 22 | try { 23 | $meta = $stmt->getColumnMeta(6); 24 | var_dump( $meta ); 25 | } catch( Exception $e ) { 26 | print "Error: " . $stmt->errorCode() . "\n"; 27 | } 28 | try{ 29 | $meta = $stmt->getColumnMeta(-1); 30 | var_dump( $meta ); 31 | } catch( ValueError $e ) { 32 | /* 33 | * PHP 8 makes PDO catch negative column 34 | * references, so it'll never reach the driver. 35 | * It won't mutate the SQL error, so it'll just 36 | * return the same value it had last time. As 37 | * such, just consider getting a ValueError 38 | * good enough for this part of the test. 39 | */ 40 | print "ValueError\n"; 41 | } catch( Exception $e ) { 42 | print "Error: " . $stmt->errorCode() . "\n"; 43 | } 44 | } 45 | } 46 | 47 | $testcase = new Test(); 48 | $testcase->runTest(); 49 | ?> 50 | --EXPECTREGEX-- 51 | array\(8\) \{ 52 | \["scale"\]=> 53 | int\(0\) 54 | \["table"\]=> 55 | string\(7\) ("ANIMALS")|("animals") 56 | \["native_type"\]=> 57 | string\(7\) "INTEGER" 58 | \["flags"\]=> 59 | array\(3\) { 60 | \["not_null"\]=> 61 | bool\(false\) 62 | \["unsigned"\]=> 63 | bool\(false\) 64 | \["auto_increment"\]=> 65 | bool\(false\) 66 | \} 67 | \["name"\]=> 68 | string\(2\) "ID" 69 | \["len"\]=> 70 | int\(11\) 71 | \["precision"\]=> 72 | int\(0\) 73 | \["pdo_type"\]=> 74 | int\(2\) 75 | \} 76 | array\(8\) \{ 77 | \["scale"\]=> 78 | int\(0\) 79 | \["table"\]=> 80 | string\(7\) ("ANIMALS")|("animals") 81 | \["native_type"\]=> 82 | string\(7\) "VARCHAR" 83 | \["flags"\]=> 84 | array\(3\) \{ 85 | \["not_null"\]=> 86 | bool\(false\) 87 | \["unsigned"\]=> 88 | bool\(true\) 89 | \["auto_increment"\]=> 90 | bool\(false\) 91 | \} 92 | \["name"\]=> 93 | string\(5\) "BREED" 94 | \["len"\]=> 95 | int\(32\) 96 | \["precision"\]=> 97 | int\(0\) 98 | \["pdo_type"\]=> 99 | int\(2\) 100 | \} 101 | array\(8\) \{ 102 | \["scale"\]=> 103 | int\(0\) 104 | \["table"\]=> 105 | string\(7\) ("ANIMALS")|("animals") 106 | \["native_type"\]=> 107 | string\(4\) "CHAR" 108 | \["flags"\]=> 109 | array\(3\) { 110 | \["not_null"\]=> 111 | bool\(false\) 112 | \["unsigned"\]=> 113 | bool\(true\) 114 | \["auto_increment"\]=> 115 | bool\(false\) 116 | \} 117 | \["name"\]=> 118 | string\(4\) "NAME" 119 | \["len"\]=> 120 | int\(16\) 121 | \["precision"\]=> 122 | int\(0\) 123 | \["pdo_type"\]=> 124 | int\(2\) 125 | \} 126 | array\(8\) \{ 127 | \["scale"\]=> 128 | int\(2\) 129 | \["table"\]=> 130 | string\(7\) ("ANIMALS")|("animals") 131 | \["native_type"\]=> 132 | string\(7\) "DECIMAL" 133 | \["flags"\]=> 134 | array\(3\) { 135 | \["not_null"\]=> 136 | bool\(false\) 137 | \["unsigned"\]=> 138 | bool\(false\) 139 | \["auto_increment"\]=> 140 | bool\(false\) 141 | \} 142 | \["name"\]=> 143 | string\(6\) "WEIGHT" 144 | \["len"\]=> 145 | int\(9\) 146 | \["precision"\]=> 147 | int\(2\) 148 | \["pdo_type"\]=> 149 | int\(2\) 150 | \} 151 | Error: HY097 152 | (Error: 42P10)|(ValueError) 153 | 154 | -------------------------------------------------------------------------------- /tests/fvt_026_ErrCode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error code. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | try { 13 | $err = $this->db->prepare('SELECT skull FROM bones'); 14 | $err->execute(); 15 | } catch (Exception $e) { 16 | echo "\nPDOStatement::errorCode(): "; 17 | print $this->db->errorCode(); 18 | } 19 | try { 20 | $err = $this->db->prepare('SELECT id FROM animals WHERE bones=100'); 21 | $err->execute(); 22 | } catch (Exception $e) { 23 | echo "\nPDOStatement::errorCode(): "; 24 | print $this->db->errorCode(); 25 | } 26 | try { 27 | $err = $this->db->prepare('SELECT id, skull FROM animals WHERE id=1'); 28 | $err->execute(); 29 | } catch (Exception $e) { 30 | echo "\nPDOStatement::errorCode(): "; 31 | print $this->db->errorCode(); 32 | } 33 | } 34 | } 35 | $testcase = new Test(); 36 | $testcase->runTest(); 37 | ?> 38 | --EXPECTREGEX-- 39 | (PDOStatement::errorCode\(\): 42S02 40 | PDOStatement::errorCode\(\): 42S22 41 | PDOStatement::errorCode\(\): 42S22)|(PDOStatement::errorCode\(\): 42S22 42 | PDOStatement::errorCode\(\): IX000 43 | PDOStatement::errorCode\(\): IX000) 44 | -------------------------------------------------------------------------------- /tests/fvt_026_V5V6_ErrCode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error code. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | try { 13 | $err = $this->db->prepare('SELECT skull FROM bones'); 14 | $err->execute(); 15 | } catch (Exception $e) { 16 | echo "\nPDOStatement::errorCode(): "; 17 | print $this->db->errorCode(); 18 | } 19 | try { 20 | $err = $this->db->prepare('SELECT id FROM animals WHERE bones=100'); 21 | $err->execute(); 22 | } catch (Exception $e) { 23 | echo "\nPDOStatement::errorCode(): "; 24 | print $this->db->errorCode(); 25 | } 26 | try { 27 | $err = $this->db->prepare('SELECT id, skull FROM animals WHERE id=1'); 28 | $err->execute(); 29 | } catch (Exception $e) { 30 | echo "\nPDOStatement::errorCode(): "; 31 | print $this->db->errorCode(); 32 | } 33 | } 34 | } 35 | $testcase = new Test(); 36 | $testcase->runTest(); 37 | ?> 38 | --EXPECTF-- 39 | PDOStatement::errorCode(): 42704 40 | PDOStatement::errorCode(): 42703 41 | PDOStatement::errorCode(): 42703 42 | -------------------------------------------------------------------------------- /tests/fvt_027_FetchColModeOptions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Testing fetchColumn with different modes and options 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | $sql = "SELECT * FROM animals WHERE id > 0"; 13 | 14 | $stmt = $this->db->prepare($sql); 15 | $stmt->execute(); 16 | while( $value = $stmt->fetchColumn() ) { 17 | print "The column value is: " . $value . "\n"; 18 | } 19 | 20 | $stmt = $this->db->prepare($sql); 21 | $stmt->execute(); 22 | while( $value = $stmt->fetchColumn( 1 ) ) { 23 | print "The column value is: " . $value . "\n"; 24 | } 25 | 26 | $stmt = $this->db->prepare($sql); 27 | $stmt->execute(); 28 | try { 29 | while( $value = $stmt->fetchColumn( -1 ) ) { 30 | print "The column value is: " . $value . "\n"; 31 | } 32 | } catch( ValueError $e ) { 33 | /* 34 | * PHP 8 makes PDO catch negative column 35 | * references, so it'll never reach the driver. 36 | * It won't mutate the SQL error, so it'll just 37 | * return the same value it had last time. As 38 | * such, just consider getting a ValueError 39 | * good enough for this part of the test. 40 | */ 41 | print "Negative index expected to fail\n"; 42 | } catch (Exception $e) { 43 | print "Negative index expected to fail\n"; 44 | } 45 | 46 | $stmt = $this->db->prepare($sql); 47 | $stmt->execute(); 48 | try { 49 | while( $value = $stmt->fetchColumn( 7 ) ) { 50 | print "The column value is: " . $value . "\n"; 51 | } 52 | } catch( ValueError $e ) { 53 | /* As above, so below (but for OOB) */ 54 | print "Out of bounds index expected to fail\n"; 55 | } catch (Exception $e) { 56 | print "Out of bounds index expected to fail\n"; 57 | } 58 | } 59 | } 60 | $testcase = new Test(); 61 | $testcase->runTest(); 62 | ?> 63 | --EXPECTF-- 64 | The column value is: 1 65 | The column value is: 2 66 | The column value is: 3 67 | The column value is: 4 68 | The column value is: 5 69 | The column value is: 6 70 | The column value is: dog 71 | The column value is: horse 72 | The column value is: gold fish 73 | The column value is: budgerigar 74 | The column value is: goat 75 | The column value is: llama 76 | Negative index expected to fail 77 | Out of bounds index expected to fail 78 | -------------------------------------------------------------------------------- /tests/fvt_028_ExecutBasicSP.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test the execution of a basic stored procedure 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | try{ 13 | $result = $this->db->exec("DROP PROCEDURE SP_Example"); 14 | } catch( Exception $e ){} 15 | 16 | $server_info = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 17 | $create = ""; 18 | if( strncmp( $server_info, "DB2", 3 ) == 0 ) 19 | { 20 | $create = <<db->exec($create); 55 | 56 | /* EXECUTE THE STORED PROCEDURE */ 57 | $stmt = $this->db->query('CALL SP_Example()'); 58 | 59 | /* FIRST RESULT SET */ 60 | while ($row = $stmt->fetch()) { 61 | var_dump($row); 62 | } 63 | 64 | } 65 | } 66 | $testcase = new Test(); 67 | $testcase->runTest(); 68 | ?> 69 | --EXPECTREGEX-- 70 | (array\(4\) \{ 71 | \["NAME"\]=> 72 | string\(16\) "Bubbles " 73 | \[0\]=> 74 | string\(16\) "Bubbles " 75 | \["ID"\]=> 76 | string\(1\) "3" 77 | \[1\]=> 78 | string\(1\) "3" 79 | \} 80 | array\(4\) \{ 81 | \["NAME"\]=> 82 | string\(16\) "Gizmo " 83 | \[0\]=> 84 | string\(16\) "Gizmo " 85 | \["ID"\]=> 86 | string\(1\) "4" 87 | \[1\]=> 88 | string\(1\) "4" 89 | \} 90 | array\(4\) \{ 91 | \["NAME"\]=> 92 | string\(16\) "Peaches " 93 | \[0\]=> 94 | string\(16\) "Peaches " 95 | \["ID"\]=> 96 | string\(1\) "1" 97 | \[1\]=> 98 | string\(1\) "1" 99 | \} 100 | array\(4\) \{ 101 | \["NAME"\]=> 102 | string\(16\) "Pook " 103 | \[0\]=> 104 | string\(16\) "Pook " 105 | \["ID"\]=> 106 | string\(1\) "0" 107 | \[1\]=> 108 | string\(1\) "0" 109 | \} 110 | array\(4\) \{ 111 | \["NAME"\]=> 112 | string\(16\) "Rickety Ride " 113 | \[0\]=> 114 | string\(16\) "Rickety Ride " 115 | \["ID"\]=> 116 | string\(1\) "5" 117 | \[1\]=> 118 | string\(1\) "5" 119 | \} 120 | array\(4\) \{ 121 | \["NAME"\]=> 122 | string\(16\) "Smarty " 123 | \[0\]=> 124 | string\(16\) "Smarty " 125 | \["ID"\]=> 126 | string\(1\) "2" 127 | \[1\]=> 128 | string\(1\) "2" 129 | \} 130 | array\(4\) \{ 131 | \["NAME"\]=> 132 | string\(16\) "Sweater " 133 | \[0\]=> 134 | string\(16\) "Sweater " 135 | \["ID"\]=> 136 | string\(1\) "6" 137 | \[1\]=> 138 | string\(1\) "6" 139 | \})|(array\(3\) \{ 140 | \[1\]=> 141 | string\(16\) "Bubbles " 142 | \[2\]=> 143 | string\(1\) "3" 144 | \[3\]=> 145 | string\(1\) "3" 146 | \}) 147 | -------------------------------------------------------------------------------- /tests/fvt_028_V5V6_ExecutBasicSP.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test the execution of a basic stored procedure 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | $this->prepareDB(); 12 | try{ 13 | $result = $this->db->exec("DROP PROCEDURE SP_Example"); 14 | } catch( Exception $e ){} 15 | 16 | $server_info = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 17 | $create = ""; 18 | if( strncmp( $server_info, "DB2", 3 ) == 0 19 | || strncmp( $server_info, "AS", 2 ) == 0 20 | || strncmp( $server_info, "QSQ", 3 ) == 0 ) 21 | { 22 | $create = <<db->exec($create); 57 | 58 | /* EXECUTE THE STORED PROCEDURE */ 59 | $stmt = $this->db->query('CALL SP_Example()'); 60 | 61 | /* FIRST RESULT SET */ 62 | while ($row = $stmt->fetch()) { 63 | var_dump($row); 64 | } 65 | 66 | } 67 | } 68 | $testcase = new Test(); 69 | $testcase->runTest(); 70 | ?> 71 | --EXPECTREGEX-- 72 | (array\(4\) \{ 73 | \["NAME"\]=> 74 | string\(16\) "Bubbles " 75 | \[0\]=> 76 | string\(16\) "Bubbles " 77 | \["ID"\]=> 78 | string\(1\) "3" 79 | \[1\]=> 80 | string\(1\) "3" 81 | \} 82 | array\(4\) \{ 83 | \["NAME"\]=> 84 | string\(16\) "Gizmo " 85 | \[0\]=> 86 | string\(16\) "Gizmo " 87 | \["ID"\]=> 88 | string\(1\) "4" 89 | \[1\]=> 90 | string\(1\) "4" 91 | \} 92 | array\(4\) \{ 93 | \["NAME"\]=> 94 | string\(16\) "Peaches " 95 | \[0\]=> 96 | string\(16\) "Peaches " 97 | \["ID"\]=> 98 | string\(1\) "1" 99 | \[1\]=> 100 | string\(1\) "1" 101 | \} 102 | array\(4\) \{ 103 | \["NAME"\]=> 104 | string\(16\) "Pook " 105 | \[0\]=> 106 | string\(16\) "Pook " 107 | \["ID"\]=> 108 | string\(1\) "0" 109 | \[1\]=> 110 | string\(1\) "0" 111 | \} 112 | array\(4\) \{ 113 | \["NAME"\]=> 114 | string\(16\) "Rickety Ride " 115 | \[0\]=> 116 | string\(16\) "Rickety Ride " 117 | \["ID"\]=> 118 | string\(1\) "5" 119 | \[1\]=> 120 | string\(1\) "5" 121 | \} 122 | array\(4\) \{ 123 | \["NAME"\]=> 124 | string\(16\) "Smarty " 125 | \[0\]=> 126 | string\(16\) "Smarty " 127 | \["ID"\]=> 128 | string\(1\) "2" 129 | \[1\]=> 130 | string\(1\) "2" 131 | \} 132 | array\(4\) \{ 133 | \["NAME"\]=> 134 | string\(16\) "Sweater " 135 | \[0\]=> 136 | string\(16\) "Sweater " 137 | \["ID"\]=> 138 | string\(1\) "6" 139 | \[1\]=> 140 | string\(1\) "6" 141 | \})|(array\(3\) \{ 142 | \[1\]=> 143 | string\(16\) "Bubbles " 144 | \[2\]=> 145 | string\(1\) "3" 146 | \[3\]=> 147 | string\(1\) "3" 148 | \}) 149 | -------------------------------------------------------------------------------- /tests/fvt_030_PDOStatement_fetch.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: PDOStatement::fetch() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->query( "SELECT id, breed, name, weight FROM animals WHERE id = 0" ); 16 | while( $row = $stmt->fetch( PDO::FETCH_BOTH ) ) { 17 | $breed = $row[1]; 18 | var_dump( $breed ); 19 | $name = $row["NAME"]; 20 | var_dump( $name ); 21 | } 22 | } 23 | } 24 | 25 | $testcase = new Test(); 26 | $testcase->runTest(); 27 | ?> 28 | --EXPECT-- 29 | string(3) "cat" 30 | string(16) "Pook " 31 | -------------------------------------------------------------------------------- /tests/fvt_031_FetchOrientations.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Tests all Fetch orientations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | dsn .= ";EnableScrollableCursors=1;"; 14 | } 15 | public function runTest() 16 | { 17 | $this->connect(); 18 | $this->prepareDB(); 19 | 20 | $stmt = $this->db->prepare( "SELECT id, breed, name, weight FROM animals ORDER BY id" , 21 | array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL ) ); 22 | $stmt->execute(); 23 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_FIRST ); 24 | var_dump( $row ); 25 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_NEXT ); 26 | var_dump( $row ); 27 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_PRIOR ); 28 | var_dump( $row ); 29 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_LAST ); 30 | var_dump( $row ); 31 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_ABS , 2 ); 32 | var_dump( $row ); 33 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_REL , 1 ); 34 | var_dump( $row ); 35 | } 36 | } 37 | 38 | $testcase = new Test(); 39 | $testcase->runTest(); 40 | ?> 41 | --EXPECT-- 42 | array(8) { 43 | ["ID"]=> 44 | string(1) "0" 45 | [0]=> 46 | string(1) "0" 47 | ["BREED"]=> 48 | string(3) "cat" 49 | [1]=> 50 | string(3) "cat" 51 | ["NAME"]=> 52 | string(16) "Pook " 53 | [2]=> 54 | string(16) "Pook " 55 | ["WEIGHT"]=> 56 | string(4) "3.20" 57 | [3]=> 58 | string(4) "3.20" 59 | } 60 | array(8) { 61 | ["ID"]=> 62 | string(1) "1" 63 | [0]=> 64 | string(1) "1" 65 | ["BREED"]=> 66 | string(3) "dog" 67 | [1]=> 68 | string(3) "dog" 69 | ["NAME"]=> 70 | string(16) "Peaches " 71 | [2]=> 72 | string(16) "Peaches " 73 | ["WEIGHT"]=> 74 | string(5) "12.30" 75 | [3]=> 76 | string(5) "12.30" 77 | } 78 | array(8) { 79 | ["ID"]=> 80 | string(1) "0" 81 | [0]=> 82 | string(1) "0" 83 | ["BREED"]=> 84 | string(3) "cat" 85 | [1]=> 86 | string(3) "cat" 87 | ["NAME"]=> 88 | string(16) "Pook " 89 | [2]=> 90 | string(16) "Pook " 91 | ["WEIGHT"]=> 92 | string(4) "3.20" 93 | [3]=> 94 | string(4) "3.20" 95 | } 96 | array(8) { 97 | ["ID"]=> 98 | string(1) "6" 99 | [0]=> 100 | string(1) "6" 101 | ["BREED"]=> 102 | string(5) "llama" 103 | [1]=> 104 | string(5) "llama" 105 | ["NAME"]=> 106 | string(16) "Sweater " 107 | [2]=> 108 | string(16) "Sweater " 109 | ["WEIGHT"]=> 110 | string(6) "150.00" 111 | [3]=> 112 | string(6) "150.00" 113 | } 114 | array(8) { 115 | ["ID"]=> 116 | string(1) "1" 117 | [0]=> 118 | string(1) "1" 119 | ["BREED"]=> 120 | string(3) "dog" 121 | [1]=> 122 | string(3) "dog" 123 | ["NAME"]=> 124 | string(16) "Peaches " 125 | [2]=> 126 | string(16) "Peaches " 127 | ["WEIGHT"]=> 128 | string(5) "12.30" 129 | [3]=> 130 | string(5) "12.30" 131 | } 132 | array(8) { 133 | ["ID"]=> 134 | string(1) "2" 135 | [0]=> 136 | string(1) "2" 137 | ["BREED"]=> 138 | string(5) "horse" 139 | [1]=> 140 | string(5) "horse" 141 | ["NAME"]=> 142 | string(16) "Smarty " 143 | [2]=> 144 | string(16) "Smarty " 145 | ["WEIGHT"]=> 146 | string(6) "350.00" 147 | [3]=> 148 | string(6) "350.00" 149 | } 150 | -------------------------------------------------------------------------------- /tests/fvt_031_V5V6_FetchOrientations.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Tests all Fetch orientations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | dsn .= ";EnableScrollableCursors=1;"; 14 | } 15 | public function runTest() 16 | { 17 | $this->connect(); 18 | $this->prepareDB(); 19 | 20 | $stmt = $this->db->prepare( "SELECT id, breed, name, weight FROM animals ORDER BY id" , 21 | array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL ) ); 22 | $stmt->execute(); 23 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_FIRST ); 24 | var_dump( $row ); 25 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_NEXT ); 26 | var_dump( $row ); 27 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_PRIOR ); 28 | var_dump( $row ); 29 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_LAST ); 30 | var_dump( $row ); 31 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_ABS , 2 ); 32 | var_dump( $row ); 33 | $row = $stmt->fetch( PDO::FETCH_BOTH , PDO::FETCH_ORI_REL , 1 ); 34 | var_dump( $row ); 35 | } 36 | } 37 | 38 | $testcase = new Test(); 39 | $testcase->runTest(); 40 | ?> 41 | --EXPECT-- 42 | array(8) { 43 | ["ID"]=> 44 | string(1) "0" 45 | [0]=> 46 | string(1) "0" 47 | ["BREED"]=> 48 | string(3) "cat" 49 | [1]=> 50 | string(3) "cat" 51 | ["NAME"]=> 52 | string(16) "Pook " 53 | [2]=> 54 | string(16) "Pook " 55 | ["WEIGHT"]=> 56 | string(4) "3.20" 57 | [3]=> 58 | string(4) "3.20" 59 | } 60 | array(8) { 61 | ["ID"]=> 62 | string(1) "1" 63 | [0]=> 64 | string(1) "1" 65 | ["BREED"]=> 66 | string(3) "dog" 67 | [1]=> 68 | string(3) "dog" 69 | ["NAME"]=> 70 | string(16) "Peaches " 71 | [2]=> 72 | string(16) "Peaches " 73 | ["WEIGHT"]=> 74 | string(5) "12.30" 75 | [3]=> 76 | string(5) "12.30" 77 | } 78 | array(8) { 79 | ["ID"]=> 80 | string(1) "0" 81 | [0]=> 82 | string(1) "0" 83 | ["BREED"]=> 84 | string(3) "cat" 85 | [1]=> 86 | string(3) "cat" 87 | ["NAME"]=> 88 | string(16) "Pook " 89 | [2]=> 90 | string(16) "Pook " 91 | ["WEIGHT"]=> 92 | string(4) "3.20" 93 | [3]=> 94 | string(4) "3.20" 95 | } 96 | array(8) { 97 | ["ID"]=> 98 | string(1) "6" 99 | [0]=> 100 | string(1) "6" 101 | ["BREED"]=> 102 | string(5) "llama" 103 | [1]=> 104 | string(5) "llama" 105 | ["NAME"]=> 106 | string(16) "Sweater " 107 | [2]=> 108 | string(16) "Sweater " 109 | ["WEIGHT"]=> 110 | string(6) "150.00" 111 | [3]=> 112 | string(6) "150.00" 113 | } 114 | array(8) { 115 | ["ID"]=> 116 | string(1) "1" 117 | [0]=> 118 | string(1) "1" 119 | ["BREED"]=> 120 | string(3) "dog" 121 | [1]=> 122 | string(3) "dog" 123 | ["NAME"]=> 124 | string(16) "Peaches " 125 | [2]=> 126 | string(16) "Peaches " 127 | ["WEIGHT"]=> 128 | string(5) "12.30" 129 | [3]=> 130 | string(5) "12.30" 131 | } 132 | array(8) { 133 | ["ID"]=> 134 | string(1) "2" 135 | [0]=> 136 | string(1) "2" 137 | ["BREED"]=> 138 | string(5) "horse" 139 | [1]=> 140 | string(5) "horse" 141 | ["NAME"]=> 142 | string(16) "Smarty " 143 | [2]=> 144 | string(16) "Smarty " 145 | ["WEIGHT"]=> 146 | string(6) "350.00" 147 | [3]=> 148 | string(6) "350.00" 149 | } 150 | -------------------------------------------------------------------------------- /tests/fvt_032_FailureErrCodes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error codes after a failed execution 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 14 | 15 | try { 16 | /* Drop the test table, in case it exists */ 17 | $drop = 'DROP TABLE test_error'; 18 | $result = $this->db->exec( $drop ); 19 | } catch( Exception $e ){} 20 | 21 | $this->db->exec("CREATE TABLE test_error (id INTEGER, data VARCHAR(50))"); 22 | 23 | echo "Begin\n"; 24 | $this->db->beginTransaction(); 25 | 26 | $stmt = $this->db->prepare("INSERT INTO test_error (id, data ) VALUES (?, ?)"); 27 | 28 | try { 29 | echo "Execute\n"; 30 | $res = $stmt->execute(array('a','b')); 31 | 32 | if($res) { 33 | echo "Commit\n"; 34 | $this->db->commit(); 35 | } else { 36 | $err = $stmt->errorInfo(); 37 | echo "Execute failed\n"; 38 | echo "$err[0]\n"; 39 | echo "$err[1]\n"; 40 | echo "$err[2]\n"; 41 | $this->db->rollBack(); 42 | } 43 | } catch(Exception $e) { 44 | $err = $stmt->errorInfo(); 45 | echo "Exception occured\n"; 46 | echo "$err[0]\n"; 47 | echo "$err[1]\n"; 48 | echo "$err[2]\n"; 49 | $this->db->rollBack(); 50 | } 51 | } 52 | } 53 | 54 | $testcase = new Test(); 55 | $testcase->runTest(); 56 | ?> 57 | --EXPECTF-- 58 | Begin 59 | Execute 60 | Exception occured 61 | 22005 62 | -99999 63 | [IBM][CLI Driver] CLI0112E Error in assignment. SQLSTATE=22005 (SQLExecute[-99999] at %s 64 | 65 | -------------------------------------------------------------------------------- /tests/fvt_032_V5V6_FailureErrCodes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error codes after a failed execution 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 14 | 15 | try { 16 | /* Drop the test table, in case it exists */ 17 | $drop = 'DROP TABLE test_error'; 18 | $result = $this->db->exec( $drop ); 19 | } catch( Exception $e ){} 20 | 21 | $this->db->exec("CREATE TABLE test_error (id INTEGER, data VARCHAR(50))"); 22 | 23 | echo "Begin\n"; 24 | $this->db->beginTransaction(); 25 | 26 | $stmt = $this->db->prepare("INSERT INTO test_error (id, data ) VALUES (?, ?)"); 27 | 28 | try { 29 | echo "Execute\n"; 30 | $res = $stmt->execute(array('a','b')); 31 | 32 | if($res) { 33 | echo "Commit\n"; 34 | $this->db->commit(); 35 | } else { 36 | $err = $stmt->errorInfo(); 37 | echo "Execute failed\n"; 38 | echo "$err[0]\n"; 39 | echo "$err[1]\n"; 40 | echo "$err[2]\n"; 41 | $this->db->rollBack(); 42 | } 43 | } catch(Exception $e) { 44 | $err = $stmt->errorInfo(); 45 | echo "Exception occured\n"; 46 | echo "$err[0]\n"; 47 | echo "$err[1]\n"; 48 | echo "$err[2]\n"; 49 | $this->db->rollBack(); 50 | } 51 | } 52 | } 53 | 54 | $testcase = new Test(); 55 | $testcase->runTest(); 56 | ?> 57 | --EXPECTF-- 58 | Begin 59 | Execute 60 | Exception occured 61 | 22018 62 | -420 63 | Character in CAST argument not valid. (SQLExecute[-420] %s 64 | -------------------------------------------------------------------------------- /tests/fvt_033_ErrNullConnParams.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error condition when given null connection parameters 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | user, $this->pass); 16 | } catch(Exception $e) { 17 | echo "Connection Failed\n"; 18 | echo $e->getMessage() . "\n\n"; 19 | } 20 | 21 | try { 22 | $my_null = NULL; 23 | $new_conn = new PDO($this->dsn, $my_null, $this->pass); 24 | } catch(Exception $e) { 25 | echo "Connection Failed\n"; 26 | echo $e->getMessage() . "\n"; 27 | } 28 | 29 | try { 30 | $my_null = NULL; 31 | $new_conn = new PDO($this->dsn, $this->user, $my_null); 32 | } catch(Exception $e) { 33 | echo "Connection Failed\n"; 34 | echo $e->getMessage(); 35 | } 36 | } 37 | } 38 | 39 | $testcase = new Test(); 40 | $testcase->runTest(); 41 | ?> 42 | --EXPECTF-- 43 | Connection Failed 44 | %s 45 | 46 | Connection Failed 47 | SQLSTATE=08001, SQL%sonnect: -30082 [%s][%s] SQL30082N Security processing failed with reason "%d" ("%s"). SQLSTATE=08001 48 | ISAM: 49 | Connection Failed 50 | SQLSTATE=08001, SQL%sonnect: -30082 [%s][%s] SQL30082N Security processing failed with reason "%d" ("%s"). SQLSTATE=08001 51 | ISAM: 52 | -------------------------------------------------------------------------------- /tests/fvt_033_V5V6_ErrNullConnParams.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error condition when given null connection parameters 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | user, $this->pass); 16 | } catch(Exception $e) { 17 | echo "Connection Failed\n"; 18 | echo $e->getMessage() . "\n\n"; 19 | } 20 | 21 | try { 22 | $my_null = " "; 23 | $new_conn = new PDO($this->dsn, $my_null, $this->pass); 24 | } catch(Exception $e) { 25 | echo "Connection Failed\n"; 26 | echo $e->getMessage() . "\n"; 27 | } 28 | 29 | try { 30 | $my_null = " "; 31 | $new_conn = new PDO($this->dsn, $this->user, $my_null); 32 | } catch(Exception $e) { 33 | echo "Connection Failed\n"; 34 | echo $e->getMessage(); 35 | } 36 | } 37 | } 38 | 39 | $testcase = new Test(); 40 | $testcase->runTest(); 41 | ?> 42 | --EXPECTF-- 43 | Connection Failed 44 | %s 45 | 46 | Connection Failed 47 | SQLSTATE=08001, SQLConnect: -30082 %s 48 | Connection Failed 49 | SQLSTATE=08001, SQLConnect: -30082 %s 50 | -------------------------------------------------------------------------------- /tests/fvt_034_ErrNonExistentTableInsert.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error condition when inserting into non-existent table 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | $myarr = array(array (10, "Java", 12, "Bean", 914.05)); 15 | $sql = "INSERT INTO doesnotexist VALUES(?, ?, ?, ?, ?, ?)"; 16 | $stmt = $this->db->prepare($sql); 17 | 18 | foreach ($myarr as $data) { 19 | if ($stmt->execute($data)) { 20 | echo "True\n"; 21 | } else { 22 | echo "False\n"; 23 | } 24 | } 25 | $stmt = null; 26 | } catch(exception $e) { 27 | print $e->getMessage(); 28 | } 29 | 30 | } 31 | } 32 | 33 | $testcase = new Test(); 34 | $testcase->runTest(); 35 | ?> 36 | --EXPECTF-- 37 | SQLSTATE[42S02]:%s-204 [%s][%s][%s] SQL0204N %s is an undefined name. SQLSTATE=42704 38 | %s 39 | -------------------------------------------------------------------------------- /tests/fvt_034_V5V6_ErrNonExistentTableInsert.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check error condition when inserting into non-existent table 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | $myarr = array(array (10, "Java", 12, "Bean", 914.05)); 15 | $sql = "INSERT INTO doesnotexist VALUES(?, ?, ?, ?, ?, ?)"; 16 | $stmt = $this->db->prepare($sql); 17 | 18 | foreach ($myarr as $data) { 19 | if ($stmt->execute($data)) { 20 | echo "True\n"; 21 | } else { 22 | echo "False\n"; 23 | } 24 | } 25 | $stmt = null; 26 | } catch(exception $e) { 27 | print $e->getMessage(); 28 | } 29 | 30 | } 31 | } 32 | 33 | $testcase = new Test(); 34 | $testcase->runTest(); 35 | ?> 36 | --EXPECTF-- 37 | SQLSTATE[42704]: Undefined object: -204 DOESNOTEXIST in %s (SQLPrepare[-204] %s 38 | -------------------------------------------------------------------------------- /tests/fvt_035_ExecReturnVal.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check return values from exec 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(false); 13 | 14 | try { 15 | $this->db->exec("DROP TABLE testExec"); 16 | } catch (Exception $e){} 17 | 18 | $sql = "CREATE TABLE testExec (id INTEGER)"; 19 | if ($this->db->exec($sql) === false) { 20 | echo "Did not work\n"; 21 | } else { 22 | echo "Worked\n"; 23 | } 24 | 25 | $this->db->exec("INSERT INTO testExec (id) values (1)"); 26 | 27 | $sql = "UPDATE testExec SET id = 5 WHERE id = 1"; 28 | if ($this->db->exec($sql) === false) { 29 | echo "Did not work\n"; 30 | } else { 31 | echo "Worked\n"; 32 | } 33 | 34 | $sql = "DELETE FROM testExec WHERE id = 1"; 35 | if ($this->db->exec($sql) === false) { 36 | echo "Did not work\n"; 37 | } else { 38 | echo "Worked\n"; 39 | } 40 | 41 | $this->db->exec("INSERT INTO testExec (id) values (2)"); 42 | $this->db->exec("INSERT INTO testExec (id) values (3)"); 43 | $this->db->exec("INSERT INTO testExec (id) values (4)"); 44 | 45 | $sql = "DELETE FROM testExec"; 46 | $rowCount = $this->db->exec($sql); 47 | echo "Row count: $rowCount"; 48 | } 49 | } 50 | 51 | $testcase = new Test(); 52 | $testcase->runTest(); 53 | ?> 54 | --EXPECTF-- 55 | Worked 56 | Worked 57 | Worked 58 | Row count: 4 59 | -------------------------------------------------------------------------------- /tests/fvt_036_SettingDiffOpt.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test the setting of different options 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | /* Set up */ 16 | try { 17 | $this->db->exec("DROP TABLE test"); 18 | } catch (Exception $e){} 19 | $this->db->exec("CREATE TABLE test (id INTEGER)"); 20 | $this->db->exec("INSERT INTO test values (1)"); 21 | $this->db->exec("INSERT INTO test values (2)"); 22 | $this->db->exec("INSERT INTO test values (3)"); 23 | $this->db->exec("INSERT INTO test values (4)"); 24 | $this->db->exec("INSERT INTO test values (5)"); 25 | 26 | /* Test ATTR_AUTOCOMMIT */ 27 | $this->db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); 28 | $this->db->beginTransaction(); 29 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | echo $res[0]."\n"; 32 | $this->db->exec( "DELETE FROM test" ); 33 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 34 | $res = $stmt->fetch( PDO::FETCH_NUM ); 35 | echo $res[0]."\n"; 36 | $this->db->rollBack(); 37 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 38 | $res = $stmt->fetch( PDO::FETCH_NUM ); 39 | echo $res[0]."\n"; 40 | 41 | /* Test ATTR_ERRMODE */ 42 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 43 | try { 44 | $this->db->exec("INSERT INTO nontest values (6)"); 45 | } catch (Exception $e) { 46 | echo "Failed: " . $e->getMessage() . "\n"; 47 | } 48 | 49 | /* Test ATTR_CASE */ 50 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); 51 | $stmt = $this->db->query( "SELECT id FROM test" ); 52 | $res = $stmt->fetch(); 53 | var_dump( $res ); 54 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); 55 | $stmt = $this->db->query( "SELECT id FROM test" ); 56 | $res = $stmt->fetch(); 57 | var_dump( $res ); 58 | 59 | /* Test ATTR_PERSISTENT */ 60 | $op = array(PDO::ATTR_PERSISTENT => true); 61 | $pdb = new PDO($this->dsn, $this->user, $this->pass, $op); 62 | var_dump($pdb); 63 | $pdb = null; 64 | $pdb = new PDO($this->dsn, $this->user, $this->pass, $op); 65 | var_dump($pdb); 66 | $pdb = null; 67 | } 68 | } 69 | 70 | $testcase = new Test(); 71 | $testcase->runTest(); 72 | ?> 73 | --EXPECTF-- 74 | 5 75 | 0 76 | 5 77 | Failed: %a 78 | array(2) { 79 | ["ID"]=> 80 | string(1) "1" 81 | [0]=> 82 | string(1) "1" 83 | } 84 | array(2) { 85 | ["id"]=> 86 | string(1) "1" 87 | [0]=> 88 | string(1) "1" 89 | } 90 | object(PDO)#%d (0) { 91 | } 92 | object(PDO)#%d (0) { 93 | } 94 | 95 | -------------------------------------------------------------------------------- /tests/fvt_036_V5V6_SettingDiffOpt.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Test the setting of different options 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | /* Set up */ 16 | try { 17 | $this->db->exec("DROP TABLE test"); 18 | } catch (Exception $e){} 19 | $this->db->exec("CREATE TABLE test (id INTEGER)"); 20 | $this->db->exec("INSERT INTO test values (1)"); 21 | $this->db->exec("INSERT INTO test values (2)"); 22 | $this->db->exec("INSERT INTO test values (3)"); 23 | $this->db->exec("INSERT INTO test values (4)"); 24 | $this->db->exec("INSERT INTO test values (5)"); 25 | 26 | /* Test ATTR_AUTOCOMMIT */ 27 | $this->db->setAttribute(PDO::ATTR_AUTOCOMMIT, false); 28 | $this->db->beginTransaction(); 29 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 30 | $res = $stmt->fetch( PDO::FETCH_NUM ); 31 | echo $res[0]."\n"; 32 | $this->db->exec( "DELETE FROM test" ); 33 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 34 | $res = $stmt->fetch( PDO::FETCH_NUM ); 35 | echo $res[0]."\n"; 36 | $this->db->rollBack(); 37 | $stmt = $this->db->query( "SELECT count(*) FROM test" ); 38 | $res = $stmt->fetch( PDO::FETCH_NUM ); 39 | echo $res[0]."\n"; 40 | 41 | /* Test ATTR_ERRMODE */ 42 | $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 43 | try { 44 | $this->db->exec("INSERT INTO nontest values (6)"); 45 | } catch (Exception $e) { 46 | echo "Failed: " . $e->getMessage() . "\n"; 47 | } 48 | 49 | /* Test ATTR_CASE */ 50 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); 51 | $stmt = $this->db->query( "SELECT id FROM test" ); 52 | $res = $stmt->fetch(); 53 | var_dump( $res ); 54 | $this->db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); 55 | $stmt = $this->db->query( "SELECT id FROM test" ); 56 | $res = $stmt->fetch(); 57 | var_dump( $res ); 58 | 59 | /* Test ATTR_PERSISTENT */ 60 | $op = array(PDO::ATTR_PERSISTENT => true); 61 | $pdb = new PDO($this->dsn, $this->user, $this->pass, $op); 62 | var_dump($pdb); 63 | $pdb = null; 64 | $pdb = new PDO($this->dsn, $this->user, $this->pass, $op); 65 | var_dump($pdb); 66 | $pdb = null; 67 | } 68 | } 69 | 70 | $testcase = new Test(); 71 | $testcase->runTest(); 72 | ?> 73 | --EXPECTF-- 74 | 5 75 | 0 76 | 5 77 | Failed: %s 78 | array(2) { 79 | ["ID"]=> 80 | string(1) "1" 81 | [0]=> 82 | string(1) "1" 83 | } 84 | array(2) { 85 | ["id"]=> 86 | string(1) "1" 87 | [0]=> 88 | string(1) "1" 89 | } 90 | object(PDO)#%d (0) { 91 | } 92 | object(PDO)#%d (0) { 93 | } 94 | 95 | -------------------------------------------------------------------------------- /tests/fvt_038_LastInsertID.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Testing the lastInsertID function. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | try { 14 | /* Drop the test table, in case it exists */ 15 | $drop = 'DROP TABLE animals'; 16 | $result = $this->db->exec( $drop ); 17 | } catch( Exception $e ){} 18 | try { 19 | /* Drop the test table, in case it exists */ 20 | $drop = 'DROP TABLE owner'; 21 | $result = $this->db->exec( $drop ); 22 | } catch( Exception $e ){} 23 | 24 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 25 | 26 | /* Create the test table */ 27 | $create = 'CREATE TABLE animals (id INTEGER, name varchar(20))'; 28 | $result = $this->db->exec( $create ); 29 | $stmt = $this->db->query( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 30 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 31 | 32 | $drop = 'DROP TABLE animals'; 33 | $result = $this->db->exec( $drop ); 34 | 35 | /* Create the test table */ 36 | $server_info = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 37 | if( strncmp( $server_info, "DB2", 3 ) == 0 ) 38 | { 39 | $create = 'CREATE TABLE animals (id integer GENERATED BY DEFAULT AS IDENTITY, 40 | name varchar(20))'; 41 | } 42 | else 43 | { 44 | $create = 'CREATE TABLE animals (id SERIAL, name varchar(20))'; 45 | } 46 | 47 | $result = $this->db->exec( $create ); 48 | $stmt = $this->db->exec( "INSERT INTO animals (name) VALUES ( 'dog' )" ); 49 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 50 | 51 | $sql = "select id from animals "; 52 | $stmt = $this->db->query($sql); 53 | $res = $stmt->fetch(); 54 | print_r($res); 55 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 56 | 57 | $stmt = $this->db->query( "INSERT INTO animals (id, name) VALUES ( 1147483647, 'dog' )" ); 58 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 59 | 60 | $stmt = $this->db->query( "INSERT INTO animals (name) VALUES ( 'dog' )" ); 61 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 62 | 63 | /* Create the test table */ 64 | if( strncmp( $server_info, "DB2", 3 ) == 0 ) 65 | { 66 | $create = 'CREATE TABLE owner (id integer, name varchar(20))'; 67 | } 68 | else 69 | { 70 | $create = 'CREATE TABLE owner (id SERIAL8, name varchar(20))'; 71 | } 72 | $result = $this->db->exec( $create ); 73 | $stmt = $this->db->query( "INSERT INTO owner (name) VALUES ( 'tom' )" ); 74 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 75 | 76 | $drop = 'DROP TABLE animals'; 77 | $result = $this->db->exec( $drop ); 78 | 79 | /* Create the test table */ 80 | $create = 'CREATE TABLE animals (id INTEGER, name varchar(20))'; 81 | $result = $this->db->exec( $create ); 82 | $stmt = $this->db->query( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 83 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 84 | 85 | $drop = 'DROP TABLE animals'; 86 | $result = $this->db->exec( $drop ); 87 | 88 | /* Create the test table */ 89 | if( strncmp( $server_info, "DB2", 3 ) == 0 ) 90 | { 91 | $create = 'CREATE TABLE animals (id integer GENERATED BY DEFAULT AS IDENTITY, 92 | name varchar(20))'; 93 | } 94 | else 95 | { 96 | $create = 'CREATE TABLE animals (id SERIAL, name varchar(20))'; 97 | } 98 | $result = $this->db->exec( $create ); 99 | $stmt = $this->db->prepare( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 100 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 101 | $stmt->execute(); 102 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 103 | 104 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 105 | print "Last Insert Id: " . $this->db->lastInsertId( "INSERT INTO animals ( id, name ) 106 | VALUES ( 2, 'dog' )" ) . "\n" ; 107 | $stmt->closeCursor(); 108 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 109 | $stmt = $this->db->prepare( "INSERT INTO animals ( id, name ) VALUES ( 2, 'dog' )" ); 110 | $stmt->closeCursor(); 111 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 112 | print "Last Insert Id: " . $this->db->lastInsertId( null ); 113 | 114 | } 115 | } 116 | $testcase = new Test(); 117 | $testcase->runTest(); 118 | ?> 119 | --EXPECTREGEX-- 120 | (Last Insert Id: 0 121 | Last Insert Id: 0 122 | Last Insert Id: 1 123 | Array 124 | \( 125 | \[ID\] => 1 126 | \[0\] => 1 127 | \) 128 | Last Insert Id: 1 129 | Last Insert Id: 1147483647 130 | Last Insert Id: 1147483648 131 | Last Insert Id: 1147483648 132 | Last Insert Id: 1147483648 133 | Last Insert Id: 1147483648 134 | Last Insert Id: 1 135 | Last Insert Id: 1 136 | Last Insert Id: 1 137 | Last Insert Id: 1 138 | Last Insert Id: 1 139 | Last Insert Id: 1)|(Last Insert Id: 0 140 | Last Insert Id: 0 141 | Last Insert Id: 1 142 | Array 143 | \( 144 | \[ID\] => 1 145 | \[0\] => 1 146 | \) 147 | Last Insert Id: 1 148 | Last Insert Id: 1147483647 149 | Last Insert Id: 2 150 | Last Insert Id: 2 151 | Last Insert Id: 2 152 | Last Insert Id: 2 153 | Last Insert Id: 1 154 | Last Insert Id: 1 155 | Last Insert Id: 1 156 | Last Insert Id: 1 157 | Last Insert Id: 1 158 | Last Insert Id: 1) 159 | -------------------------------------------------------------------------------- /tests/fvt_038_V5V6_LastInsertID.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Testing the lastInsertID function. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | try { 14 | /* Drop the test table, in case it exists */ 15 | $drop = 'DROP TABLE animals'; 16 | $result = $this->db->exec( $drop ); 17 | } catch( Exception $e ){} 18 | try { 19 | /* Drop the test table, in case it exists */ 20 | $drop = 'DROP TABLE owner'; 21 | $result = $this->db->exec( $drop ); 22 | } catch( Exception $e ){} 23 | 24 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 25 | 26 | /* Create the test table */ 27 | $create = 'CREATE TABLE animals (id INTEGER, name varchar(20))'; 28 | $result = $this->db->exec( $create ); 29 | $stmt = $this->db->query( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 30 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 31 | 32 | $drop = 'DROP TABLE animals'; 33 | $result = $this->db->exec( $drop ); 34 | 35 | /* Create the test table */ 36 | $server_info = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 37 | if( strncmp( $server_info, "DB2", 3 ) == 0 38 | || strncmp( $server_info, "AS", 2 ) == 0 39 | || strncmp( $server_info, "QSQ", 3 ) == 0 ) 40 | { 41 | $create = 'CREATE TABLE animals (id integer GENERATED BY DEFAULT AS IDENTITY, 42 | name varchar(20))'; 43 | } 44 | else 45 | { 46 | $create = 'CREATE TABLE animals (id SERIAL, name varchar(20))'; 47 | } 48 | 49 | $result = $this->db->exec( $create ); 50 | $stmt = $this->db->exec( "INSERT INTO animals (name) VALUES ( 'dog' )" ); 51 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 52 | 53 | $sql = "select id from animals "; 54 | $stmt = $this->db->query($sql); 55 | $res = $stmt->fetch(); 56 | print_r($res); 57 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 58 | 59 | $stmt = $this->db->query( "INSERT INTO animals (id, name) VALUES ( 1147483647, 'dog' )" ); 60 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 61 | 62 | $stmt = $this->db->query( "INSERT INTO animals (name) VALUES ( 'dog' )" ); 63 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n"; 64 | 65 | /* Create the test table */ 66 | if( strncmp( $server_info, "DB2", 3 ) == 0 67 | || strncmp( $server_info, "AS", 2 ) == 0 68 | || strncmp( $server_info, "QSQ", 3 ) == 0 ) 69 | { 70 | $create = 'CREATE TABLE owner (id integer, name varchar(20))'; 71 | } 72 | else 73 | { 74 | $create = 'CREATE TABLE owner (id SERIAL8, name varchar(20))'; 75 | } 76 | $result = $this->db->exec( $create ); 77 | $stmt = $this->db->query( "INSERT INTO owner (name) VALUES ( 'tom' )" ); 78 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 79 | 80 | $drop = 'DROP TABLE animals'; 81 | $result = $this->db->exec( $drop ); 82 | 83 | /* Create the test table */ 84 | $create = 'CREATE TABLE animals (id INTEGER, name varchar(20))'; 85 | $result = $this->db->exec( $create ); 86 | $stmt = $this->db->query( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 87 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 88 | 89 | $drop = 'DROP TABLE animals'; 90 | $result = $this->db->exec( $drop ); 91 | 92 | /* Create the test table */ 93 | if( strncmp( $server_info, "DB2", 3 ) == 0 94 | || strncmp( $server_info, "AS", 2 ) == 0 95 | || strncmp( $server_info, "QSQ", 3 ) == 0 ) 96 | { 97 | $create = 'CREATE TABLE animals (id integer GENERATED BY DEFAULT AS IDENTITY, 98 | name varchar(20))'; 99 | } 100 | else 101 | { 102 | $create = 'CREATE TABLE animals (id SERIAL, name varchar(20))'; 103 | } 104 | $result = $this->db->exec( $create ); 105 | $stmt = $this->db->prepare( "INSERT INTO animals ( id, name ) VALUES ( 1, 'dog' )" ); 106 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 107 | $stmt->execute(); 108 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 109 | 110 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 111 | print "Last Insert Id: " . $this->db->lastInsertId( "INSERT INTO animals ( id, name ) 112 | VALUES ( 2, 'dog' )" ) . "\n" ; 113 | $stmt->closeCursor(); 114 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 115 | $stmt = $this->db->prepare( "INSERT INTO animals ( id, name ) VALUES ( 2, 'dog' )" ); 116 | $stmt->closeCursor(); 117 | print "Last Insert Id: " . $this->db->lastInsertId() . "\n" ; 118 | print "Last Insert Id: " . $this->db->lastInsertId( null ); 119 | 120 | } 121 | } 122 | $testcase = new Test(); 123 | $testcase->runTest(); 124 | ?> 125 | --EXPECTREGEX-- 126 | (Last Insert Id: 0 127 | Last Insert Id: 0 128 | Last Insert Id: 1 129 | Array 130 | \( 131 | \[ID\] => 1 132 | \[0\] => 1 133 | \) 134 | Last Insert Id: 1 135 | Last Insert Id: 1147483647 136 | Last Insert Id: 1147483648 137 | Last Insert Id: 1147483648 138 | Last Insert Id: 1147483648 139 | Last Insert Id: 1147483648 140 | Last Insert Id: 1 141 | Last Insert Id: 1 142 | Last Insert Id: 1 143 | Last Insert Id: 1 144 | Last Insert Id: 1 145 | Last Insert Id: 1)|(Last Insert Id: 0 146 | Last Insert Id: 0 147 | Last Insert Id: 1 148 | Array 149 | \( 150 | \[ID\] => 1 151 | \[0\] => 1 152 | \) 153 | Last Insert Id: 1 154 | Last Insert Id: 1147483647 155 | Last Insert Id: 2 156 | Last Insert Id: 2 157 | Last Insert Id: 2 158 | Last Insert Id: 2 159 | Last Insert Id: 1 160 | Last Insert Id: 1 161 | Last Insert Id: 1 162 | Last Insert Id: 1 163 | Last Insert Id: 1 164 | Last Insert Id: 1) 165 | -------------------------------------------------------------------------------- /tests/fvt_040_ServerInfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Get the server info. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $result = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 14 | echo "Server Info: $result\n"; 15 | if ($result = NULL) { 16 | echo "Result is NULL...bad\n"; 17 | } 18 | } 19 | } 20 | 21 | $testcase = new Test(); 22 | $testcase->runTest(); 23 | ?> 24 | --EXPECTREGEX-- 25 | (Server Info: DB2.+)|(Server Info: IDS.+) 26 | -------------------------------------------------------------------------------- /tests/fvt_040_V5V6_ServerInfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Get the server info. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $result = $this->db->getAttribute(PDO::ATTR_SERVER_INFO); 14 | echo "Server Info: $result\n"; 15 | if ($result = NULL) { 16 | echo "Result is NULL...bad\n"; 17 | } 18 | } 19 | } 20 | 21 | $testcase = new Test(); 22 | $testcase->runTest(); 23 | ?> 24 | --EXPECTREGEX-- 25 | (Server Info: DB2.+)|(Server Info: IDS.+)|Server Info: QSQ|Server Info: AS 26 | -------------------------------------------------------------------------------- /tests/fvt_49872_ClearingErrCodes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check the clearing of error codes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $sql = "selec id from animals "; 25 | try { 26 | $stmt = $this->db->query($sql); 27 | } catch ( Exception $e) {} 28 | 29 | $sql = "select id from animals "; 30 | $stmt = $this->db->query($sql); 31 | print_r($this->db->errorInfo()); 32 | 33 | $res = $stmt->fetch(); 34 | print_r($res); 35 | } 36 | } 37 | 38 | $testcase = new Test(); 39 | $testcase->runTest(); 40 | ?> 41 | --EXPECT-- 42 | Array 43 | ( 44 | [0] => 00000 45 | [1] => 46 | [2] => 47 | ) 48 | -------------------------------------------------------------------------------- /tests/fvt_49872_V5V6_ClearingErrCodes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Check the clearing of error codes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* Create the test table */ 21 | $create = 'CREATE TABLE animals (id INTEGER)'; 22 | $result = $this->db->exec( $create ); 23 | 24 | $sql = "selec id from animals "; 25 | try { 26 | $stmt = $this->db->query($sql); 27 | } catch ( Exception $e) {} 28 | 29 | $sql = "select id from animals "; 30 | $stmt = $this->db->query($sql); 31 | print_r($this->db->errorInfo()); 32 | 33 | $res = $stmt->fetch(); 34 | print_r($res); 35 | } 36 | } 37 | 38 | $testcase = new Test(); 39 | $testcase->runTest(); 40 | ?> 41 | --EXPECT-- 42 | Array 43 | ( 44 | [0] => 00000 45 | [1] => 46 | [2] => 47 | ) 48 | 49 | -------------------------------------------------------------------------------- /tests/fvt_66610_V6_stored_proc_io_char.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try more complex in/out stored proc call 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | try { 12 | $create = "DROP PROCEDURE lotchar\n"; 13 | $result = $this->db->exec( $create ); 14 | } catch( Exception $e ) {} 15 | try { 16 | $create = "CREATE PROCEDURE lotchar(\n"; 17 | $create .= " INOUT V1 VARCHAR(128),\n"; 18 | $create .= " INOUT V2 CHAR(128))\n"; 19 | $create .= " LANGUAGE SQL\n"; 20 | $create .= "BEGIN\n"; 21 | $create .= "SET V1 = V2;\n"; 22 | $create .= "SET V2 = 'TRUE i was replaced with longer string';\n"; 23 | $create .= "END\n"; 24 | $result = $this->db->exec( $create ); 25 | $v1 = "hi from v1"; 26 | $v2 = "hi from v2"; 27 | $stmt = $this->db->prepare('call lotchar(?,?)'); 28 | /* 29 | echo getmypid(); 30 | sleep(30); 31 | */ 32 | $r1 = $stmt->bindParam(1,$v1, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 33 | $r2 = $stmt->bindParam(2,$v2, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 34 | $rc = $stmt->execute(); 35 | print $v1."\n"; 36 | print $v2."\n"; 37 | print "done\n"; 38 | } catch( Exception $e ) { 39 | $err = $this->db->errorInfo(); 40 | $cod = $this->db->errorCode(); 41 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 42 | } 43 | } /* runTest */ 44 | } 45 | $testcase = new Test(); 46 | $testcase->runTest(); 47 | ?> 48 | --EXPECTF-- 49 | hi from v2 50 | TRUE i was replaced with longer string%s 51 | done 52 | 53 | -------------------------------------------------------------------------------- /tests/fvt_66620_V6_stored_proc_io_int.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try more complex in/out stored proc call 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | try { 12 | $create = "DROP PROCEDURE lotint\n"; 13 | $result = $this->db->exec( $create ); 14 | } catch( Exception $e ) {} 15 | try { 16 | $create = "CREATE PROCEDURE lotint(\n"; 17 | $create .= " INOUT V1 SMALLINT,\n"; 18 | $create .= " INOUT V2 INTEGER,\n"; 19 | $create .= " INOUT V3 BIGINT)\n"; 20 | $create .= " LANGUAGE SQL\n"; 21 | $create .= "BEGIN\n"; 22 | $create .= "SET V1 = V1 + 42;\n"; 23 | $create .= "SET V2 = V2 + 42;\n"; 24 | $create .= "SET V3 = V3 + 42;\n"; 25 | $create .= "END\n"; 26 | $result = $this->db->exec( $create ); 27 | $v1 = 1; 28 | $v2 = 2; 29 | $v3 = 3; 30 | $stmt = $this->db->prepare('call lotint(?,?,?)'); 31 | /* 32 | echo getmypid(); 33 | sleep(30); 34 | */ 35 | $r1 = $stmt->bindParam(1,$v1, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT); 36 | $r2 = $stmt->bindParam(2,$v2, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT); 37 | $r3 = $stmt->bindParam(3,$v3, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT); 38 | $rc = $stmt->execute(); 39 | print $v1."\n"; 40 | print $v2."\n"; 41 | print $v3."\n"; 42 | print "done\n"; 43 | } catch( Exception $e ) { 44 | $err = $this->db->errorInfo(); 45 | $cod = $this->db->errorCode(); 46 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 47 | } 48 | } /* runTest */ 49 | } 50 | $testcase = new Test(); 51 | $testcase->runTest(); 52 | ?> 53 | --EXPECTF-- 54 | 43 55 | 44 56 | 45 57 | done 58 | -------------------------------------------------------------------------------- /tests/fvt_66630_V6_stored_proc_io_real.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try more complex in/out stored proc call 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | try { 12 | $create = "DROP PROCEDURE lotfloat\n"; 13 | $result = $this->db->exec( $create ); 14 | } catch( Exception $e ) {} 15 | try { 16 | $create = "CREATE PROCEDURE lotfloat(\n"; 17 | $create .= " INOUT V1 FLOAT(4),\n"; 18 | $create .= " INOUT V2 FLOAT(8),\n"; 19 | $create .= " INOUT V3 REAL,\n"; 20 | $create .= " INOUT V4 DOUBLE)\n"; 21 | $create .= " LANGUAGE SQL\n"; 22 | $create .= "BEGIN\n"; 23 | $create .= "SET V1 = V1 + 42.42;\n"; 24 | $create .= "SET V2 = V2 + 42.42;\n"; 25 | $create .= "SET V3 = V3 + 43.43;\n"; 26 | $create .= "SET V4 = V4 + 44.44;\n"; 27 | $create .= "END\n"; 28 | $result = $this->db->exec( $create ); 29 | $v1 = 1.1; 30 | $v2 = 2.2; 31 | $stmt = $this->db->prepare('call lotfloat(?,?,?,?)'); 32 | /* 33 | echo getmypid(); 34 | sleep(30); 35 | */ 36 | $r1 = $stmt->bindParam(1,$v1, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 37 | $r2 = $stmt->bindParam(2,$v2, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 38 | $r3 = $stmt->bindParam(3,$v3, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 39 | $r4 = $stmt->bindParam(4,$v4, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 40 | $rc = $stmt->execute(); 41 | print round($v1, 2)."\n"; 42 | print round($v2, 2)."\n"; 43 | print round($v3, 2)."\n"; 44 | print round($v4, 2)."\n"; 45 | print "done\n"; 46 | } catch( Exception $e ) { 47 | $err = $this->db->errorInfo(); 48 | $cod = $this->db->errorCode(); 49 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 50 | } 51 | } /* runTest */ 52 | } 53 | $testcase = new Test(); 54 | $testcase->runTest(); 55 | ?> 56 | --EXPECTF-- 57 | 43.52 58 | 44.62 59 | 43.43 60 | 44.44 61 | done 62 | 63 | -------------------------------------------------------------------------------- /tests/fvt_66640_V6_stored_proc_io_dec.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try more complex in/out stored proc call 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | try { 12 | $create = "DROP PROCEDURE lotfloat\n"; 13 | $result = $this->db->exec( $create ); 14 | } catch( Exception $e ) {} 15 | try { 16 | $create = "CREATE PROCEDURE lotfloat(\n"; 17 | $create .= " INOUT V1 DECIMAL(12,2),\n"; 18 | $create .= " INOUT V2 NUMERIC(12,2))\n"; 19 | $create .= " LANGUAGE SQL\n"; 20 | $create .= "BEGIN\n"; 21 | $create .= "SET V1 = V1 + 42.42;\n"; 22 | $create .= "SET V2 = V2 + 42.42;\n"; 23 | $create .= "END\n"; 24 | $result = $this->db->exec( $create ); 25 | $v1 = 1.1; 26 | $v2 = 2.2; 27 | $stmt = $this->db->prepare('call lotfloat(?,?)'); 28 | /* 29 | echo getmypid(); 30 | sleep(30); 31 | */ 32 | $r1 = $stmt->bindParam(1,$v1, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 33 | $r2 = $stmt->bindParam(2,$v2, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 34 | $rc = $stmt->execute(); 35 | print $v1."\n"; 36 | print $v2."\n"; 37 | print "done\n"; 38 | } catch( Exception $e ) { 39 | $err = $this->db->errorInfo(); 40 | $cod = $this->db->errorCode(); 41 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 42 | } 43 | } /* runTest */ 44 | } 45 | $testcase = new Test(); 46 | $testcase->runTest(); 47 | ?> 48 | --EXPECTF-- 49 | 43.52 50 | 44.62 51 | done 52 | 53 | -------------------------------------------------------------------------------- /tests/fvt_66699_V6_xmlservice.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try more complex in/out stored proc call 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 11 | try { 12 | $stmt = $this->db->prepare('call xmlservice.iplug512K(?,?,?,?)'); 13 | $ipc = "na"; 14 | $ctl = "*here"; 15 | $xmlIn = $this->ZZARRAY2(); 16 | $xmlOut = ""; 17 | /* 18 | echo getmypid(); 19 | sleep(30); 20 | */ 21 | $r1 = $stmt->bindParam(1,$ipc, PDO::PARAM_STR); 22 | $r2 = $stmt->bindParam(2,$ctl, PDO::PARAM_STR); 23 | $r3 = $stmt->bindParam(3,$xmlIn, PDO::PARAM_STR); 24 | $r4 = $stmt->bindParam(4,$xmlOut, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT); 25 | $rc = $stmt->execute(); 26 | print $xmlOut; 27 | print "\ndone\n"; 28 | } catch( Exception $e ) { 29 | $err = $this->db->errorInfo(); 30 | $cod = $this->db->errorCode(); 31 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 32 | } 33 | } 34 | public function ZZARRAY2() { 35 | // XXX: This shouldn't hardcode the xmlservice library. 36 | // But it does use test programs not in the system xmlservice distribution... 37 | $clob = << 39 | 61 | ENDPROC; 62 | return $clob; 63 | } 64 | } 65 | 66 | $testcase = new Test(); 67 | $testcase->runTest(); 68 | ?> 69 | --EXPECTF-- 70 | 71 | 119 | done 120 | 121 | -------------------------------------------------------------------------------- /tests/fvt_77710_V6_system_naming_libchar.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try system naming *LIBL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(true,true,PDO::I5_TXN_NO_COMMIT); 15 | 16 | /* This is odd, yes? 17 | try { 18 | $libl = "select current path from sysibm.sysdummy1"; 19 | $stmt = $this->db->query( $libl ); 20 | print("$libl\n"); 21 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 22 | print($row[0]); 23 | print("\n"); 24 | } 25 | } catch( Exception $e ) { } 26 | */ 27 | 28 | try { 29 | $libl = "select current schema from sysibm.sysdummy1"; 30 | $stmt = $this->db->query( $libl ); 31 | print("$libl\n"); 32 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 33 | print($row[0]); 34 | print("\n"); 35 | } 36 | } catch( Exception $e ) { } 37 | 38 | try { 39 | $create = "DROP TABLE liblchar\n"; 40 | //print("$create\n"); 41 | $result = $this->db->query( $create ); 42 | } catch( Exception $e ) { } 43 | try { 44 | $create = "CREATE TABLE liblchar(\n"; 45 | $create .= " V1 VARCHAR(128),\n"; 46 | $create .= " V2 CHAR(128),\n"; 47 | $create .= " N1 VARCHAR(128),\n"; 48 | $create .= " N2 CHAR(128),\n"; 49 | $create .= " E1 VARCHAR(128),\n"; 50 | $create .= " E2 CHAR(128))\n"; 51 | //print("$create\n"); 52 | $result = $this->db->query( $create ); 53 | } catch( Exception $e ) { 54 | $err = $this->db->errorInfo(); 55 | $cod = $this->db->errorCode(); 56 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 57 | } 58 | try { 59 | $v1 = "hi from v1"; 60 | $v2 = "hi from v2"; 61 | $n1 = null; 62 | $n2 = null; 63 | $e1 = ""; 64 | $e2 = ""; 65 | $callme = "insert into liblchar (v1,v2,n1,n2,e1,e2) values (?,?,?,?,?,?)"; 66 | //print("$callme\n"); 67 | $stmt = $this->db->prepare($callme); 68 | $r1 = $stmt->bindParam(1,$v1); 69 | $r2 = $stmt->bindParam(2,$v2); 70 | $r3 = $stmt->bindParam(3,$n1); 71 | $r4 = $stmt->bindParam(4,$n2); 72 | $r5 = $stmt->bindParam(5,$e1); 73 | $r6 = $stmt->bindParam(6,$e2); 74 | $rc = $stmt->execute(); 75 | $v1 = "hi from v1"; 76 | $v2 = "hi from v2"; 77 | $n1 = null; 78 | $n2 = null; 79 | $e1 = ""; 80 | $e2 = ""; 81 | $rc = $stmt->execute(array($v1,$v2,$n1,$n2,$e1,$e2)); 82 | } catch( Exception $e ) { 83 | $err = $this->db->errorInfo(); 84 | $cod = $this->db->errorCode(); 85 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 86 | } 87 | try { 88 | $readme = "SELECT * FROM liblchar"; 89 | print("$readme\n"); 90 | $stmt = $this->db->query( $readme ); 91 | while ($res = $stmt->fetch( PDO::FETCH_BOTH )) { 92 | $v1 = $res[0]; 93 | $v2 = trim($res[1]); 94 | $n1 = $res[2]; 95 | $n2 = trim($res[3]); 96 | $e1 = $res[4]; 97 | $e2 = trim($res[5]); 98 | print "String contents: ($v1,$v2,$n1,$n2,$e1,$e2)\n"; 99 | } 100 | } catch( Exception $e ) { 101 | $err = $this->db->errorInfo(); 102 | $cod = $this->db->errorCode(); 103 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 104 | } 105 | 106 | try { 107 | $readme = "SELECT hex(v1),hex(v2),hex(n1),hex(n2),hex(e1),hex(e2) FROM liblchar"; 108 | print("$readme\n"); 109 | $stmt = $this->db->query( $readme ); 110 | while ($res = $stmt->fetch( PDO::FETCH_BOTH )) { 111 | $v1 = $res[0]."."; 112 | $v2 = substr($res[1],0,40)."..."; 113 | $n1 = $res[2]."."; 114 | $n2 = substr($res[3],0,40)."..."; 115 | $e1 = $res[4]."."; 116 | $e2 = substr($res[5],0,40)."..."; 117 | print "HEX:\nv1=$v1\nv2=$v2\nn1=$n1\nn2=$n2\ne1=$e1\ne2=$e2\n"; 118 | } 119 | } catch( Exception $e ) { 120 | $err = $this->db->errorInfo(); 121 | $cod = $this->db->errorCode(); 122 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 123 | } 124 | 125 | } /* runTest */ 126 | } 127 | $testcase = new Test(); 128 | $testcase->runTest(); 129 | ?> 130 | --EXPECTF-- 131 | %s 132 | *LIBL 133 | %s 134 | String contents: (hi from v1,hi from v2,,,,) 135 | String contents: (hi from v1,hi from v2,,,,) 136 | SELECT hex(v1),hex(v2),hex(n1),hex(n2),hex(e1),hex(e2) FROM liblchar 137 | %s 138 | v1=8889408699969440A5F1. 139 | v2=8889408699969440A5F240404040404040404040... 140 | n1=. 141 | n2=... 142 | e1=. 143 | e2=4040404040404040404040404040404040404040... 144 | %s 145 | v1=8889408699969440A5F1. 146 | v2=8889408699969440A5F240404040404040404040... 147 | n1=. 148 | n2=... 149 | e1=. 150 | e2=4040404040404040404040404040404040404040... 151 | 152 | 153 | -------------------------------------------------------------------------------- /tests/fvt_77720_V6_system_naming_libint.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try system naming *LIBL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(true,true,PDO::I5_TXN_NO_COMMIT); 15 | 16 | /* This is odd, yes? 17 | try { 18 | $libl = "select current path from sysibm.sysdummy1"; 19 | $stmt = $this->db->query( $libl ); 20 | print("$libl\n"); 21 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 22 | print($row[0]); 23 | print("\n"); 24 | } 25 | } catch( Exception $e ) { } 26 | */ 27 | 28 | try { 29 | $libl = "select current schema from sysibm.sysdummy1"; 30 | $stmt = $this->db->query( $libl ); 31 | print("$libl\n"); 32 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 33 | print($row[0]); 34 | print("\n"); 35 | } 36 | } catch( Exception $e ) { } 37 | 38 | try { 39 | $create = "DROP TABLE libint\n"; 40 | //print("$create\n"); 41 | $result = $this->db->query( $create ); 42 | } catch( Exception $e ) { } 43 | try { 44 | $create = "CREATE TABLE libint(\n"; 45 | $create .= " V1 SMALLINT,\n"; 46 | $create .= " V2 INTEGER,\n"; 47 | $create .= " V3 BIGINT,\n"; 48 | $create .= " N1 SMALLINT,\n"; 49 | $create .= " N2 INTEGER,\n"; 50 | $create .= " N3 BIGINT,\n"; 51 | $create .= " E1 SMALLINT,\n"; 52 | $create .= " E2 INTEGER,\n"; 53 | $create .= " E3 BIGINT)\n"; 54 | //print("$create\n"); 55 | $result = $this->db->query( $create ); 56 | } catch( Exception $e ) { 57 | $err = $this->db->errorInfo(); 58 | $cod = $this->db->errorCode(); 59 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 60 | } 61 | try { 62 | $v1 = 1; 63 | $v2 = 2; 64 | $v3 = 3; 65 | $n1 = null; 66 | $n2 = null; 67 | $n3 = null; 68 | $e1 = ""; 69 | $e2 = ""; 70 | $e3 = ""; 71 | $callme = "insert into libint (v1,v2,v3,n1,n2,n3,e1,e2,e3) values (?,?,?,?,?,?,?,?,?)"; 72 | //print("$callme\n"); 73 | $stmt = $this->db->prepare($callme); 74 | $r1 = $stmt->bindParam(1,$v1); 75 | $r2 = $stmt->bindParam(2,$v2); 76 | $r3 = $stmt->bindParam(3,$v3); 77 | $r4 = $stmt->bindParam(4,$n1); 78 | $r5 = $stmt->bindParam(5,$n2); 79 | $r6 = $stmt->bindParam(6,$n3); 80 | $r7 = $stmt->bindParam(7,$e1); 81 | $r8 = $stmt->bindParam(8,$e2); 82 | $r9 = $stmt->bindParam(9,$e3); 83 | $rc = $stmt->execute(); 84 | $v1 = 1; 85 | $v2 = 2; 86 | $v3 = 3; 87 | $n1 = null; 88 | $n2 = null; 89 | $n3 = null; 90 | $e1 = ""; 91 | $e2 = ""; 92 | $e3 = ""; 93 | $rc = $stmt->execute(array($v1,$v2,$v3,$n1,$n2,$n3,$e1,$e2,$e3)); 94 | } catch( Exception $e ) { 95 | $err = $this->db->errorInfo(); 96 | $cod = $this->db->errorCode(); 97 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 98 | } 99 | try { 100 | $readme = "SELECT * FROM libint"; 101 | print("$readme\n"); 102 | $stmt = $this->db->query( $readme ); 103 | while ($res = $stmt->fetch( PDO::FETCH_BOTH )) { 104 | $v1 = $res[0]; 105 | $v2 = $res[1]; 106 | $v3 = $res[2]; 107 | $n1 = $res[3]; 108 | $n2 = $res[4]; 109 | $n3 = $res[5]; 110 | $e1 = $res[6]; 111 | $e2 = $res[7]; 112 | $e3 = $res[8]; 113 | print "Int contents: ($v1,$v2,$v3,$n1,$n2,$n3,$e1,$e2,$e3)\n"; 114 | } 115 | } catch( Exception $e ) { 116 | $err = $this->db->errorInfo(); 117 | $cod = $this->db->errorCode(); 118 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 119 | } 120 | 121 | } /* runTest */ 122 | } 123 | $testcase = new Test(); 124 | $testcase->runTest(); 125 | ?> 126 | --EXPECTF-- 127 | %s 128 | *LIBL 129 | %s 130 | Int contents: (1,2,3,,,,,,) 131 | Int contents: (1,2,3,,,,,,) 132 | 133 | -------------------------------------------------------------------------------- /tests/fvt_77730_V6_system_naming_libreal.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try system naming *LIBL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(true,true,PDO::I5_TXN_NO_COMMIT); 15 | 16 | /* This is odd, yes? 17 | try { 18 | $libl = "select current path from sysibm.sysdummy1"; 19 | $stmt = $this->db->query( $libl ); 20 | print("$libl\n"); 21 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 22 | print($row[0]); 23 | print("\n"); 24 | } 25 | } catch( Exception $e ) { } 26 | */ 27 | 28 | try { 29 | $libl = "select current schema from sysibm.sysdummy1"; 30 | $stmt = $this->db->query( $libl ); 31 | print("$libl\n"); 32 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 33 | print($row[0]); 34 | print("\n"); 35 | } 36 | } catch( Exception $e ) { } 37 | 38 | try { 39 | $create = "DROP TABLE libreal\n"; 40 | //print("$create\n"); 41 | $result = $this->db->query( $create ); 42 | } catch( Exception $e ) { } 43 | try { 44 | $create = "CREATE TABLE libreal(\n"; 45 | $create .= " V1 FLOAT(4),\n"; 46 | $create .= " V2 FLOAT(8),\n"; 47 | $create .= " V3 REAL,\n"; 48 | $create .= " V4 DOUBLE,\n"; 49 | $create .= " N1 FLOAT(4),\n"; 50 | $create .= " N2 FLOAT(8),\n"; 51 | $create .= " N3 REAL,\n"; 52 | $create .= " N4 DOUBLE,\n"; 53 | $create .= " E1 FLOAT(4),\n"; 54 | $create .= " E2 FLOAT(8),\n"; 55 | $create .= " E3 REAL,\n"; 56 | $create .= " E4 DOUBLE)\n"; 57 | //print("$create\n"); 58 | $result = $this->db->query( $create ); 59 | } catch( Exception $e ) { 60 | $err = $this->db->errorInfo(); 61 | $cod = $this->db->errorCode(); 62 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 63 | } 64 | try { 65 | $v1 = 1.1; 66 | $v2 = 2.2; 67 | $v3 = 3.3; 68 | $v4 = 4.4; 69 | $n1 = null; 70 | $n2 = null; 71 | $n3 = null; 72 | $n4 = null; 73 | $e1 = ""; 74 | $e2 = ""; 75 | $e3 = ""; 76 | $e4 = ""; 77 | $callme = "insert into libreal (v1,v2,v3,v4,n1,n2,n3,n4,e1,e2,e3,e4) values (?,?,?,?,?,?,?,?,?,?,?,?)"; 78 | //print("$callme\n"); 79 | $stmt = $this->db->prepare($callme); 80 | $r1 = $stmt->bindParam(1,$v1); 81 | $r2 = $stmt->bindParam(2,$v2); 82 | $r3 = $stmt->bindParam(3,$v3); 83 | $r4 = $stmt->bindParam(4,$v4); 84 | $r5 = $stmt->bindParam(5,$n1); 85 | $r6 = $stmt->bindParam(6,$n2); 86 | $r7 = $stmt->bindParam(7,$n3); 87 | $r8 = $stmt->bindParam(8,$n4); 88 | $r9 = $stmt->bindParam(9,$e1); 89 | $r10 = $stmt->bindParam(10,$e2); 90 | $r11 = $stmt->bindParam(11,$e3); 91 | $r12 = $stmt->bindParam(12,$e4); 92 | $rc = $stmt->execute(); 93 | $v1 = 1.1; 94 | $v2 = 2.2; 95 | $v3 = 3.3; 96 | $v4 = 4.4; 97 | $n1 = null; 98 | $n2 = null; 99 | $n3 = null; 100 | $n4 = null; 101 | $e1 = ""; 102 | $e2 = ""; 103 | $e3 = ""; 104 | $e4 = ""; 105 | $rc = $stmt->execute(array($v1,$v2,$v3,$v4,$n1,$n2,$n3,$n4,$e1,$e2,$e3,$e4)); 106 | } catch( Exception $e ) { 107 | $err = $this->db->errorInfo(); 108 | $cod = $this->db->errorCode(); 109 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 110 | } 111 | try { 112 | $readme = "SELECT * FROM libreal"; 113 | print("$readme\n"); 114 | $stmt = $this->db->query( $readme ); 115 | while ($res = $stmt->fetch( PDO::FETCH_BOTH )) { 116 | $v1 = $res[0]; 117 | $v2 = $res[1]; 118 | $v3 = $res[2]; 119 | $v4 = $res[3]; 120 | $n1 = $res[4]; 121 | $n2 = $res[5]; 122 | $n3 = $res[6]; 123 | $n4 = $res[7]; 124 | $e1 = $res[8]; 125 | $e2 = $res[9]; 126 | $e3 = $res[10]; 127 | $e4 = $res[11]; 128 | print "Real contents: ($v1,$v2,$v3,$v4,$n1,$n2,$n3,$n4,$e1,$e2,$e3,$e4)\n"; 129 | } 130 | } catch( Exception $e ) { 131 | $err = $this->db->errorInfo(); 132 | $cod = $this->db->errorCode(); 133 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 134 | } 135 | 136 | } /* runTest */ 137 | } 138 | $testcase = new Test(); 139 | $testcase->runTest(); 140 | ?> 141 | --EXPECTF-- 142 | %s 143 | *LIBL 144 | %s 145 | Real contents: (1.1,2.2,3.3,4.4,,,,,,,,) 146 | Real contents: (1.1,2.2,3.3,4.4,,,,,,,,) 147 | 148 | -------------------------------------------------------------------------------- /tests/fvt_77740_V6_system_naming_libdec.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Try system naming *LIBL 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(true,true,PDO::I5_TXN_NO_COMMIT); 15 | 16 | /* This is odd, yes? 17 | try { 18 | $libl = "select current path from sysibm.sysdummy1"; 19 | $stmt = $this->db->query( $libl ); 20 | print("$libl\n"); 21 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 22 | print($row[0]); 23 | print("\n"); 24 | } 25 | } catch( Exception $e ) { } 26 | */ 27 | 28 | try { 29 | $libl = "select current schema from sysibm.sysdummy1"; 30 | $stmt = $this->db->query( $libl ); 31 | print("$libl\n"); 32 | while( $row = $stmt->fetch( PDO::FETCH_NUM ) ) { 33 | print($row[0]); 34 | print("\n"); 35 | } 36 | } catch( Exception $e ) { } 37 | 38 | try { 39 | $create = "DROP TABLE libdec\n"; 40 | //print("$create\n"); 41 | $result = $this->db->query( $create ); 42 | } catch( Exception $e ) { } 43 | try { 44 | $create = "CREATE TABLE libdec(\n"; 45 | $create .= " V1 DECIMAL(12,2),\n"; 46 | $create .= " V2 NUMERIC(12,2),\n"; 47 | $create .= " V3 DECIMAL(8,4),\n"; 48 | $create .= " V4 NUMERIC(8,4),\n"; 49 | $create .= " N1 DECIMAL(12,2),\n"; 50 | $create .= " N2 NUMERIC(12,2),\n"; 51 | $create .= " N3 DECIMAL(8,4),\n"; 52 | $create .= " N4 NUMERIC(8,4),\n"; 53 | $create .= " E1 DECIMAL(12,2),\n"; 54 | $create .= " E2 NUMERIC(12,2),\n"; 55 | $create .= " E3 DECIMAL(8,4),\n"; 56 | $create .= " E4 NUMERIC(8,4))\n"; 57 | //print("$create\n"); 58 | $result = $this->db->query( $create ); 59 | } catch( Exception $e ) { 60 | $err = $this->db->errorInfo(); 61 | $cod = $this->db->errorCode(); 62 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 63 | } 64 | try { 65 | $v1 = 1.1; 66 | $v2 = 2.2; 67 | $v3 = 3.3; 68 | $v4 = 4.4; 69 | $n1 = null; 70 | $n2 = null; 71 | $n3 = null; 72 | $n4 = null; 73 | $e1 = ""; 74 | $e2 = ""; 75 | $e3 = ""; 76 | $e4 = ""; 77 | $callme = "insert into libdec (v1,v2,v3,v4,n1,n2,n3,n4,e1,e2,e3,e4) values (?,?,?,?,?,?,?,?,?,?,?,?)"; 78 | //print("$callme\n"); 79 | $stmt = $this->db->prepare($callme); 80 | $r1 = $stmt->bindParam(1,$v1); 81 | $r2 = $stmt->bindParam(2,$v2); 82 | $r3 = $stmt->bindParam(3,$v3); 83 | $r4 = $stmt->bindParam(4,$v4); 84 | $r5 = $stmt->bindParam(5,$n1); 85 | $r6 = $stmt->bindParam(6,$n2); 86 | $r7 = $stmt->bindParam(7,$n3); 87 | $r8 = $stmt->bindParam(8,$n4); 88 | $r9 = $stmt->bindParam(9,$e1); 89 | $r10 = $stmt->bindParam(10,$e2); 90 | $r11 = $stmt->bindParam(11,$e3); 91 | $r12 = $stmt->bindParam(12,$e4); 92 | $rc = $stmt->execute(); 93 | $v1 = 1.1; 94 | $v2 = 2.2; 95 | $v3 = 3.3; 96 | $v4 = 4.4; 97 | $n1 = null; 98 | $n2 = null; 99 | $n3 = null; 100 | $n4 = null; 101 | $e1 = ""; 102 | $e2 = ""; 103 | $e3 = ""; 104 | $e4 = ""; 105 | $rc = $stmt->execute(array($v1,$v2,$v3,$v4,$n1,$n2,$n3,$n4,$e1,$e2,$e3,$e4)); 106 | } catch( Exception $e ) { 107 | $err = $this->db->errorInfo(); 108 | $cod = $this->db->errorCode(); 109 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 110 | } 111 | try { 112 | $readme = "SELECT * FROM libdec"; 113 | print("$readme\n"); 114 | $stmt = $this->db->query( $readme ); 115 | while ($res = $stmt->fetch( PDO::FETCH_BOTH )) { 116 | $v1 = $res[0]; 117 | $v2 = $res[1]; 118 | $v3 = $res[2]; 119 | $v4 = $res[3]; 120 | $n1 = $res[4]; 121 | $n2 = $res[5]; 122 | $n3 = $res[6]; 123 | $n4 = $res[7]; 124 | $e1 = $res[8]; 125 | $e2 = $res[9]; 126 | $e3 = $res[10]; 127 | $e4 = $res[11]; 128 | print "Dec contents: ($v1,$v2,$v3,$v4,$n1,$n2,$n3,$n4,$e1,$e2,$e3,$e4)\n"; 129 | } 130 | } catch( Exception $e ) { 131 | $err = $this->db->errorInfo(); 132 | $cod = $this->db->errorCode(); 133 | echo("error ".$cod." ".$err[0]." ".$err[1]." ".$err[2]); 134 | } 135 | 136 | } /* runTest */ 137 | } 138 | $testcase = new Test(); 139 | $testcase->runTest(); 140 | ?> 141 | --EXPECTF-- 142 | %s 143 | *LIBL 144 | %s 145 | Dec contents: (1.10,2.20,3.3000,4.4000,,,,,,,,) 146 | Dec contents: (1.10,2.20,3.3000,4.4000,,,,,,,,) 147 | 148 | -------------------------------------------------------------------------------- /tests/fvt_V5V6_SQLParamData_fail.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Make sure SQLParamData fails for invalid inputs for data-on-exec (IBM i) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | 14 | try { 15 | /* Drop the test table, in case it exists */ 16 | $drop = 'DROP TABLE animals'; 17 | $result = $this->db->exec( $drop ); 18 | } catch( Exception $e ){} 19 | 20 | /* 21 | * make sure the test table has encoding that will fail conversion 22 | */ 23 | $create = 'CREATE TABLE animals (id INTEGER, my_clob clob ccsid 37)'; 24 | $result = $this->db->exec( $create ); 25 | 26 | $fp = fopen( dirname(__FILE__) . "/large_clob.dat" , "r" ); 27 | //$fp = fopen("large_clob.dat" , "r" ); // Test Tool 28 | $stmt = $this->db->prepare('insert into animals (id,my_clob) values (:id,:my_clob)'); 29 | $stmt->bindValue( ':id' , 0 ); 30 | $stmt->bindParam( ':my_clob' , $fp , PDO::PARAM_LOB ); 31 | $stmt->execute(); 32 | // XXX: This error is i specific; I'd like to have an equivalent test for LUW. 33 | } 34 | } 35 | 36 | $testcase = new Test(); 37 | $testcase->runTest(); 38 | ?> 39 | --EXPECTF-- 40 | Fatal error: Uncaught PDOException: SQLSTATE[22504]: <>: -191 Mixed data or UTF-8 data not properly formed. (SQLParamData[-191] at %s:%d) in %s:%d 41 | Stack trace: 42 | #0 %s(%d): PDOStatement->execute() 43 | #1 %s(%d): Test->runTest() 44 | #2 {main} 45 | thrown in %s on line %d 46 | -------------------------------------------------------------------------------- /tests/fvt_V5V6_isam_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: ISAM Error 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | $sql = "SELECT count(*) FROM notab"; 16 | 17 | try { 18 | $stmt = $this->db->query($sql); 19 | } catch (PDOException $e) { 20 | echo "Error code:\n"; 21 | print_r($this->db->errorCode()); 22 | echo "\n"; 23 | echo "Error info:\n"; 24 | print_r($this->db->errorInfo()); 25 | } 26 | } 27 | } 28 | 29 | $testcase = new Test(); 30 | $testcase->runTest(); 31 | ?> 32 | --EXPECTF-- 33 | Attempting to connect.. 34 | Error code: 35 | 42704 36 | Error info: 37 | Array 38 | ( 39 | [0] => 42704 40 | [1] => -204 41 | [2] => NOTAB in DB2 type *FILE not found. (SQLPrepare[-204] %s 42 | ) 43 | 44 | -------------------------------------------------------------------------------- /tests/fvt_boolean.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Boolean data type 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | // Tests insert and select 16 | try { 17 | $this->db->exec("drop table booltest"); 18 | } catch (Exception $e) {} 19 | $this->db->exec("create table booltest (id integer not null, enabled boolean, primary key(id))"); 20 | 21 | $s = $this->db->prepare("insert into booltest (id, enabled) values (1, ?)"); 22 | $x = true; 23 | $s->bindParam(1, $x, PDO::PARAM_BOOL); 24 | $r = $s->execute();; 25 | 26 | $s = $this->db->prepare("insert into booltest (id, enabled) values (2, ?)"); 27 | $x = false; 28 | $s->bindParam(1, $x, PDO::PARAM_BOOL); 29 | $r = $s->execute(); 30 | 31 | $s = $this->db->prepare("select * from booltest"); 32 | $s->execute(); 33 | while ($r = $s->fetch(PDO::FETCH_ASSOC)) { 34 | // This can return 0/1 on LUW or TRUE/FALSE on i 35 | echo $r["ID"] . ": " . $r["ENABLED"] . "\n"; 36 | } 37 | } 38 | } 39 | 40 | $testcase = new Test(); 41 | $testcase->runTest(); 42 | ?> 43 | --EXPECTREGEX-- 44 | 1: (1|TRUE) 45 | 2: (0|FALSE) 46 | -------------------------------------------------------------------------------- /tests/fvt_client_info.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Client Info 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_USERID)); 16 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_ACCTSTR)); 17 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_APPLNAME)); 18 | // This will default to the hostname of the system nowadays. 19 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_WRKSTNNAME)); 20 | 21 | $this->db->setAttribute(PDO::SQL_ATTR_INFO_USERID, "MyUser"); 22 | $this->db->setAttribute(PDO::SQL_ATTR_INFO_ACCTSTR, "MyAccountString"); 23 | $this->db->setAttribute(PDO::SQL_ATTR_INFO_APPLNAME, "MyApp"); 24 | $this->db->setAttribute(PDO::SQL_ATTR_INFO_WRKSTNNAME, "MyWorkStation"); 25 | 26 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_USERID)); 27 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_ACCTSTR)); 28 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_APPLNAME)); 29 | var_dump($this->db->getAttribute(PDO::SQL_ATTR_INFO_WRKSTNNAME)); 30 | } 31 | } 32 | 33 | $testcase = new Test(); 34 | $testcase->runTest(); 35 | ?> 36 | --EXPECTF-- 37 | Attempting to connect.. 38 | string(0) "" 39 | string(0) "" 40 | string(0) "" 41 | string(%d) "%S" 42 | string(6) "MyUser" 43 | string(15) "MyAccountString" 44 | string(5) "MyApp" 45 | string(13) "MyWorkStation" 46 | -------------------------------------------------------------------------------- /tests/fvt_handle_empty_parameter.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Handle empty parameter (GH-12) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 13 | $this->prepareDB(); 14 | 15 | $stmt = $this->db->prepare( "SELECT * FROM animals WHERE name = ?" ); 16 | $stmt->bindValue(1, ""); 17 | $stmt->execute(); 18 | print $stmt->rowCount() . "\n"; 19 | echo "Number of rows: " . count( $stmt->fetchAll() ) . "\n"; 20 | } 21 | } 22 | 23 | $testcase = new Test(); 24 | $testcase->runTest(); 25 | ?> 26 | --EXPECT-- 27 | -1 28 | Number of rows: 0 29 | 30 | -------------------------------------------------------------------------------- /tests/fvt_isam_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: ISAM Error 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | connect(); 14 | 15 | $sql = "SELECT count(*) FROM notab"; 16 | 17 | try { 18 | $stmt = $this->db->query($sql); 19 | } catch (PDOException $e) { 20 | echo "Error code:\n"; 21 | print_r($this->db->errorCode()); 22 | echo "\n"; 23 | echo "Error info:\n"; 24 | // It seems older Db2 LUW returned 42S22/-206, 25 | // but the current version seems to instead 26 | // return 42S02/-204, with a different message. 27 | // Note that [2] includes a newline as well.. 28 | print_r($this->db->errorInfo()); 29 | } 30 | } 31 | } 32 | 33 | $testcase = new Test(); 34 | $testcase->runTest(); 35 | ?> 36 | --EXPECTREGEX-- 37 | Attempting to connect.. 38 | Error code: 39 | 42S[02]2 40 | Error info: 41 | Array 42 | \( 43 | \[0\] => 42S[02]2 44 | \[1] => -20[46] 45 | \[2\] => \[IBM\]\[.*\]\[.*\] (The specified table (notab) is not in the database. \(.*\[-206\] at .*\) ISAM: \[IBM\]\[.*\]\[.*\] -111 ISAM error: no record found.|SQL0204N "DB2INST1.NOTAB" is an undefined name. SQLSTATE=42704\n.*) 46 | \) 47 | -------------------------------------------------------------------------------- /tests/fvt_trusted_context.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | pdo_ibm: Trusted Context 3 | --SKIPIF-- 4 | 10 | --FILE-- 11 | getVariables(); 24 | $db = $this->connect(); 25 | $this->createDB($db); 26 | 27 | $this->setup($db, "WITH AUTHENTICATION", "INSERT"); 28 | 29 | //Operation with wrong user name and password. 30 | $tcdb = $this->connectTC(true); 31 | if($tcdb) { 32 | if($tcdb->getAttribute(PDO::SQL_ATTR_USE_TRUSTED_CONTEXT)) { 33 | $userBefore = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 34 | 35 | //Switching user. 36 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID, "fakeuser"); 37 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_PASSWORD, "fakepass"); 38 | 39 | $userAfter = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 40 | 41 | if($userAfter != $userBefore) { 42 | echo "User has been switched.\n"; 43 | $this->dbOperations($tcdb); 44 | } 45 | } 46 | } 47 | 48 | //Passing password before user while switching user. 49 | $tcdb = $this->connectTC(true); 50 | if($tcdb) { 51 | if($tcdb->getAttribute(PDO::SQL_ATTR_USE_TRUSTED_CONTEXT)) { 52 | //Switching user. 53 | try { 54 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_PASSWORD, $this->tcpass); 55 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID, $this->tcuser); 56 | } catch (PDOException $ex) { 57 | print_r($tcdb->errorInfo()); 58 | } 59 | } 60 | } 61 | 62 | //Normal opeartion. 63 | $tcdb = $this->connectTC(true); 64 | if($tcdb) { 65 | if($tcdb->getAttribute(PDO::SQL_ATTR_USE_TRUSTED_CONTEXT)) { 66 | 67 | $userBefore = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 68 | 69 | //Switching user. 70 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID, $this->tcuser); 71 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_PASSWORD, $this->tcpass); 72 | 73 | $userAfter = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 74 | 75 | if($userAfter != $userBefore) { 76 | echo "User has been switched.\n"; 77 | $this->dbOperations($tcdb); 78 | } 79 | } 80 | } 81 | 82 | $this->setup($db, "WITHOUT AUTHENTICATION", "UPDATE"); 83 | 84 | //Normal opeartion. 85 | $tcdb = $this->connectTC(true); 86 | if($tcdb) { 87 | if($tcdb->getAttribute(PDO::SQL_ATTR_USE_TRUSTED_CONTEXT)) { 88 | $userBefore = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 89 | 90 | //Switching user. 91 | $tcdb->setAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID, $this->tcuser); 92 | 93 | $userAfter = $tcdb->getAttribute(PDO::SQL_ATTR_TRUSTED_CONTEXT_USERID); 94 | 95 | if($userAfter != $userBefore) { 96 | echo "User has been switched.\n"; 97 | $this->dbOperations($tcdb); 98 | } 99 | } 100 | } 101 | //Write the test here, switch user and do operations. 102 | 103 | $this->dropDB($db); 104 | } 105 | 106 | public function getVariables() { 107 | 108 | $this->authID = getenv('PDOTEST_AUTHID'); 109 | $this->authPass = getenv('PDOTEST_AUTHPASS'); 110 | $this->tcuser = getenv('PDOTEST_TCUSER'); 111 | $this->tcpass = getenv('PDOTEST_TCPASS'); 112 | 113 | if(strstr($this->dsn, "HOSTNAME")) { 114 | $temp = split("HOSTNAME=", $this->dsn); 115 | $temp = split(";", $temp[1]); 116 | $this->hostname = $temp[0]; 117 | } else { 118 | $this->hostname = "localhost"; 119 | } 120 | } 121 | 122 | public function setup($db, $authType = "WITH AUTHENTICATION", $grant = "INSERT") { 123 | 124 | //Preparing all the SQL statements. 125 | $sql_drop_role = "DROP ROLE role_01"; 126 | $sql_drop_trusted_context = "DROP TRUSTED CONTEXT ctx"; 127 | 128 | $sql_create_role = "CREATE ROLE role_01"; 129 | $sql_create_trusted_context = "CREATE TRUSTED CONTEXT ctx BASED UPON CONNECTION USING SYSTEM AUTHID "; 130 | $sql_create_trusted_context .= $this->authID; 131 | $sql_create_trusted_context .= " ATTRIBUTES (ADDRESS '"; 132 | $sql_create_trusted_context .= $this->hostname; 133 | $sql_create_trusted_context .= "') DEFAULT ROLE role_01 ENABLE WITH USE FOR "; 134 | $sql_create_trusted_context .= $this->tcuser . " "; 135 | $sql_create_trusted_context .= $authType; 136 | 137 | 138 | $sql_grant_permission = "GRANT " . $grant . " ON TABLE trusted_table TO ROLE role_01"; 139 | 140 | //Executing the SQLs. 141 | try { 142 | $db->exec($sql_drop_trusted_context); 143 | } catch (PDOException $ex) { } 144 | 145 | try { 146 | $db->exec($sql_drop_role); 147 | } catch (PDOException $ex) { } 148 | 149 | try { 150 | $db->exec($sql_create_role); 151 | } catch (PDOException $ex) { } 152 | 153 | try { 154 | $db->exec($sql_create_trusted_context); 155 | } catch (PDOException $ex) { } 156 | 157 | try { 158 | $db->exec($sql_grant_permission); 159 | } catch (PDOException $ex) { } 160 | } 161 | 162 | public function dropDB($db) { 163 | //Print contain of database. 164 | $this->printTable($db); 165 | 166 | //Preparing all the SQL statements. 167 | $sql_drop_table = "DROP TABLE trusted_table"; 168 | $sql_drop_role = "DROP ROLE role_01"; 169 | $sql_drop_trusted_context = "DROP TRUSTED CONTEXT ctx"; 170 | 171 | //Executing the SQLs. 172 | try { 173 | $db->exec($sql_drop_table); 174 | } catch (PDOException $ex) { } 175 | 176 | try { 177 | $db->exec($sql_drop_trusted_context); 178 | } catch (PDOException $ex) { } 179 | 180 | try { 181 | $db->exec($sql_drop_role); 182 | } catch (PDOException $ex) { } 183 | } 184 | 185 | public function connectTC($useTC=true) { 186 | $db = new PDO($this->dsn, $this->authID, $this->authPass, array(PDO::SQL_ATTR_USE_TRUSTED_CONTEXT => $useTC)); 187 | $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 188 | $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); 189 | $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 190 | return $db; 191 | } 192 | 193 | public function createDB ($db) { 194 | $sql_drop_table = "DROP TABLE trusted_table"; 195 | 196 | $sql_create_table = "CREATE TABLE trusted_table(i1 int,i2 int)"; 197 | $sql_insert = "INSERT INTO trusted_table (i1, i2) VALUES (?, ?)"; 198 | 199 | try { 200 | $db->exec($sql_drop_table); 201 | } catch (PDOException $ex) { } 202 | 203 | try { 204 | $db->exec($sql_create_table); 205 | } catch (PDOException $ex) { } 206 | 207 | $stmt = $db->prepare( $sql_insert ); 208 | if($stmt) { 209 | for($i = 1;$i <= 2;$i++) { 210 | $result = $stmt->execute(array($i * 10, $i * 20)); 211 | } 212 | 213 | } 214 | 215 | $this->printTable($db); 216 | } 217 | 218 | public function dbOperations ($db) { 219 | $sql_insert = "INSERT INTO $this->user.trusted_table (i1, i2) VALUES (100, 200)"; 220 | $sql_update = "UPDATE $this->user.trusted_table set i1 = 2000 WHERE i2 = 20"; 221 | 222 | try { 223 | $db->exec($sql_insert); 224 | } catch (PDOException $ex) { 225 | print_r($db->errorInfo()); 226 | } 227 | 228 | try { 229 | $db->exec($sql_update); 230 | } catch (PDOException $ex) { 231 | print_r($db->errorInfo()); 232 | } 233 | } 234 | 235 | public function printTable($db) { 236 | $sql = "SELECT * FROM trusted_table"; 237 | $stmt = $db->prepare($sql); 238 | $res = $stmt->execute(); 239 | while ($result = $stmt->fetch()) { 240 | var_dump($result); 241 | } 242 | } 243 | } 244 | 245 | $testcase = new Test(); 246 | $testcase->runTest(); 247 | ?> 248 | --EXPECTF-- 249 | array(4) { 250 | ["I1"]=> 251 | string(2) "10" 252 | [0]=> 253 | string(2) "10" 254 | ["I2"]=> 255 | string(2) "20" 256 | [1]=> 257 | string(2) "20" 258 | } 259 | array(4) { 260 | ["I1"]=> 261 | string(2) "20" 262 | [0]=> 263 | string(2) "20" 264 | ["I2"]=> 265 | string(2) "40" 266 | [1]=> 267 | string(2) "40" 268 | } 269 | User has been switched. 270 | Array 271 | ( 272 | [0] => 08001 273 | [1] => -30082 274 | [2] => [%s][%s][%s] SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001 275 | (SQLExecDirect[-30082] at %s:%d) 276 | ) 277 | Array 278 | ( 279 | [0] => 40003 280 | [1] => -900 281 | [2] => [%s][%s][%s] SQL0900N The application state is in error. A database connection does not exist. SQLSTATE=08003 282 | (SQLExecDirect[-900] at %s:%d) 283 | ) 284 | Array 285 | ( 286 | [0] => HY010 287 | [1] => -99999 288 | [2] => [%s][%s] CLI0198E Missing trusted context userid. SQLSTATE=HY010 (SQLSetConnectAttr[-99999] at %s:%d) 289 | ) 290 | User has been switched. 291 | Array 292 | ( 293 | [0] => 42501 294 | [1] => -551 295 | [2] => [%s][%s][%s] SQL0551N "%s" does not have the privilege to perform operation "UPDATE" on object "%s.TRUSTED_TABLE". SQLSTATE=42501 296 | (SQLExecDirect[-551] at %s:%d) 297 | ) 298 | User has been switched. 299 | Array 300 | ( 301 | [0] => 42501 302 | [1] => -551 303 | [2] => [%s][%s][%s] SQL0551N "%s" does not have the privilege to perform operation "INSERT" on object "%s.TRUSTED_TABLE". SQLSTATE=42501 304 | (SQLExecDirect[-551] at %s:%d) 305 | ) 306 | array(4) { 307 | ["I1"]=> 308 | string(4) "2000" 309 | [0]=> 310 | string(4) "2000" 311 | ["I2"]=> 312 | string(2) "20" 313 | [1]=> 314 | string(2) "20" 315 | } 316 | array(4) { 317 | ["I1"]=> 318 | string(2) "20" 319 | [0]=> 320 | string(2) "20" 321 | ["I2"]=> 322 | string(2) "40" 323 | [1]=> 324 | string(2) "40" 325 | } 326 | array(4) { 327 | ["I1"]=> 328 | string(3) "100" 329 | [0]=> 330 | string(3) "100" 331 | ["I2"]=> 332 | string(3) "200" 333 | [1]=> 334 | string(3) "200" 335 | } 336 | -------------------------------------------------------------------------------- /tests/large_blob.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-database-pdo_ibm/660e8cd00b39aa1c5a50b0da01bb70e5c16aa6ab/tests/large_blob.dat -------------------------------------------------------------------------------- /tests/large_clob.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-database-pdo_ibm/660e8cd00b39aa1c5a50b0da01bb70e5c16aa6ab/tests/large_clob.dat -------------------------------------------------------------------------------- /tests/skipif.PASE: -------------------------------------------------------------------------------- 1 | "i5 using modified driver with suffix -sgx", 4 | "fvt_006_ErrConditions_01"=>"i5 different error msg vs LUW", 5 | "fvt_007_ErrConditions_02"=>"i5 diff float to string round vs LUW", 6 | "fvt_008_ErrNonExistentTables"=>"i5 different error msg vs LUW", 7 | "fvt_008_V5_ErrNonExistentTables"=>"V5R4 no longer supported", 8 | "fvt_009_ErrFaultySQL"=>"i5 different error msg vs LUW", 9 | "fvt_013_ScrollableCursorNegativeRow"=>"i5 .10 vs LUW 0.10 and i5 -225 vs LUW -99999", 10 | "fvt_015_InsertSelectClobBlobColumns"=>"i5 XML viper not supported", 11 | "fvt_016_InsertIntegerBindingString"=>"i5 query INTEGER blank is zero, not blank", 12 | "fvt_017_InsertRetrieveLargeClobFile_01"=>"i5 bind after execute vs LUW bind before execute", 13 | "fvt_017b_InsertRetrieveLargeClobFile_02"=>"i5 bind after execute vs LUW bind before execute", 14 | "fvt_023_CommitAutocommitOFF"=>"i5 connect OptimizeAutoCommit=0 not allowed", 15 | "fvt_024_ChangeFetchModes"=>"test case improvement", 16 | "fvt_025_ColumnMetaData"=>"i5 different meta data no table vs LUW", 17 | "fvt_026_ErrCode"=>"i5 different error msg vs LUW", 18 | "fvt_028_ExecutBasicSP"=>"i5 different error msg vs LUW", 19 | "fvt_031_FetchOrientations"=>"i5 connect EnableScrollableCursors=1 not allowed", 20 | "fvt_032_FailureErrCodes"=>"i5 different error msg vs LUW", 21 | "fvt_033_ErrNullConnParams"=>"i5 fvt.inc modified for connect", 22 | "fvt_034_ErrNonExistentTableInsert"=>"i5 different error msg vs LUW", 23 | "fvt_036_SettingDiffOpt"=>"i5 different error msg vs LUW", 24 | "fvt_038_LastInsertID"=>"test case improvement", 25 | "fvt_040_ServerInfo"=>"test case improvement", 26 | "fvt_trusted_context"=>"i5 no trusted support", 27 | "fvt_isam_error"=>"i5 different errors"]; 28 | $myos = PHP_OS; 29 | $mytest = basename($_SERVER["PHP_SELF"]); 30 | if (strpos(" ".$myos,'400') > 0 || strpos(" ".$myos,'AIX') > 0) { 31 | if ( substr(phpversion(),0,1) <= 5) { 32 | $mypase["fvt_49872_V5V6_ClearingErrCodes"] = "i5 (null) missing vs LUW"; 33 | } else { 34 | $mypase["fvt_49872_ClearingErrCodes"] = "i5 (null) missing vs LUW"; 35 | } 36 | foreach ($mypase as $key => $value) { 37 | if (preg_match('/'.$key.'/', $mytest)) { 38 | die('skip'); 39 | } 40 | } 41 | } 42 | else { 43 | if (preg_match("/V5|V6/", $mytest)) { 44 | die('skip'); 45 | } 46 | } 47 | ?> 48 | -------------------------------------------------------------------------------- /tests/skipif.inc: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /tests/spook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-database-pdo_ibm/660e8cd00b39aa1c5a50b0da01bb70e5c16aa6ab/tests/spook.png --------------------------------------------------------------------------------