...
위 문서에 있는 SELinux 정책 변경도 사전에 적용해 두자.
설치
composer.json 에 laravel용 오라클 패키지인 yajra/laravel-oci8 를 추가.
Code Block { "require": { "yajra/laravel-oci8": "~2.0" } }
또는 명령행에서 실행
Code Block composer require "yajra/laravel-oci8" "~2.0"
컴포저 업데이트
Code Block composer update
OCI Provider 를 laravel 의 service provider 에 등록해 줘야 함. config/app.php 를 열어서 'provides' 에 다음 내용 추가
Expand Code Block language php 'providers' => [ /* * Laravel Framework Service Providers... */ Illuminate\Foundation\Providers\ArtisanServiceProvider::class, Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Illuminate\Bus\BusServiceProvider::class, Illuminate\Cache\CacheServiceProvider::class, // ... // 추가 yajraYajra\Oci8\Oci8ServiceProvider::class, ],
app/database.php 에 DB 연결 정보를 추가한다.
Code Block language php title database.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' => '', ], ],
.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 | ||||
---|---|---|---|---|
| ||||
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; } |
...
같이 보기
...