laravel-oci8
laravel-oci8 copied to clipboard
Get nextId using insertGetId.
Summary of problem or feature request
When using this code:
$nextId = \DB::table('table')->insertGetId([]);
I get the following exception:
[2020-03-04 17:11:26] local.ERROR: Undefined index: object {"exception":"[object] [2020-03-04 17:25:34] local.ERROR: Undefined index: object {"exception":"[object] (ErrorException(code: 0): Undefined index: object at /var/www/html/vendor/yajra/laravel-oci8/src/Oci8/Query/Grammars/OracleGrammar.php:253)
[stacktrace]
#0 /var/www/html/vendor/yajra/laravel-oci8/src/Oci8/Query/Grammars/OracleGrammar.php(253): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/html/v...', 253, Array)
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2155): Yajra\\Oci8\\Query\\Grammars\\OracleGrammar->compileInsertGetId(Object(Yajra\\Oci8\\Query\\OracleBuilder), Array, 'id')
this code given error
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 4)[2]['object'];
Code snippet of problem
The way that I'm trying to connect looks like this:
config\oracle.php
<?php
return [
'oracle' => [
'driver' => 'oracle',
'tns' => env('ORACLE_DB_TNS', ''),
'host' => env('ORACLE_DB_HOST'),
'port' => env('ORACLE_DB_PORT', '1521'),
'database' => env('ORACLE_DB_DATABASE'),
'username' => env('ORACLE_DB_USER'),
'password' => env('ORACLE_DB_PASSWORD'),
'charset' => env('ORACLE_DB_CHARSET', 'JA16SJIS'),
'prefix' => env('ORACLE_DB_PREFIX', ''),
'prefix_schema' => env('ORACLE_DB_SCHEMA_PREFIX', ''),
],
];
System details
- linux(docker container php:7,2-fpm)
- PHP 7.2
- Laravel 5.5.*
- Laravel-OCI8 5.5.*
Is it the recommended way to get the next id? I think you should be getting it directly from the sequence?
DB::getSequence()->nextValue('USERS_ID_SEQ');