yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8
https://yajrabox.com/docs/laravel-oci8
MIT License
834 stars 237 forks source link

Use of undefined constant OCI_CRED_EXT - assumed 'OCI_CRED_EXT' (this will throw an Error in a future version of PHP) #506

Closed muhghazaliakbar closed 5 years ago

muhghazaliakbar commented 5 years ago

Summary of problem or feature request

I'm having error when trying to select table. Anyone can help?

Code snippet of problem

Route::get('test-oracle-connection', function () {
    $sspd = \Illuminate\Support\Facades\DB::connection('oracle')->table('sspd')->first();

    dd($sspd);
});

Errors:

Use of undefined constant OCI_CRED_EXT - assumed 'OCI_CRED_EXT' (this will throw an Error in a future version of PHP)

System details

anugrahdputra commented 5 years ago

i got same problem

muhghazaliakbar commented 5 years ago

@anugrahdputra Did you figured out?

yajra commented 5 years ago

@muhghazaliakbar can you please provide the table's migration? Working fine on my side using the users table.

   tinker
Psy Shell v0.9.9 (PHP 7.1.26 — cli) by Justin Hileman
>>> DB::table('users')->first();
=> {#4125
     +"id": "1",
     +"first_name": "CMS",
     +"last_name": "Administrator",
     +"email": "admin@example.com",
     +"email_verified_at": null,
     +"is_activated": "1",
     +"is_blocked": "0",
     +"password": "$2y$10$F8GAwF/tAl6HWDvxxvqDDOkGstYvV8jmahvPbI3bRc.54U821qfeK",
     +"avatar": null,
     +"parameters": null,
     +"is_admin": "1",
     +"remember_token": "hkx4oIZ4MP",
     +"verification_token": null,
     +"deleted_at": null,
     +"created_by": "0",
     +"updated_by": "0",
     +"created_at": "2019-05-09 02:33:36",
     +"updated_at": "2019-05-09 02:33:36",
   }
>>>
anugrahdputra commented 5 years ago

@muhghazaliakbar @yajra

Code snippet of problem $data = DB::connection('oracle')->select('SELECT * FROM SW_DB WHERE ROWNUM = 1')

It working fine with tinker, but doesn't work from laravel controller and give this error Use of undefined constant OCI_CRED_EXT - assumed 'OCI_CRED_EXT' (this will throw an Error in a future version of PHP)

System Detail

yajra commented 5 years ago

Still working for me. There might be something odd on your table which may cause the issue?

Route::get('/', function () {
    dump(DB::select('select * from users where rownum=1'));
    dd(DB::table('users')->first());
});
array:1 [▼
  0 => {#1369 ▼
    +"id": "1"
    +"first_name": "CMS"
    +"last_name": "Administrator"
    +"email": "admin@example.com"
    +"email_verified_at": null
    +"is_activated": "1"
    +"is_blocked": "0"
    +"password": "$2y$10$F8GAwF/tAl6HWDvxxvqDDOkGstYvV8jmahvPbI3bRc.54U821qfeK"
    +"avatar": null
    +"parameters": null
    +"is_admin": "1"
    +"remember_token": "hkx4oIZ4MP"
    +"verification_token": null
    +"deleted_at": null
    +"created_by": "0"
    +"updated_by": "0"
    +"created_at": "2019-05-09 02:33:36"
    +"updated_at": "2019-05-09 02:33:36"
  }
]
{#1375 ▼
  +"id": "1"
  +"first_name": "CMS"
  +"last_name": "Administrator"
  +"email": "admin@example.com"
  +"email_verified_at": null
  +"is_activated": "1"
  +"is_blocked": "0"
  +"password": "$2y$10$F8GAwF/tAl6HWDvxxvqDDOkGstYvV8jmahvPbI3bRc.54U821qfeK"
  +"avatar": null
  +"parameters": null
  +"is_admin": "1"
  +"remember_token": "hkx4oIZ4MP"
  +"verification_token": null
  +"deleted_at": null
  +"created_by": "0"
  +"updated_by": "0"
  +"created_at": "2019-05-09 02:33:36"
  +"updated_at": "2019-05-09 02:33:36"
}
anugrahdputra commented 5 years ago

@yajra thank you, my problem has been solved. yesterday an error occurred because I used php7.3 on the ubuntu setting but php apache2 still uses php7.2

muhghazaliakbar commented 5 years ago

@anugrahdputra @yajra Can you show me your .env config please?

anugrahdputra commented 5 years ago

@muhghazaliakbar My problem yesterday was not Laravel or Laravel-Oci8, but a problem with PHP settings. But this is my .env config


