kalel1500/laravel-db2-raw
最新稳定版本:v0.1.0-beta.1
Composer 安装命令:
composer require kalel1500/laravel-db2-raw
包简介
laravel-db2-raw is a simple helper to execute raw DB2 queries in Laravel.
README 文档
README
laravel-db2-raw is a simple helper to execute raw DB2 queries in Laravel.
This package provides a thin wrapper around the native ibm_db2 functions (db2_connect, db2_exec, db2_fetch_assoc, db2_close) to make it easier to run raw DB2 SQL queries in Laravel without using Eloquent.
Installation
Requirements
- PHP >= 8.2
ext-jsonext-ibm_db2- Laravel >= 12.x
Installation
Install laravel-db2-raw in your Laravel app with Composer:
composer require kalel1500/laravel-db2-raw
Configuration
The following environment variables are used by the default connection:
DB2RAW_CONNECTION: Default logical connection name (e.g.main).DB2RAW_HOST: DB2 server hostname or IP.DB2RAW_PORT: DB2 server port.DB2RAW_DATABASE: DB2 database name.DB2RAW_USERNAME: Username used to connect.DB2RAW_PASSWORD: Password used to connect.
This is the default configuration file (config/db2_raw.php):
/*
|--------------------------------------------------------------------------
| DB2 connections
|--------------------------------------------------------------------------
*/
'default' => env('DB2RAW_CONNECTION', 'main'),
'connections' => [
'main' => [
'host' => env('DB2RAW_HOST'),
'port' => env('DB2RAW_PORT'),
'database' => env('DB2RAW_DATABASE'),
'username' => env('DB2RAW_USERNAME'),
'password' => env('DB2RAW_PASSWORD'),
]
]
You can also publish the configuration file (config/db2_raw.php) with the following command
php artisan vendor:publish --tag="db2raw"
Usage
Basic
To launch a query you can use the Db2 facade:
use Thehouseofel\DB2Raw\Facades\Db2; Db2::exec($query)
The exec method receives the full SQL string and returns an array of associative arrays. Column names are normalized to lowercase. Currently, parameter binding (e.g. using ?) is not supported: you must build the full SQL statement yourself.
Be careful when building SQL strings with user input to avoid SQL injection vulnerabilities.
Defining additional connections
You can also define additional connections in the configuration file:
'connections' => [
//...
'admin' => [
'host' => env('DB2RAW_ADMIN_HOST'),
'port' => env('DB2RAW_ADMIN_PORT'),
'database' => env('DB2RAW_ADMIN_DATABASE'),
'username' => env('DB2RAW_ADMIN_USERNAME'),
'password' => env('DB2RAW_ADMIN_PASSWORD'),
]
]
And before executing the query you can select which connection to use:
use Thehouseofel\DB2Raw\Facades\Db2; Db2::connection('admin')->exec($query)
License
laravel-db2-raw is open-sourced software licensed under the GNU General Public License v3.0.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-12-02