2026-11-11 13:15:01 +00:00
2026-11-11 13:15:01 +00:00
2026-11-11 10:48:53 +00:00
2026-11-11 13:15:01 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 11:22:00 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 11:03:23 +00:00
2026-11-11 11:16:35 +00:00
2026-11-11 13:15:01 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 10:48:53 +00:00
2026-11-11 13:15:01 +00:00
2026-11-11 09:57:07 +00:00
2026-11-11 09:57:07 +00:00

Laravel 13 with Db2 LUW

This Laravel application includes a project-local Db2 driver built on PHP PDO_ODBC, unixODBC, and the IBM Db2 CLI driver. The verified setup uses Laravel 13.25.0, PHP 8.5.11 on macOS, and Db2 LUW 12.1.5.0 in Docker.

Create a database in Docker

Run these commands from your Mac terminal. The first command shows the container name and published ports. This setup uses the Db2-Server container with port 50000 published to the Mac.

docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Ports}}'
docker exec -it Db2-Server bash

At the container's root prompt, switch to the Db2 instance owner.

su - db2inst1

Wait for the prompt to show db2inst1, then load the Db2 environment and list the databases.

. ~/sqllib/db2profile
db2 list db directory

If LARAVEL does not already appear in the database directory, create it alongside MAIN.

db2 create database LARAVEL

Connect to the new database and confirm the target before creating application objects.

db2 connect to LARAVEL
db2 "VALUES CURRENT SERVER"
db2 "CREATE SCHEMA DB2_TEST AUTHORIZATION DB2INST1"
db2 connect reset

Run CREATE SCHEMA once if you want the dedicated DB2_TEST schema. To use the connection's default schema, skip that statement and omit DB2_SCHEMA from Laravel's environment. With the local db2inst1 account, the fallback previously resolved to DB2INST1. The database account needs privileges to create and manage application objects in the chosen schema.

Register the ODBC data source on the Mac

Use a distinct DSN called LARAVELDB so the existing MEDIUK entry can still point to MAIN. Confirm PHP has the ODBC extension and locate the active unixODBC configuration.

php -r 'print_r(PDO::getAvailableDrivers());'
odbcinst -j
odbcinst -q -d

The driver list should include odbc, and unixODBC should list IBM DB2 ODBC DRIVER. Add this section once to the active odbc.ini. In the verified Mac setup the system file is /opt/homebrew/etc/odbc.ini. Back up the file before editing.

[LARAVELDB]
Driver=IBM DB2 ODBC DRIVER
Database=LARAVEL
Hostname=127.0.0.1
Port=50000
Protocol=TCPIP

Register the same alias with the IBM client. The commands below use the verified installation paths. If DB2DSDRIVER_CFG_PATH selects another file, back up and use that active configuration instead.

cp -p "$HOME/IBM/db2/clidriver/cfg/db2dsdriver.cfg" \
  "$HOME/IBM/db2/clidriver/cfg/db2dsdriver.cfg.bak-$(date +%Y%m%d-%H%M%S)"
"$HOME/IBM/db2/clidriver/bin/db2cli" writecfg add \
  -dsn LARAVELDB -database LARAVEL -host 127.0.0.1 -port 50000
odbcinst -q -s
"$HOME/IBM/db2/clidriver/bin/db2cli" validate -dsn LARAVELDB

SQL1531N with LARAVELDB already listed by unixODBC usually means the IBM client cannot find the alias in its active configuration. Check that the PHP process and your terminal use the same IBM client configuration.

Configure Laravel and run migrations

In the project's .env, set the connection details and use your own credentials.

DB_CONNECTION=db2_local
DB2_DSN=LARAVELDB
DB2_DATABASE=LARAVEL
DB2_SCHEMA=DB2_TEST
DB2_USERNAME=db2inst1
DB2_PASSWORD=your_password

The DSN selects the actual target and supplies the host and port. DB2_DATABASE is Laravel's connection metadata. This connector gets its network settings from the DSN.

From the project directory, clear cached configuration and verify the database and schema through Laravel.

php artisan config:clear
php artisan tinker --execute='dump(DB::selectOne("SELECT CURRENT SERVER AS DB_NAME, CURRENT SCHEMA AS SCHEMA_NAME FROM SYSIBM.SYSDUMMY1"));'

When the output shows LARAVEL and your intended schema, run:

php artisan migrate
php artisan migrate:status

