Seiden Group
Modern Development & Open Source for IBM i
  • Link to LinkedIn
  • Link to Mail
  • Home
  • Seiden PHP+
    • Seiden PHP+
    • Install & Learn
    • SmartSupport
    • PHP Migrations & Upgrades
    • Success Stories
    • Free PHP Assessment
    • Documentation
    • What’s New (Changelog)
  • IBM i Services
    • Development
    • Training & Mentoring
    • Open Source Setup & Upgrades
    • SSL/TLS Install & Learn
    • Performance
  • Support
    • Open Source & PHP
    • VS Code for i
    • Developer Support
    • Support Success Stories
  • VS Code for i
    • Support
    • Training
    • Code for i Resource Guide
    • Getting Started Videos
    • Code for IBM i Fridays
  • Free Stuff
    • IBM i Strategy & Tips
    • PHP Upgrade Assessment
    • CNX Valence Assessment
    • VS Code for IBM i Resources
    • Code for IBM i Fridays
    • QCachegrind Download
    • PHP Toolkit for IBM i Resources
    • Qshell on i Library
  • Blog
  • About
    • About Our Team
    • About Alan Seiden
    • Speakers & Sessions
    • In the News
  • Contact
  • 201.447.2437
  • Search
  • Menu Menu

Seiden Group Blog

Connecting to IBM i Db2 with the Laravel PHP Framework

January 18, 2023/1 Comment/in ODBC, PHP /by Alan Seiden

Laravel FrameworkLaravel has been inspiring loyalty among PHP developers for its documentation, community, and many built-in features.

Like most PHP frameworks, Laravel is cross-platform and can work with IBM i and Db2 data. This article shows how to take full advantage of Laravel’s built-in database components by installing an IBM i-specific extension to Laravel’s database connection class.

A new fork for a useful package

For years, PHP developers used the laravel-db2 package from cooper22 to connect to IBM i data. As the cooper22 package became stale and it slowed its acceptance of community updates, users stepped up. BWI Companies, in cooperation with Seiden Group, created a “fork” (a copy), dubbed it db2-driver, and is maintaining it actively.

What you can do with db2-driver

Once you configure access to your IBM i database, you can use several popular Laravel features with it, including Query Builder; Migrations; and Eloquent, Laravel’s object-relational mapper (ORM).

Requirements

PDO_ODBC: BWI Companies decided to simplify the new package by limiting support to PDO_ODBC, which works well on IBM i and can connect to IBM i from other platforms. Support for the legacy PDO_IBM and ibm_db2 extensions were not carried forward in this package, although Seiden Group continues to maintain and support PDO_IBM and ibm_db2 in its Seiden PHP+ package. The ODBC driver supports library lists and other popular IBM i Db2 features.

PHP 8.1+: This package requires PHP 8.1 or higher.

How to install and configure db2_driver

The readme file is the best place to start, but we will summarize the steps here:

  • Install the package via composer inside your project directory:
    1
    composer require bwicompanies/db2-driver
  • Add a new connection in database.php, using the example settings in the readme as a guide. All supported ODBC connection string keywords are available there, including library list support.
    • Several database.php values, such as env('DB_HOST'), will be pulled from the .env file in the main Laravel folder.
    • Specify your default database connection name, which can be any string. Example:
      • 'default' => env('DB_CONNECTION', 'myIbmi'),
    • Add details in an array for the database connection. Example key name (paste in your database.php settings after this):
      • ‘myIbmi' => [
  • Edit the .env file to add key database connection settings, such as password. The .env file is not considered “code” and by default won’t be committed to Git repositories. Example settings:
    • DB_CONNECTION=myIbmi # any name you want that matches main key in database.php
    • DB_HOST=127.0.0.1 # server/IP address
    • DB_DATABASE=*LOCAL # DSN name from odbc.ini or other ODBC DSN storage
    • DB_USERNAME= # IBM i user with rights to your objects
    • DB_PASSWORD= # IBM i password
    • Optional settings:
      • DB_SCHEMA=# if using a single IBM i Db2 default library
      • DB_PORT=50000 # if connecting from Linux, Windows, or non-i platform

Run a query and get data

Now you should be able to connect to your IBM i data using code like the following:

PHP
1
2
3
4
5
6
7
8
use Illuminate\Support\Facades\DB;
 
// https://laravel.com/docs/9.x/database#running-a-select-query
$customers = DB::select('select * from QIWS.QCUSTCDT');
 
foreach ($customers as $customer) {
    echo $customer->city;
}

Laravel PHP and IBM i Db2 working together

Give the DB2 for IBM i Laravel Driver a try. It’s open source, accepting improvements and enhancements. I hope a community of IBM i PHP developers join us to contribute actively and help to make it even better.

Thank you to BWI Companies and all those who contributed to the original package.

As always, stay in touch and let us know if you would like help getting started or support to keep up your skills.

Tags: DB2, IBMi, laravel, PHP
Share this entry
  • Share on Facebook
  • Share on X
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Reddit
  • Share by Mail
https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png 0 0 Alan Seiden https://www.seidengroup.com/wp-content/uploads/2017/03/SeidenLogo-180.png Alan Seiden2023-01-18 10:59:172025-12-15 12:19:30Connecting to IBM i Db2 with the Laravel PHP Framework
Alan Seiden

About Alan Seiden

Alan works to preserve your investment in IBM enterprise systems by designing and implementing modernization strategies that leverage your existing business logic.

With a passion ...Read More

1 reply
  1. Néstor López
    Néstor López says:
    February 13, 2024 at 4:09 pm

    I’ve tried to connect to DB2 database but I get the following error:
    PDOException
    SQLSTATE[08004] SQLDriverConnect: 10061 [IBM][System i Access ODBC Driver]Communications link error. comm rc=10061 – CWBCO1049 – The IBM i server application has not started or the connection has been blocked by a firewall

    PHP 8.2.15
    Laravel 10.41.0

    What should I do?

    Have a nice day

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

SUBSCRIBE
Open Thinking
Monthly IBM i Strategy & Tips
  • This field is for validation purposes and should be left unchanged.

IBM i Development

  • RPG, COBOL, SQL, Node,
    PHP, Python, Valance, etc.
  • Modernization. Integration.
  • Web and API Solutions
  • Legacy Maintenance
    ...
LET'S GET IT DONE!

Recent Posts

  • Mitigating the eMudhra Intermediate CA Compromise with IBM i
  • Critical Security Update Available in Seiden PHP+ Server
  • Moving to IBM i 7.6? An SDA Alternative with VS Code and IBM Bob
  • What’s New with Mapepire Database Connector for IBM i
  • Do You Need IBM i Observability?
  • PHP 8.6 is Coming Soon to IBM i
  • Safer npm installation is on the way for Node.js (and all JavaScript)
  • Access Modern Security for IBM i and Connected Web Environments
  • IBM i: A Natural Platform for Agentic AI
  • PHP on IBM i in 2026: The Modernization Engine

SEIDEN GROUP: Modern Development & Open Source for IBM i

Home   |   Seiden PHP+   |   IBM i Services  |   Support   |   VS Code for i   |   Free Stuff   |   Blog  |   Privacy Policy  |   Contact         201.447.2437

© 2026 Seiden Group, LLC
  • Link to LinkedIn
  • Link to Mail
Link to: Edit IFS Files Using Visual Studio Code for IBM i Link to: Edit IFS Files Using Visual Studio Code for IBM i Edit IFS Files Using Visual Studio Code for IBM i Link to: Why I Learned RPGLE Link to: Why I Learned RPGLE Why I Learned RPGLE
Scroll to top Scroll to top Scroll to top