Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP says: Call to undefined function yajra\\Pdo\\oci_connect() but I have OCI8 installed and enabled #54

Closed
rgiaviti opened this issue Jan 31, 2015 · 15 comments

Comments

@rgiaviti
Copy link

Ok, guys, I don't know for sure if this is a bug, but I report it because this is very strange. First of wall, I got this error when I try to seed my database using the comand (only when I try to seed):

 php artisan db:seed

Then I got the error:

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to undefined function yajra\Pdo\oci_connect()","file":"/var/www/html/po/vendor/yajra/laravel-pdo-via-oci8/src/yajra/Pdo/Oci8.php","line":81}}

Ok, now first question: Do I have to install PDO OCI?

I just installed OCI8 with Instant Client 12:

sudo pecl install oci8

Added: extension=oci8.so in oci8.ini at /etc/php5/fpm/conf.d. Checked the install with <?php phpinfo(); ?>and it's OK (see attached image).
oci8

Well, after all those configuration, I started install yajra/laravel-oci8. Added the configuration at composer.json. Added, yajra\Oci8\Oci8ServiceProvider' in config/app.php and I configured the database. Ok then, now I can connect successfully but I got the error when I try to seed the database.

My environment:

  • Apache 2.4;
  • PHP 5.6;
  • Laravel 4.2;
  • PHP OCI8 2.0.8.
  • yajra/laravel: 2.1.0;
  • Oracle Instant Client 12.1;
  • Linux Mint 17.1
@yajra
Copy link
Owner

yajra commented Jan 31, 2015

You don't need to install PDO_OCI.

Question: Does Laravel works when you access it on the browser? Try testing the connection on a test route. If it works then the problem must be on your PHP CLI configuration.

Route::get('test', function() {
    dd (DB::connection()->getPdo());
});

@yajra
Copy link
Owner

yajra commented Jan 31, 2015

Also check your PHP CLI environment. Most probably, you have multiple php installations? Try running php -v and which php to verify if you have the correct settings.

@rgiaviti
Copy link
Author

Hi! Thanks for the answers! I have installed PHP with sudo apt-get install php5-cli php5-fpm (PHP is running as FastCGI). Besides php5-fpm and php5-cli, I uinstalled a lot of other libraries. If I run php -v:

rgiaviti@unformint ~ $ php -v
PHP 5.6.5-1+deb.sury.org~trusty+1 (cli) (built: Jan 26 2015 11:42:37)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
rgiaviti@unformint ~ $

About your second question, yes, it works when I access on the browser. I just changed your code to specify my Oracle connection (not my default connection):

Route::get('test', function() {
    dd(DB::connection('e1')->getPdo());
});

When I accessed on the browser, no error has been shown. Output:

object(yajra\Pdo\Oci8)[218]
  public '_dbh' => resource(4, oci8 connection)
  protected '_options' => 
    array (size=4)
      8 => int 2
      3 => int 2
      11 => int 0
      'charset' => string 'AL32UTF8' (length=8)
  protected '_inTransaction' => boolean false
  protected '_table' => null

To provide more details about this problem, here is the seed that when I run, raises the problem shown. In my seed, I connect in a Oracle database, query against it, get the data and insert into my default database (pgsql).

public function run() {
    DB::transaction(function() {
        DB::table('activities')->delete();

        $e1Activities = DB::connection('e1')->select('SELECT * FROM vw_activities');

        foreach($e1Activities as $e1Atv) {
            $poAtv = array('code' => trim($e1Atv->code),
                           'desc' => trim($e1Atv->desc),
                           'type' => $e1Atv->type,
                           'codeu' => $e1Atv->codeu,
                           'codedir' => $e1Atv->codedir,
                           'sigdir' => $e1Atv->sigdir,
                           'codeemp' => $e1Atv->codeemp,
                           'codetec' => $e1Atv->codetec,
                           'active' => $e1Atv->active,
                           'conv' => trim($e1Atv->conv),
                           'user' => trim($e1Atv->user),
                           'codemas' => $e1Atv->codemas,
                           'date' => $e1Atv->date);

            DB::table('activities')->insert($poAtv);
        }
    });
}

@rgiaviti
Copy link
Author

