ledtest / oracle
Laravel 的 Oracle DB 驱动程序
Requires
- php: ^7.3.0
- illuminate/database: ^8.24.0
- illuminate/pagination: ^8.0
- illuminate/support: ^8.0
Requires (Dev)
- mockery/mockery: ^1.4.2
- phpunit/phpunit: ^9.3.3
- dev-develop
- 8.0.0
- 7.x-dev
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.x-dev
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.8.x-dev
- 5.8.1
- 5.8.0
- 5.7.x-dev
- 5.7.1
- 5.6.x-dev
- 5.6.4
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.4.x-dev
- 5.4.4
- 5.4.3
- 5.4.2
- 5.4.1
- 5.3.x-dev
- 5.3.2
- 5.3.1
- 5.2.x-dev
- 5.2.2
- 5.2.1
- 5.1.x-dev
- 5.1.2
- 5.1.1
- 4.2.x-dev
- 4.2.1
- 4.1.x-dev
- 4.1.1
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.3.0
- 0.2.1
- 0.2.0
- dev-master
This package is auto-updated.
Last update: 2024-09-12 14:54:32 UTC
README
OracleDB(针对 Laravel 8.x 更新)
OracleDB 是 Laravel 框架的 Oracle 数据库驱动程序包 - 感谢 @taylorotwell。OracleDB 是 Illuminate/Database 的扩展,它使用 PDO_OCI 扩展或封装在 PDO 命名空间中的 OCI8 函数。
注意:此包尚未在 PHP 8 上进行测试。
请报告您可能发现的任何错误。
安装
使用 Composer
composer require jfelder/oracledb
在此命令期间,Laravel 的 "自动发现" 功能应自动注册 OracleDB 的服务提供者。
接下来,使用 artisan:publish 命令发布 OracleDB 的配置文件。这将 OracleDB 的配置文件复制到您的项目中的 config/oracledb.php。
php artisan vendor:publish --tag=oracledb-config
为了完成安装,设置您的环境变量(通常在您的 .env 文件中)为在 config/oracledb.php 中使用的相应环境变量:例如 DB_HOST、DB_USERNAME 等。
此外,在执行任何查询之前,您的应用程序可能需要配置数据库连接会话的 NLS_DATE_FORMAT。一种实现方式是在 AppServiceProvider 的 boot 方法中运行一个语句,例如
if (config('database.default') === 'oracle') { DB::statement("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); }
基本用法
此包的配置文件位于 config/oracledb.php。在此文件中,您定义所有 oracle 数据库连接。如果您需要建立多个连接,只需复制示例连接即可。如果您想将其中一个连接设置为默认连接,请在 config/database.php 中的 "Default Database Connection Name" 部分输入您为连接设置的名称。
一旦您已配置 OracleDB 数据库连接(s),您可以使用 DB 门面正常运行查询。
注意:OCI8 是默认驱动。如果您想使用 PDO_OCI 驱动程序,请将 config/oracledb.php 文件中要使用 PDO_OCI 的任何连接的 driver 值更改为 'pdo'。将驱动设置为 'pdo' 将使 OracleDB 使用 PDO_OCI 扩展。给定任何其他 driver 值,OracleDB 将使用 OCI8 函数。
$results = DB::select('select * from users where id = ?', [1]);
上面的语句假设您已将默认连接设置为在 config/database.php 文件中设置的 oracle 连接,并且将始终返回一个 array 结果。
$results = DB::connection('oracle')->select('select * from users where id = ?', [1]);
就像内置的数据库驱动程序一样,您可以使用连接方法访问在 config/oracledb.php 文件中设置的 oracle 数据库(s)。
向具有自增 ID 的表中插入记录
$id = DB::connection('oracle')->table('users')->insertGetId( ['email' => 'john@example.com', 'votes' => 0], 'userid' );
注意:当使用 insertGetId 方法时,您可以在 insertGetId 函数的第二个参数中指定自增列名称。如果没有指定,它将默认为 "id"。
有关更多信息,请参阅 Laravel 数据库基本文档。
未实现的功能
本包中未实现一些第三方Laravel数据库驱动程序的功能。欢迎提交Pull requests以实现这些功能之一,或者如果您发现未列出的未实现功能,可以扩展此列表。
查询构建器
- 插入或忽略
DB::from('users')->insertOrIgnore(['email' => 'foo']); - 使用空值插入获取ID
DB::from('users')->insertGetId([]);(但支持使用非空值调用) - 插入更新(upserts)
DB::from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email'); - 通过连接删除
DB::from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('users.email', '=', 'foo')->delete(); - 限制删除
DB::from('users')->where('email', '=', 'foo')->orderBy('id')->take(1)->delete(); - JSON操作
DB::from('users')->where('items->sku', '=', 'foo-bar')->get();
模式构建器
- 如果存在则删除表
Schema::dropIfExists('some_table'); - 删除所有表、视图或类型
Schema::dropAllTables(),Schema::dropAllViews(),和Schema::dropAllTypes() - 设置表上的校对规则
$blueprint->collation('BINARY_CI') - 设置列上的校对规则
$blueprint->string('some_column')->collation('BINARY_CI') - 设置表上的注释
$blueprint->comment("This table is great.") - 设置列上的注释
$blueprint->string('foo')->comment("Some helpful info about the foo column") - 设置自增列的起始值
$blueprint->increments('id')->startingValue(1000) - 创建私有临时表
$blueprint->temporary() - 重命名索引
$blueprint->renameIndex('foo', 'bar') - 在创建索引时指定算法(通过第三个参数)
$blueprint->index(['foo', 'bar'], 'baz', 'hash') - 创建空间索引
$blueprint->spatialIndex('coordinates') - 流畅地创建空间索引
$blueprint->point('coordinates')->spatialIndex() - 创建生成列,如mysql驱动程序的
virtualAs和storedAs,以及postgres的generatedAs;例如,假设存在名为price的整数类型列,$blueprint->integer('discounted_virtual')->virtualAs('price - 5') - 创建JSON列
$blueprint->json('foo')或 JSONB列$blueprint->jsonb('foo')(Oracle建议将JSON存储在VARCHAR2、CLOB或BLOB列中) - 创建不带精度的带时区的时间戳列
$blueprint->dateTimeTz('created_at'),或带精度的$blueprint->timestampTz('created_at', 1) - 创建具有时区组件的Laravel风格时间戳列
$blueprint->timestampsTz() - 创建UUID列
$blueprint->uuid('foo')(Oracle建议使用16字节原始数据类型列来存储UUID) - 创建外键UUID列
$blueprint->foreignUuid('foo') - 创建用于存储IP地址的列
$blueprint->ipAddress('foo')(将实现为45个字符的VARCHAR2) - 创建用于存储MAC地址的列
$blueprint->macAddress('foo')(将实现为17个字符的VARCHAR2) - 创建几何列
$blueprint->geometry('coordinates') - 创建几何点列
$blueprint->point('coordinates') - 指定SRID创建几何点列
$blueprint->point('coordinates', 4326) - 创建线性字符串列
$blueprint->linestring('coordinates') - 创建多边形列
$blueprint->polygon('coordinates') - 创建几何集合列
$blueprint->geometrycollection('coordinates') - 创建多点列
$blueprint->multipoint('coordinates') - 创建多线字符串列
$blueprint->multilinestring('coordinates') - 创建多边形列
$blueprint->multipolygon('coordinates') - 创建不指定第二个或第三个参数的双精度浮点列
$blueprint->double('foo')(但支持$blueprint->double('foo', 5, 2)) - 创建带有
useCurrent修饰符的时间戳列$blueprint->timestamp('created_at')->useCurrent()
许可证
本软件受MIT许可证许可。