ORACLE_CONNECTION=oraview
ORACLE_HOST=172.16.10.8
ORACLE_PORT=3334
ORACLE_DATABASE=JR
ORACLE_USERNAME=JR_USER
ORACLE_PASSWORD=
ascali commented 5 years ago

@muhghazaliakbar My problem yesterday was not Laravel or Laravel-Oci8, but a problem with PHP settings. But this is my .env config

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Tk2Z9C8vuQ9FHqDJhAYutvTQixdzl9FBkzblfXD4YA0=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jr_laravel_oracle
DB_USERNAME=root
DB_PASSWORD=

ORACLE_CONNECTION=oraview
ORACLE_HOST=172.16.10.8
ORACLE_PORT=3334
ORACLE_DATABASE=JR
ORACLE_USERNAME=JR_USER
ORACLE_PASSWORD=p4$$w0rD

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Here my .env set up for oracle DBDRKOUTEI_CONNECTION=oracle DBDRKOUTEI_HOST=xxxxx-server DBDRKOUTEI_HOSTIPL=xxxxxxxx DBDRKOUTEI_PORT=1521 DBDRKOUTEI_SID=orcl DBDRKOUTEI_USERNAME=xxxxxx DBDRKOUTEI_PASSWORD=xxxxx DBDRKOUTEI_DATABASE=xxxxx

hope this help you @anugrahdputra

ascali commented 5 years ago

Hi @yajra please help me, I stuck with that error , any clue for that ? I have searched for it on stackoverflow and google, but still haven't found the answer.

Here is the source code that I wrote in Lumen 5.8.*:

    $xxx= DB::connection('xxxxx');
    $current_month = date('m-Y');
    $proses = $xxx->select("
      SELECT cstmr_cd, COUNT(*) AS count_mold
      FROM t_jobno 
      WHERE TO_CHAR(PROC_DEADLINE, 'MM-YYYY') = '$current_month' AND cstmr_cd IS NOT NULL
      AND MFGNO NOT IN ( 'P-KYI-2dp RA Fix', 'TES', 'Contoh Try Sample', 'Z-KAIZEN', 'OTHER', 'SIMUL-G300TAC-B2', 'SIMUL-P-ACC-946F CC', 'KYI XXX', 'P-AAC-XXX' )
      GROUP BY cstmr_cd ORDER BY cstmr_cd ASC
    ");
    if ($proses!=null){
      return responses(1,'',$proses,200);
    }else{
      return responses(0,'Gagal mengambil data',[],404);
    } 

and some logs:

Use of undefined constant OCI_CRED_EXT - assumed 'OCI_CRED_EXT' (this will throw an Error in a future version of PHP)
in OracleConnector.php line 41
at Application->Laravel\Lumen\Concerns\{closure}(2, 'Use of undefined constant OCI_CRED_EXT - assumed \'OCI_CRED_EXT\' (this will throw an Error in a future version of PHP)', 'C:\\inetpub\\wwwroot\\fusion\\dashboard_meiwa_api\\vendor\\yajra\\laravel-oci8\\src\\Oci8\\Connectors\\OracleConnector.php', 41,array('config' => array('driver' => 'oracle', 'host' => '192.168.1.xxx', 'port' => '1521', 'database' => 'xxxxxx', 'service_name' => 'orcl', 'username' => 'xxxxxx, 'password' => 'xxxxx', 'charset' => 'AL32UTF8', 'prefix' => '', 'strict' => false, 'name' => 'xxxx'), 'tns' => '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.xxx)(PORT = 1521)) (CONNECT_DATA =(SERVICE_NAME = orcl)))', 'options' => array(2, 2, 0)))in OracleConnector.php line 41

The actions I have taken:

  1. I previously run on a standalone php server (php 7.25)
  2. then I move to the iis server with php 7.25

The version in composer I use today is

    "require": {
        "php": ">=7.2.5",
        "laravel/lumen-framework": "5.8.*",
        "vlucas/phpdotenv": "^3.3",
        "staudenmeir/eloquent-param-limit-fix": "^1.0",
        "yajra/laravel-oci8": "5.8.*"
    },
yajra commented 5 years ago

~~@ascali are you using Windows OS? It seems like OCI_CRED_EXT is not supporting it. ~~

This was introduced on #474. Reviewing a possible fix. If you can, please do not hesitate to submit a PR for a fix.

-- EDIT -- It seems like windows is not a culprit since this SO post uses OSX and the OP uses macOS too :).

yajra commented 5 years ago

Maybe suppressing the error might fix the issue? Can you please try the code below. Or maybe a try catch? It's working on my side so I can't reproduce the issue.

