dok55/laravel-sybase

基于Sybase的Eloquent模块扩展,适用于Laravel 5.x。

2.4.6 2021-02-23 02:00 UTC

README

Packagist Version PHP from Packagist Packagist GitHub contributors GitHub

  • 启用使用多种类型的字段。
  • 使用默认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

"uepg/laravel-sybase": "~2.0"

执行以下命令更新包依赖项

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' => 'sqlsrv',
            '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',
            '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

设置为使用数字数据类型

在迁移文件中,您必须将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');
    }
}