Create the database first. Migrations create application tables in that database. Existing data in MAIN stays there until you transfer it separately.

Browse or remove schemas

DBeaver Community can connect using its IBM Db2 LUW driver. Use host 127.0.0.1, port 50000, database LARAVEL, and your Db2 credentials. DBeaver connects via JDBC and can have a separate connection for MAIN. DBeaver Community download

To inspect the old DB2_TEST schema, run the following in the same db2inst1 shell inside Docker.

db2 connect to MAIN
db2 "VALUES CURRENT SERVER"
db2 "LIST TABLES FOR SCHEMA DB2_TEST"

After confirming MAIN, use db2 "DROP SCHEMA DB2_TEST RESTRICT" to remove an empty schema. SQL0478N means dependent objects remain. If you intend to permanently delete those objects and their data from MAIN, run:

db2 "CALL SYSPROC.ADMIN_DROP_SCHEMA('DB2_TEST', NULL, 'DB2INST1', 'DROP_DB2_TEST_ERRORS')"
db2 "SELECT SCHEMANAME FROM SYSCAT.SCHEMATA WHERE SCHEMANAME = 'DB2_TEST'"
db2 connect reset

Zero rows confirms removal. If the procedure reports an error table, inspect it for individual failures. SQL1024N means you need to connect to the database from the current shell first.

How the driver works

Component Responsibility
Database configuration Defines the db2_local connection with the odbc driver.
AppServiceProvider Registers the driver with Laravel, opens PDO using the DSN, and applies the configured schema or reads CURRENT SCHEMA for metadata.
Db2Connection Wires up the Db2 builder, grammars, and processor. Decodes the internal NULL indicators on eligible result reads.
Db2QueryBuilder and Db2QueryGrammar Compile Db2 pagination, savepoints, case-aware LIKE, and MERGE-based upserts and insert-or-ignore. Apply PDO_ODBC result handling when fetching eligible rows.
Db2Processor Retrieves generated identities on the same connection after insertion.
Db2SchemaGrammar Converts Laravel schema blueprints into Db2 DDL for tables, columns, indexes, and constraints.
Db2SchemaBuilder Reads table, column, index, and foreign-key metadata from the Db2 catalog.

The result-only SQL path adds NULL indicators where needed and formats nullable timestamps for Eloquent date casting. Embedded queries keep their declared columns, which is required for scalar subqueries, WHERE IN, and UNION.

On Db2 LUW, unqualified table names resolve in one current schema. Use a qualified table such as DB::connection('db2_local')->table('ARCHIVE.CUSTOMERS') to access another schema in the same database, subject to privileges. The IBM i Access DBQ library-list setting does not provide a table search path on Db2 LUW.

Laravel can also select its standard MySQL driver through DB_CONNECTION=mysql and the corresponding DB_* settings. Switching the connection leaves existing Db2 data in Db2. The release notes cover the verified Db2 setup.

Developer workflow

  1. Check the installed Illuminate APIs and the existing driver classes before editing. Keep changes in application code. Add accurate PHPDoc headers and explicit return types to methods you add or modify, matching inherited signatures.
  2. Reproduce the problem through the normal Laravel entry point in a focused test under tests/Feature/Db2. Use a disposable database or schema. The Db2 tests explicitly use db2_local, and the release test creates and removes its own schema.
  3. Run the focused test against Db2 before the fix. Check the SQL, catalog state, or PHP values relevant to the failure. Run PHP syntax checks on changed files and then rerun the focused and regression suites.
composer validate --no-check-publish --no-interaction
APP_ENV=testing php artisan test --do-not-cache-result tests/Feature/Db2/ReleaseCompatibilityTest.php
APP_ENV=testing php artisan test --do-not-cache-result tests/Feature/Db2
APP_ENV=testing php artisan test --do-not-cache-result
git diff --check

A skipped Db2 test means the connection or extension was unavailable. The general application tests use SQLite and the Db2 integration tests use the configured Db2 connection.

Review the schema compatibility notes for type mappings, index limits, and when Db2 may require REORG. The query compatibility notes describe the scope of NULL handling and query support. The release verification records the tested version matrix and the migration and authenticated passkey-page checks. Browser WebAuthn enrolment and sign-in were outside that verification.

S
Description
Laravel 13 testbed qith custom DB2 driver
Readme
509 KiB
Languages
PHP 69%
Blade 29.6%
CSS 1%
JavaScript 0.3%