//  OracleConnector.php

        if (@array_get($options, 'session_mode') === OCI_CRED_EXT) {
            // External connections can only be used with user / and an empty password
            $config['username'] = '/';
            $config['password'] = null;
        }
ascali commented 5 years ago

Maybe suppressing the error might fix the issue? Can you please try the code below. Or maybe a try catch? It's working on my side so I can't reproduce the issue.

//  OracleConnector.php

        if (@array_get($options, 'session_mode') === OCI_CRED_EXT) {
            // External connections can only be used with user / and an empty password
            $config['username'] = '/';
            $config['password'] = null;
        }

@yajra I changed my code with yours and try what you suggest but there was no change, with the same error. Actualy I have tried to reproduce the error on another server, but that error didn't appear. I'm confused, is it wrong from the library or from my code or else, ..

yajra commented 5 years ago

It's not a problem with the package but on PHP settings as per @anugrahdputra confirmation. But I am not sure what settings needs to be adjusted.

ascali commented 5 years ago

It's not a problem with the package but on PHP settings as per @anugrahdputra confirmation. But I am not sure what settings needs to be adjusted.

I think my settings is fine because previously run normal there is no error, do you have any recomendation about it..

CodinMoldovanu commented 5 years ago

Also confronted with this. Tinker works without issue but running code inside a Controller greets me with the same error as above.

yajra commented 5 years ago

Unfortunately, I can't replicate the issue and not really sure how to fix this. If anyone finds a solution, please do not hesitate to submit a PR. Thanks!

CodinMoldovanu commented 5 years ago

Ok, the issue was not in PHP per se but in configuration of the instant client for Oracle. There's $LD_LIBRARY_PATH and $ORACLE_HOME environment variables which should both point to the path of the instant client.

@ascali can you try setting those two env vars and see if you still encounter the error?

mdemori commented 5 years ago

Hello, I just had the same problem, after one our of testing I found that I forgot to activate the oci8 module on fpm. I just activated it for CLI so, tinker work but I receive the error message inside a controller of my web application.

Activating the module on fpm has fixed the problem for me.

wjgray99 commented 5 years ago

I recently hit upon this issue and was able to resolve it. I came across the problem while updating PHP. The only resolution I've found thus far is to ensure that you are on 64 bit everything (Apache, PHP, AND Oracle Instant Client). Also, be sure to point your Apache (64-bit!) to the correct PHP (64-bit) in httpd.conf. Make sure the 64 bit Instant Client is on your path! Once all the pieces were in the right place... voila.

That undefined constant's value is HUGELY negative (> 32-bit).

Hope this helps!

wjgray99 commented 5 years ago

Unfortunately, I can't replicate the issue and not really sure how to fix this. If anyone finds a solution, please do not hesitate to submit a PR. Thanks!

Yajra... simply put a 32-bit instant client in the path rather than a 64 bit and you will see this error.

yajra commented 5 years ago

@wjgray99 thanks for the inputs. Can't try your solution now but I'm glad you were able to figure this out. Thanks!

JPdiedhiou commented 5 years ago

Hi i'm trying to make a seeder but when i run the command: php artisan make:seed i get this errors i need help for to progress.....

ErrorException : Use of undefined constant users - assumed 'users' (this will throw an Error in a future version of PHP)

