Skip to content

Commit 49be530

Browse files
committed
Initial commit
1 parent 600eab4 commit 49be530

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3843
-2
lines changed

.gitattributes

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
* text=auto
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.git export-ignore
10+
/docs export-ignore
11+
/examples export-ignore
12+
/tests export-ignore
13+
14+
.gitattributes export-ignore
15+
.gitignore export-ignore
16+
17+
composer.lock export-ignore
18+
pint.json export-ignore
19+
phpunit.xml export-ignore
20+
phpunit.xml.dist export-ignore

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.env
2+
/composer.lock
3+
/node_modules/
4+
/vendor/
5+
/.php-cs-fixer.cache
6+
/.DS_Store
7+
/.vscode/
8+
/.phpunit.result.cache
9+
/.pest.phpunit.cache

README.md

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,182 @@
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.

composer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "emkcloud/laravel-iseries-db2",
3+
"description": "Laravel Driver for DB2 on IBM iSeries",
4+
"keywords": [
5+
"as400",
6+
"database",
7+
"db2",
8+
"driver",
9+
"ibm",
10+
"iseries",
11+
"laravel",
12+
"odbc",
13+
"pdo"
14+
],
15+
"homepage": "https://github.com/emkcloud/laravel-iseries-db2",
16+
"type": "library",
17+
"license": "MIT",
18+
"authors": [
19+
{
20+
"name": "Massimo Della Rovere",
21+
"email": "[email protected]",
22+
"role": "Developer"
23+
}
24+
],
25+
"autoload": {
26+
"psr-4": {
27+
"Emkcloud\\IseriesDb2\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Tests\\": "tests/"
33+
}
34+
},
35+
"require": {
36+
"illuminate/support": "^12.0"
37+
},
38+
"extra": {
39+
"laravel": {
40+
"providers": [
41+
"Emkcloud\\IseriesDb2\\Providers\\IseriesDb2ServiceProvider"
42+
]
43+
}
44+
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true,
47+
"require-dev": {
48+
"laravel/pint": "^1.22",
49+
"pestphp/pest": "^3.8",
50+
"orchestra/testbench": "^10.2"
51+
},
52+
"config": {
53+
"allow-plugins": {
54+
"pestphp/pest-plugin": true
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)