rgiaviti commented Feb 2, 2015

Hi! More details. Maybe can help.

I tried to run the same command in another enviroment (my work - Linux Mint also and Windows 7 64 bits with Xampp). Same problem. On Windows machine, I collected the stacktrace (below). Now I don't know if this is a bug or if there is a problema with my project. :(

The error occurs exactly on this line in the seeder: DB::connection('e1')->select('SELECT * FROM vw_atividade'); But, if I use my default connection, for exemple, DB::select('select * from table');, it works fine!

[2015-02-02 15:02:06] production.ERROR: exception 'yajra\Pdo\Oci8\Exceptions\Oci8Exception' in C:\Desenvolvimento\xampp\htdocs\po\vendor\yajra\laravel-pdo-via-oci8\src\yajra\Pdo\Oci8.php:88
Stack trace:
#0 C:\Desenvolvimento\xampp\htdocs\po\vendor\yajra\laravel-oci8\src\yajra\Oci8\Connectors\OracleConnector.php(41): yajra\Pdo\Oci8->__construct('(DESCRIPTION = ...', 'dta', 'dta', Array)
#1 C:\Desenvolvimento\xampp\htdocs\po\vendor\yajra\laravel-oci8\src\yajra\Oci8\Connectors\OracleConnector.php(56): yajra\Oci8\Connectors\OracleConnector->createConnection('(DESCRIPTION = ...', Array, Array)
#2 C:\Desenvolvimento\xampp\htdocs\po\vendor\yajra\laravel-oci8\src\yajra\Oci8\Oci8ServiceProvider.php(47): yajra\Oci8\Connectors\OracleConnector->connect(Array)
#3 [internal function]: yajra\Oci8\Oci8ServiceProvider->yajra\Oci8\{closure}(Array, 'e1')
#4 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(173): call_user_func(Object(Closure), Array, 'e1')
#5 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(64): Illuminate\Database\DatabaseManager->makeConnection('e1')
#6 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Database\DatabaseManager->connection('e1')
#7 C:\Desenvolvimento\xampp\htdocs\po\app\database\seeds\admin\TabelaAtividadesSeeder.php(23): Illuminate\Support\Facades\Facade::__callStatic('connection', Array)
#8 C:\Desenvolvimento\xampp\htdocs\po\app\database\seeds\admin\TabelaAtividadesSeeder.php(23): Illuminate\Support\Facades\DB::connection('e1')
#9 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\Connection.php(458): TabelaAtividadesSeeder->{closure}(Object(Illuminate\Database\PostgresConnection))
#10 [internal function]: Illuminate\Database\Connection->transaction(Object(Closure))
#11 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(321): call_user_func_array(Array, Array)
#12 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Database\DatabaseManager->__call('transaction', Array)
#13 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Database\DatabaseManager->transaction(Object(Closure))
#14 C:\Desenvolvimento\xampp\htdocs\po\app\database\seeds\admin\TabelaAtividadesSeeder.php(42): Illuminate\Support\Facades\Facade::__callStatic('transaction', Array)
#15 C:\Desenvolvimento\xampp\htdocs\po\app\database\seeds\admin\TabelaAtividadesSeeder.php(42): Illuminate\Support\Facades\DB::transaction(Object(Closure))
#16 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\Seeder.php(37): TabelaAtividadesSeeder->run()
#17 C:\Desenvolvimento\xampp\htdocs\po\app\database\seeds\DatabaseSeeder.php(15): Illuminate\Database\Seeder->call('TabelaAtividade...')
#18 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Database\Console\SeedCommand.php(57): DatabaseSeeder->run()
#19 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Console\Command.php(112): Illuminate\Database\Console\SeedCommand->fire()
#20 C:\Desenvolvimento\xampp\htdocs\po\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(253): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 C:\Desenvolvimento\xampp\htdocs\po\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 C:\Desenvolvimento\xampp\htdocs\po\vendor\symfony\console\Symfony\Component\Console\Application.php(889): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 C:\Desenvolvimento\xampp\htdocs\po\vendor\symfony\console\Symfony\Component\Console\Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\SeedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 C:\Desenvolvimento\xampp\htdocs\po\vendor\symfony\console\Symfony\Component\Console\Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 C:\Desenvolvimento\xampp\htdocs\po\artisan(59): Symfony\Component\Console\Application->run()
#26 {main} [] []