at /home/jp/Laravel-projects/Messagerie_version_1.0/database/seeds/UsersTableSeeder.php:15 11| */ 12| public function run() 13| { 14| for($i = 0; $i < 10; $i++){

15| \Illuminate\Support\Facades\DB::table(users)->insert([ 16| 'name'=> "Ghostman$i", 17| 'email'=> "ghost$i@man.sn", 18| "password"=> bcrypt('0000') 19| ]);

Exception trace:

1 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Use of undefined constant users - assumed 'users' (this will throw an Error in a future version of PHP)", "/home/jp/Laravel-projects/Messagerie_version_1.0/database/seeds/UsersTableSeeder.php", []) /home/jp/Laravel-projects/Messagerie_version_1.0/database/seeds/UsersTableSeeder.php:15

2 UsersTableSeeder::run() /home/jp/Laravel-projects/Messagerie_version_1.0/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32

Please use the argument -v to see more details.

CodinMoldovanu commented 5 years ago

@JPdiedhiou you need to use quotes on the table name like so DB::table('table_name')

@yajra can this issue be closed since it was identified that the issue lies in the system configuration? Maybe a change in documentation to be a bit more verbose about the instantclient will solve future issues. Will try to compile some resources and help with this.

yajra commented 5 years ago

I just had the same issue after updating to Catalina but restarting fixes it for me. Closing the issue and thanks for inputs.

cbj4074 commented 4 years ago

Generally, this error seems to occur whenever the oci8 PHP extension is not being loaded for whatever reason. Many of the other descriptions here, such as table reference quote syntax in runtime code, are probably red-herrings.

For example, I encountered this error when debugging with phpdbg, which maintains a completely separate INI configuration from the regular PHP CLI executable. I had forgotten to create a symlink to enable oci8.so specifically for the phpdbg environment and received this error only when running tests.

The bottom line: if you receive this error, check your phpinfo() output in whichever environment you are executing PHP (CLI, PHP-FPM, phpdbg, etc.) and if oci8 is not loaded, there's a problem with the client architecture, the required environment variables (ORACLE_HOME and/or LD_LIBRARY_PATH), or oci8 simply hasn't been enabled in the effective PHP configuration file(s).

rizama commented 3 years ago

similiar problem, but my problem solved by restarting my php using service php-fpm restart (full syntax) because driver oci8 has not detected by php..

nowen21 commented 3 years ago

Buena apreciados parte de la solución la encontré en el siguiente link: https://stackoverflow.com/questions/41632584/c-wamp64-bin-php-php7-0-10-ext-php-oci8-12c-dll-1-is-not-a-valid-win32-app/46761211 y las librerías .dll van de acuerdo a la versión del php que se encuentra en el siguiente link: https://pecl.php.net/package/oci8/2.2.0/windows; en mi caso utilicé: 7.4 Thread Safe (TS) x64. Espero haber contribuido en la solución que me llevó casi una semana encontrarla. Saludos desde Colombia

JPdiedhiou commented 3 years ago

Hello dear, Thank you for this solution. I think it will always help. Best regards

Cordialement DIEDHIOU Jean Pierre [cid:003c5f9c-6ee9-476b-80b4-2584f2cab049] Founder & Ceo Digital Passion Developper | Digital Referent | Graphic Designer Tel: +221 77 233 90 37 / 76 027 19 16 diedhioujp@outlook.com | digital@digitalpassion.io https://www.digitalpassion.io


De : Ing José Dúmar Jiménez Ruíz notifications@github.com Envoyé : vendredi 12 février 2021 18:52 À : yajra/laravel-oci8 laravel-oci8@noreply.github.com Cc : Ghost_man diedhioujp@outlook.com; Mention mention@noreply.github.com Objet : Re: [yajra/laravel-oci8] Use of undefined constant OCI_CRED_EXT - assumed 'OCI_CRED_EXT' (this will throw an Error in a future version of PHP) (#506)

Buena apreciados parte de la solución la encontré en el siguiente link: https://stackoverflow.com/questions/41632584/c-wamp64-bin-php-php7-0-10-ext-php-oci8-12c-dll-1-is-not-a-valid-win32-app/46761211 y las librerías .dll van de acuerdo a la versión del php que se encuentra en el siguiente link: https://pecl.php.net/package/oci8/2.2.0/windows; en mi caso utilicé: 7.4 Thread Safe (TS) x64. Espero haber contribuido en la solución que me llevó casi una semana encontrarla. Saludos desde Colombia

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/yajra/laravel-oci8/issues/506#issuecomment-778383259, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGJ3MHM6CNWYA2NDRO3HWM3S6V2GJANCNFSM4HMHVBHA.

shafiqruslan commented 3 years ago

I'm having the same problem on my intel mac Big Sur. Did anyone fix it?

cbj4074 commented 3 years ago

@shafiqruslan There's nothing to "fix". The OCI8 extension is not registered with PHP correctly, so you need to troubleshoot the reason for that.

I suggest reading my earlier post carefully. Check your phpinfo() output, and if the OCI8 extension is not listed, check the potential causes that I noted.

shafiqruslan commented 3 years ago

@shafiqruslan There's nothing to "fix". The OCI8 extension is not registered with PHP correctly, so you need to troubleshoot the reason for that.

I suggest reading my earlier post carefully. Check your phpinfo() output, and if the OCI8 extension is not listed, check the potential causes that I noted.

Hi, i have a question. i just found php.ini in my computer but not others ini u mention 😅. Can i know where to locate it? In my phpinfo(), it listed oci8 enable.

einnar82 commented 3 years ago

Hello,

It seems that the OCI_CRED_EXT constant is not exist. My workaround is to override the OracleConnector and Oci8ServiceProvider of the existing package. Please see my gist file here.

Make sure that you will declare the App\Providers\Oci8ServiceProvider into the config/app.php

image

I hope it helps anyone else. Thanks!