uepg / laravel-sybase
Laravel 10.x 的基于 Sybase 的 Eloquent 模块扩展
Requires
- php: ^8.1
- ext-pdo: *
- doctrine/dbal: ^3.5.1
- illuminate/database: ^10
- illuminate/support: ^10
Requires (Dev)
- nunomaduro/collision: ^7.4
- orchestra/testbench: ^8.5
- dev-master
- 4.0.0
- 3.0.0
- v2.x-dev
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0
- v1.x-dev
- 1.3.2
- 1.3.1
- 1.3
- 1.2.1
- 1.2.0.7
- 1.2.0.6
- 1.2.0.5
- 1.2.0.4
- 1.2.0.3
- 1.2.0.2
- 1.2.0.1
- 1.2
- 1.1
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0
- 0.3.0
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2
- 0.1.1
- 0.1.0
- dev-revert-84-revert-83-laravel-sybase
- dev-revert-83-laravel-sybase
- dev-dev
This package is auto-updated.
Last update: 2024-09-07 18:35:28 UTC
README
- 启用使用多种类型的字段。
- 使用默认 eloquent:与 odbc 和 dblib 兼容!
- 迁移!(进行中 - Work in Progress)
安装
在您的 composer.json 文件的 require 部分添加以下内容
Laravel 5.1, 5.2, 5.3
"uepg/laravel-sybase": "~1.0"
Laravel 5.4, 5.5, 5.6, 5.7, 5.8, 6.x, 7.x, 8.x, 9.x
"uepg/laravel-sybase": "~2.0"
Laravel 10.x
"uepg/laravel-sybase": "~3.0" // old version //or The new version "uepg/laravel-sybase": "~4.0" // new version
执行以下命令更新包依赖项
composer update
在 config/app.php 文件中您的 providers 数组中添加以下条目,在 Laravel 5.5 或更高版本中是可选的
Uepg\LaravelSybase\SybaseServiceProvider::class,
在 config/app.php 文件中您的 aliases 数组中添加以下条目,在 Laravel 5.5 或更高版本中是可选的
'UepgBlueprint' => Uepg\LaravelSybase\Database\Schema\Blueprint::class,
更新您的 config/database.php 的默认驱动程序为 sybase 或您自定义的 odbc 的设置。以下是一个示例
<?php ... return [ ... 'connections' => [ ... 'sybase' => [ 'driver' => 'sybasease', 'host' => env('DB_HOST', 'sybase.myserver.com'), 'port' => env('DB_PORT', '5000'), 'database' => env('DB_DATABASE', 'mydatabase'), 'username' => env('DB_USERNAME', 'user'), 'password' => env('DB_PASSWORD', 'password'), 'charset' => 'utf8', // Experimental yet, prefer use the `DB_CHARSET` and `APPLICATION_CHARSET` 'prefix' => '', ], ... ], ... ]
更新您的 .env 文件为 sybase 或您自定义的 odbc 的设置。以下是一个示例
...
DB_CONNECTION=sybase
DB_HOST=sybase.myserver.com
DB_PORT=5000
DB_DATABASE=mydatabase
DB_USERNAME=user
DB_PASSWORD=password
...
配置 freetds 驱动程序
在 Linux 系统中,驱动程序版本必须在 freetds.conf 文件中设置为正确的字符集页面使用。
该文件通常位于 /etc/freetds/freetds.conf。以下示例将全局部分配置如下
[global]
# TDS protocol version
tds version = 5.0
配置数据库和应用程序之间的字符集
为了配置数据库和应用程序之间的字符集,在 .env
文件中添加 DB_CHARSET
和 APPLICATION_CHARSET
字段,以下是一个示例
DB_CHARSET=CP850 APPLICATION_CHARSET=UTF8
配置缓存
由于库在收到请求时总是查询表信息,因此可以使用缓存来避免过多的查询。
要使用缓存,将 SYBASE_CACHE_COLUMNS
和 SYBASE_CACHE_COLUMNS_TIME
字段添加到 .env
文件中,以下是一个示例
SYBASE_CACHE_COLUMNS=true SYBASE_CACHE_COLUMNS_TIME=3600 # cache table information by `3600` seconds
设置使用数值数据类型
在迁移文件中,您必须将 use Illuminate\Database\Schema\Blueprint;
替换为 use Uepg\LaravelSybase\Database\Schema\Blueprint;
。以下是一个示例
<?php use Illuminate\Support\Facades\Schema; // use Illuminate\Database\Schema\Blueprint; use Uepg\LaravelSybase\Database\Schema\Blueprint; // or "use UepgBlueprint as Blueprint" use Illuminate\Database\Migrations\Migration; class CreateTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('table_name', function (Blueprint $table) { $table->numeric('column_name', length, autoIncrement); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('table_name'); } }