Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

사전 작업

PHP용 OCI 드라이버가 설치되어야 한다.

위 문서에 있는 SELinux 정책 변경도 사전에 적용해 두자.

 


설치

  1. composer.json 에 laravel용 오라클 패키지인 yajra/laravel-oci8 를 추가.

    Code Block
    {
        "require": {
            "yajra/laravel-oci8": "~2.0^8"
        }
    }


    컴포저 업데이트 실행

    Code Block
    composer update
  2. 또는 명령행에서 실행

    Code Block
    composer require "yajra/laravel-oci8" "~2.0"
  3. 컴포저 업데이트

    Code Block
    composer update
  4. :^8
  5. OCI Provider 를 laravel 의 service provider 에 등록해 줘야 함. config/app.php 를 열어서 'provides' 에 다음 내용 추가

    Expand
    Code Block
    languagephp
    'providers' => [
    
           /*          * Laravel Framework Service Providers...
             */
    // 추가
           Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
            Illuminate\Auth\AuthServiceProvider Yajra\Oci8\Oci8ServiceProvider::class,
            Illuminate\Broadcasting\BroadcastServiceProvider::class,
            Illuminate\Bus\BusServiceProvider::class,
            Illuminate\Cache\CacheServiceProvider::class,
    		// ...
            // 추가
            yajra\Oci8\Oci8ServiceProvider::class,
        ],],
  6. config/oracle.php 이 생기도록 vendor publishing 실행

    Code Block
    php artisan vendor:publish --tag=oracle
  7. app/database.php 에 DB 연결 정보를 추가한다.

    Code Block
    languagephp
    titledatabase.php
    <?php
    return [
        /*
        |--------------------------------------------------------------------------
        | Default Database Connection Name
        |--------------------------------------------------------------------------
        |
        | Here you may specify which of the database connections below you wish
        | to use as your default connection for all database work. Of course
        | you may use many connections at once using the Database library.
        |
        */
    
    
    'default' => 'oracle',
    'connections' => [
            'oracle' => [
                'driver' => 'oracle',
                'host' => env('ORACLE_HOST'),
                'port' => env('ORACLE_PORT', 1521),
                'database' =>  env('ORACLE_SID'),
                'username' => env('ORACLE_USERNAME'),
                'password' => env('ORACLE_PASSWORD'),
                'charset' => env('ORACLE_CHARSET','AL32UTF8'),
                'prefix' => '',
            ],
            'sqlite' => [
                'driver'   => 'sqlite',
                'database' => __DIR__.'/../database/production.sqlite',
                'prefix'   => '',
            ],
            'mysql' => [
                'driver'    => 'mysql',
                'host'      => 'localhost',
                'database'  => 'forge',
                'username'  => 'forge',
                'password'  => '',
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
            ],
    ],
  8. .env 파일에 연결 정보를 설정한다.

    Code Block
    ORACLE_HOST=myoracle.example.com
    ORACLE_PORT=1521
    ORACLE_SID=mySid
    ORACLE_USERNAME=scott
    ORACLE_PASSWORD=tiger
    ORACLE_CHARSET=AL32UTF8

...

Code Block
php artisan make:model User

...


라우트 파일

Code Block
languagephp
titleroutes.php
Route::get('oratest', function($id) {
	$u = \App\User::find($id)->get();
 
	return $u;
});

웹 브라우저로 http://localhost:8000/oratest/3 에 연결하여 동작 여부 확인

 


만약 다음과 같은 에러가 발생한다면 서비스 프로바이더(yajra\Oci8\Oci8ServiceProvider::class)config/app.php 에 등록했는지 확인.

Code Block
InvalidArgumentException with message 'Unsupported driver [oracle]'

 


사용

blob 

...

Code Block
use yajra\Oci8\Eloquent\OracleEloquent as Eloquent;
 
class Post extends Eloquent {

    // define binary/blob fields
    protected $binaries = ['content'];

    // define the sequence name used for incrementing
    // default value would be {table}_{primaryKey}_seq if not set
    protected $sequence = null;

}

 

 



같이 보기

...