Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 = 'leandro@leandroafonso.com';
         $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 ) )


16.2k
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: http://forum.phalconphp.com/help/markdown



26.8k

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