Pdo in command line php?

I had the following problem when trying to connect to oracle database from PHP when running in command line

"DB Connection failed: could not find driver"

the connection function was as follows

function databaseConnection(){
$dsn = 'oci:dbname=localhost/';
$user = '';
$password = 'password';

try {
$pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage()."\n";

return $pdo;

and from the web server all was fine

but when i try to run it from command line i get this error
"DB Connection failed: could not find driver"

The problem was that PHP , when running from command line ,was not "looking" at the same "php.ini" as it was looking when running from the WEB

To fix it i added the environment variable:"PHPRC" that points to "C:\xampp\apache\bin" where my real php.ini is located

PHPRC environment variable tells PHP where to look for the php.ini

below you can see the search order of php.ini from PHP script

This file controls many aspects of PHP's behavior. In order for PHP to
; read it, it must be named 'php.ini'. PHP looks for it in the current
; working directory, in the path designated by the environment variable
; PHPRC, and in the path that was defined in compile time (in that order).
; Under Windows, the compile-time path is the Windows directory. The
; path in which the php.ini file is looked for can be overridden using
; the -c argument in command line mode.