We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

May be a bug or dumb user? - Connecting to Oracle

when I try run this code bellow on controller, its fine! returns data from database:

         $test = new Phalcon\Db\Adapter\Pdo\Oracle(array(
             'adapter'     => 'Oracle',
             'username'    => 'SAAS',
             'password'    => 'saas',
             'dbname'      => '//192.168.120.27/XE',
             'schema' => 'SAAS'
         ));
         $rs=$test->query("select * from USERS");
         print_r($rs->fetchAll());

It's ok! returns data from oracle DB.

When I run this code below, hoping to use the connection as defined in config.:

   $user = new Users();
         $user->name = 'leandro';
         $user->email = '[email protected]';
         $user->id = 1;
         $user->save();
         print_r($user);
        die;

My database config session:

     'database' => array(
         'adapter'     => 'Oracle',
         'username'    => 'TEKNISA_SAAS',
         'password'    => 'teknisa',
         'host'        => '192.168.120.27',
         'dbname'      => 'XE',
         'schema'      => 'TEKNISA_SAAS'
     ),

Dont works! :-(

Returns error:

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (translated from portuguese)

Trace

 #0
     Class: PDO
     line:#
     Function:__construct Array ( [0] => mysql:host=192.168.120.27;dbname=XE;schema=SAAS [1] => SAAS [2] => saas [3] => Array ( [3] => 2 ) ) 
 #1
     Class: Phalcon\Db\Adapter\Pdo
     line:#
     Function:connect Array ( [0] => Array ( [host] => 192.168.120.27 [username] => SAAS [password] => saas [dbname] => XE [schema] => SAAS ) ) 
 #2
     Class: Phalcon\Db\Adapter\Pdo
     line:#63
     Function:__construct Array ( [0] => Array ( [host] => 192.168.120.27 [username] => SAAS [password] => saas [dbname] => XE [schema] => SAAS ) )


22.5k
Accepted
answer
edited Apr '14

I believe this is a bug in the config class because even defining an Oracle adapter is being instantiated the Mysql adapter.

I commented to the config database session and created the adapter instance in the oracle bootstrap and set the oracle adapter in di as follows and it worked perfectly.

$config = array(

         "dbname" => "//192.168.120.27/XE",
         "username" => "SAAS",
         "password" => "saas"
     );
     $connection = new Phalcon\Db\Adapter\Pdo\Oracle($config);
     $di->set('db',$connection);

@Leandro: I've re-formatted your post with better code highlighting. "Edit" your post to see what I did, or look at the help to learn more: https://forum.phalcon.io/help/markdown



81.1k

In this part of my devtolols Phalcon DevTools (2.0.7) remains unreacted expecting something from the web interface is the same if I specify the schema name, otherwise tells me that the table does not exist