@yajra
Copy link
Owner

yajra commented Feb 3, 2015

Hi,

The output on your browser indicates that oci8 is working properly. However, it is weird why oci_connect could not be found on the terminal. Were you able to setup the Oracle Environments?

Troubleshooting

The most common problem with installing OCI8 is not having the Oracle environment correctly set. This typically appears as a problem using oci_connect() or oci_pconnect(). The error may be a PHP error such as Call to undefined function oci_connect(), an Oracle error such as ORA-12705, or even an Apache crash. Check the Apache log files for startup errors and see the sections above to resolve this problem.

@rgiaviti
Copy link
Author

rgiaviti commented Feb 3, 2015

Well, after days working and researching about this issue, I think I got, at least, one conclusion: *Oracle is a Hell on Earth!

I have tested on two Linux Machines and one Windows Machine. All of them had the same problem. However, on my last try on Linux, I purged every PHP package, Apache and Oracle Client from my system. Completely clean.

Then, I downloaded Xampp for Linux and I enabled oci8 under xampp using default client that ships with xampp (version 11.2.0.3.0). Tested with <?php phpinfo(); ?> and it worked. Tested with php artisan db:seed and it WORKED!

Don't know why, but it worked. I think it's because Oracle Instant Client version, but I tried with versions 12, and 10 (both 32 and 64 bits). They didn't worked.

Well, now I will keep working with xampp.

@rgiaviti rgiaviti closed this as completed Feb 3, 2015
@yajra
Copy link
Owner

yajra commented Feb 4, 2015

Yeah, I agree that setting up oci8 is a bit frustrating. Been there on my first or so months working on php oracle and sort it out using Zend Server which works well out of the box just by enabling oci8 extension. ^_^

Anyways, good to know that you sort it out on Xampp. 🍻

@yajra
Copy link
Owner

yajra commented Mar 6, 2015

Hi! Just experienced this issue today while setting up homestead with php5-fpm. The solution for this was to add extension=oci8.so on /etc/php5/cli/php.ini. Finally found it after an hour of researching and no luck finding anything that works. This was just a wild guess using trial and error but it works. It appears that cli have different php.ini than the fpm/web config.

@rgiaviti
Copy link
Author

rgiaviti commented Jun 8, 2015

Thank you! Today I setup a new enviroment for a new project and I experienced this issue again. I created a new file named 20-oci.ini under /etc/php5/cli/conf.d and added your suggested content to it: extension=oci8.so and worked like a charm. Thank you very much!

@rgiaviti
Copy link
Author

rgiaviti commented Jun 9, 2015

Well, the error always occurs when I use command line tools, like migrate or seed. So, when I use php artisan migrate, for example, I think the system is using the cli php.ini and not fpm. This explains why was not finding oci_connect() function.

@yajra
Copy link
Owner

yajra commented Jun 9, 2015

Yes, I can confirm that CLI have different config than fpm. BTW, if you're still having problems on your environment, try using my version of homestead-oracle. This is what I am using for my development and I do not encounter errors like this so far.

@rafatv
Copy link

rafatv commented Oct 24, 2015

Hi everybody. I recently installed this library using WAMP. I spent almost two days trying to configurate it, but the error wasn't in the library. The thing is that WAMP has TWO php.ini files. The one you choose from the icon in your System Tray is the file in php folder, but also you have to uncomment the "extension=php_oci8_11g.dll" in the php.ini found in the apache/bin folder so you can use artisan in your CLI.
Hope this save time to many people ;)

@amrigo
Copy link

amrigo commented Jan 3, 2017

@Tugsbayar
Copy link

I have a same issue. I use following requirement:

"require": {
        "laravel/framework": "4.2.11",
        "yajra/laravel-oci8": "1.*",
}

Is the version 1.* compatible with php 5.6?

@falahatiali
Copy link

@yajra : yajra can i migrate in oracle ?
i work with oracle in laravel with ur packege and work corrrectly . now i want to create migrate and work with them . but i get this error :
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function Yajra\Pdo\oci_connect()

@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants