|
1 |
| -# laravel-iseries-db2 |
2 |
| -Laravel integration with DB2 on IBM iSeries (formerly AS/400) |
| 1 | +# iseries-db2 |
| 2 | + |
| 3 | +**Laravel Driver for DB2 on IBM iSeries (AS/400)** |
| 4 | + |
| 5 | +A modern DB2 driver for Laravel, supporting IBM i (iSeries) systems using ODBC. This package is inspired by [db2-driver](https://github.com/BWICompanies/db2-driver), but due to significant changes introduced in Laravel 12, it was necessary to rebuild the driver from scratch. Designed for Laravel and IBM i >= 7.1 release. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Laravel 12+ support |
| 10 | +- Compatible with IBM iSeries DB2 >= 7.1 |
| 11 | +- Compatible with `artisan db:table` |
| 12 | +- Compatible with migration commands |
| 13 | +- Using Laravel's modern Grammar |
| 14 | +- Add Custom Laravel DB2 Methods |
| 15 | +- Use only Query Builder, no Eloquent |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +- [IBM i Access ODBC (Windows & Linux)](https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/installation.html) |
| 20 | +- [PHP PDO_ODBC extension (Documentation)](https://www.php.net/manual/en/book.pdo.php) |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +```bash |
| 25 | +composer require emkcloud/iseries-db2 |
| 26 | +``` |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +- [Define connection in database.php](docs/contents/connection.md) |
| 31 | +- [Define appropriate variables in .env](examples/variables.env) |
| 32 | + |
| 33 | +## Artisan Commands |
| 34 | + |
| 35 | +The following Laravel schema and database inspection commands have been tested and are fully supported by this driver with environment Laravel 12 and IBM iSeries 7.4: |
| 36 | + |
| 37 | +``` |
| 38 | +// ✅ Artisan command support |
| 39 | +php artisan db:show --database=iseries |
| 40 | +php artisan db:show --database=iseries --counts |
| 41 | +php artisan db:show --database=iseries --views |
| 42 | +
|
| 43 | +// ✅ Artisan command support |
| 44 | +php artisan db:table --database=iseries |
| 45 | +php artisan db:table --database=iseries MYTABLE |
| 46 | +``` |
| 47 | + |
| 48 | +## Example Output |
| 49 | + |
| 50 | +- Screenshot of [`artisan db:table`](docs/images/artisan-table-columns.jpg) |
| 51 | +- Screenshot of [`artisan db:show`](docs/images/artisan-table-show.jpg) |
| 52 | +- Screenshot of [`artisan db:show --counts`](docs/images/artisan-table-count.jpg) |
| 53 | +- Screenshot of [`artisan db:show --views`](docs/images/artisan-table-views.jpg) |
| 54 | + |
| 55 | +## Schema Commands |
| 56 | + |
| 57 | +```php |
| 58 | +// ✅ Get all schemas for specific connection |
| 59 | +Schema::connection('iseries')->getSchemas(); |
| 60 | + |
| 61 | +// ✅ Get all tables for default schema |
| 62 | +Schema::connection('iseries')->getTables(); |
| 63 | +Schema::connection('iseries')->getTableListing(); |
| 64 | + |
| 65 | +// ✅ Get info columns table for default or specific schema |
| 66 | +Schema::connection('iseries')->getColumns('MYTABLE'); |
| 67 | +Schema::connection('iseries')->getColumns('MYSCHEMA.MYTABLE'); |
| 68 | + |
| 69 | +// ✅ Get list columns table for default or specific schema |
| 70 | +Schema::connection('iseries')->getColumnListing('MYTABLE'); |
| 71 | +Schema::connection('iseries')->getColumnListing('MYSCHEMA.MYTABLE'); |
| 72 | + |
| 73 | +// ✅ Get column type for specific table |
| 74 | +Schema::connection('iseries')->getColumnType('MYTABLE','MYCOL'); |
| 75 | +Schema::connection('iseries')->getColumnType('MYSCHEMA.MYTABLE','MYCOL'); |
| 76 | + |
| 77 | +// ✅ Get info indexes table for default or specific schema |
| 78 | +Schema::connection('iseries')->getIndexes('MYTABLE'); |
| 79 | +Schema::connection('iseries')->getIndexes('MYSCHEMA.MYTABLE'); |
| 80 | + |
| 81 | +// ✅ Get foreign keys table for default or specific schema |
| 82 | +Schema::connection('iseries')->getForeignKeys('MYTABLE'); |
| 83 | +Schema::connection('iseries')->getForeignKeys('MYSCHEMA.MYTABLE'); |
| 84 | + |
| 85 | +// ✅ Get info views for default or specific schema |
| 86 | +Schema::connection('iseries')->getViews(); |
| 87 | +Schema::connection('iseries')->getViews('MYSCHEMA'); |
| 88 | + |
| 89 | +// ✅ Check table existence for default or specific schema |
| 90 | +Schema::connection('iseries')->hasTable('MYTABLE'); |
| 91 | +Schema::connection('iseries')->hasTable('MYSCHEMA.MYTABLE'); |
| 92 | + |
| 93 | +// ✅ Check column existence for specific table |
| 94 | +Schema::connection('iseries')->hasColumn('MYTABLE','MYCOL') |
| 95 | +Schema::connection('iseries')->hasColumn('MYSCHEMA.MYTABLE','MYCOL') |
| 96 | + |
| 97 | +// ✅ Check columns existence for specific table |
| 98 | +Schema::connection('iseries')->hasColumns('MYTABLE',['MYCOL1','MYCOLN']) |
| 99 | +Schema::connection('iseries')->hasColumns('MYSCHEMA.MYTABLE',['MYCOL1','MYCOLN']) |
| 100 | + |
| 101 | +// ✅ Check index existence for specific table |
| 102 | +Schema::connection('iseries')->hasIndex('MYTABLE','MYINDEX') |
| 103 | +Schema::connection('iseries')->hasIndex('MYSCHEMA.MYTABLE','MYINDEX') |
| 104 | + |
| 105 | +// ✅ Check view existence for default or specific schema |
| 106 | +Schema::connection('iseries')->hasView('MYVIEW') |
| 107 | +Schema::connection('iseries')->hasView('MYSCHEMA.MYVIEW') |
| 108 | +``` |
| 109 | + |
| 110 | +## Custom DB2 Methods |
| 111 | + |
| 112 | +Retrieve a list of available IBM i libraries. |
| 113 | + |
| 114 | +```php |
| 115 | +// ✅ Get list libraries presents in IBM iseries system |
| 116 | +Schema::connection('iseries')->getSchemas(); |
| 117 | +Schema::connection('iseries')->getSchemasListing(); |
| 118 | + |
| 119 | +// ✅ Get list libraries presents in IBM iseries system |
| 120 | +Schema::connection('iseries')->getLibraries(); |
| 121 | +Schema::connection('iseries')->getLibrariesListing(); |
| 122 | +``` |
| 123 | + |
| 124 | +This package adds convenient methods to execute remote IBM i programs. |
| 125 | + |
| 126 | +```php |
| 127 | +// ✅ Runs a CALL select program with parameters |
| 128 | +DB::connection('iseries')->executeSelect('MYLIBRARY.MYPROGRAM'); |
| 129 | +DB::connection('iseries')->executeSelect('MYLIBRARY.MYPROGRAM',[$PARM1,$PARM2]); |
| 130 | + |
| 131 | +// ✅ Runs a CALL statement stored program with parameters |
| 132 | +DB::connection('iseries')->executeStatement('MYLIBRARY/MYPROGRAM'); |
| 133 | +DB::connection('iseries')->executeStatement('MYLIBRARY/MYPROGRAM',[$PARM1,$PARM2]); |
| 134 | +``` |
| 135 | + |
| 136 | +## Migration Commands |
| 137 | + |
| 138 | +```php |
| 139 | +// ✅ Creates a table with the given structure |
| 140 | +DB::connection('iseries')->create(MYTABLESTRUCTURE); |
| 141 | + |
| 142 | +// ✅ Drops a table if it exists (supports schema prefix) |
| 143 | +DB::connection('iseries')->dropIfExists('MYTABLE'); |
| 144 | +DB::connection('iseries')->dropIfExists('MYSCHEMA/MYTABLE'); |
| 145 | +``` |
| 146 | + |
| 147 | +## Migration Blueprint |
| 148 | + |
| 149 | +Laravel's Blueprint class offers a wide variety of methods for building database schemas. |
| 150 | +I focused on implementing the most essential and commonly used ones. |
| 151 | + |
| 152 | +## Migration Examples |
| 153 | + |
| 154 | +- [Example verified commands](docs/contents/blueprint.md) |
| 155 | +- [Example standard migration](examples/migration.php) |
| 156 | + |
| 157 | +## Migration Drop & Rename |
| 158 | + |
| 159 | +To use Drop and Rename operations, the database connection user must have the correct permissions to execute the `ADDRPYLE` and `RMVRPYLE` commands. You can grant the necessary permissions by running the following commands on the IBM i system: |
| 160 | + |
| 161 | +```python |
| 162 | +GRTOBJAUT OBJ(QSYS/ADDRPYLE) OBJTYPE(*CMD) USER(MYUSER) AUT(*USE) |
| 163 | +GRTOBJAUT OBJ(QSYS/RMVRPYLE) OBJTYPE(*CMD) USER(MYUSER) AUT(*USE) |
| 164 | +``` |
| 165 | + |
| 166 | +If an automatic reply to the `CPF32B2` message is configured directly on the central server, this warning can be ignored. If you enable automation on the central system, you must set the environment variable to false. |
| 167 | + |
| 168 | +```ini |
| 169 | +ISERIES_ODBC_REPLY_AUTOMATIC=false |
| 170 | +``` |
| 171 | + |
| 172 | +## Other Resources |
| 173 | + |
| 174 | +- [DB2 Connection String](https://www.ibm.com/docs/en/i/7.6.0?topic=details-connection-string-keywords) |
| 175 | +- [Documentation PDO Attributes](https://www.php.net/manual/en/book.pdo.php) |
| 176 | +- [IBM i Access Driver Release Notes](https://www.ibm.com/support/pages/ibm-i-access-acs-updates-pase) |
| 177 | +- [Alternative Package db2driver](https://github.com/BWICompanies/db2-driver) |
| 178 | +- [Documentation for DB2 for IBM i](https://www.ibm.com/docs/en/i/7.6.0?topic=concepts-database-files) |
| 179 | + |
| 180 | +## License |
| 181 | + |
| 182 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments