spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Support using only the "database" key for config if using Oracle #12

Closed ekarlso closed 12 years ago

ekarlso commented 12 years ago

In Oracle you can use just the SID / Service Name to connect to the database (it will look up the db via LDAP or tnsnames.ora)

See the attached file.

ekarlso commented 12 years ago

I'll just paste it here instead since I can't push to git at the moment.

ekarlso commented 12 years ago

I remove "localhost" from the config

<?php defined('SYSPATH') or die('No direct access allowed.');

$config = array();

$config['default'] = array( 'type' => 'mysql', // string (e.g. db2, drizzle, firebird, mariadb, mssql, mysql, oracle, postgresql, or sqlite) 'driver' => 'standard', // string (e.g. standard, improved, or pdo) 'connection' => array( 'persistent' => FALSE, // boolean 'hostname' => '', // string 'port' => '', // string 'database' => '', // string 'username' => 'root', // string 'password' => 'root', // string ), 'caching' => FALSE, // boolean 'charset' => 'utf8', // string 'profiling' => FALSE, // boolean 'table_prefix' => '', // string );

return $config; ?>

ekarlso commented 12 years ago

leap/classes/base/db/oracle/connection/standard.php -> open() - Made a change to use the database if not $host...

public function open() {
    if ( ! $this->is_connected()) {
        $host = $this->data_source->host;
        $database = $this->data_source->database;

        if ( ! empty($host) ) {
            $connection_string = '//'. $this->data_source->host;
            $port = $this->data_source->port; // default port is 1521
            if ( ! empty($port)) {
                $connection_string .= ':' . $port;
            }
            $connection_string .= '/' . $this->data_source->database;
        } elseif ( isset($database) ) {
            $connection_string = $this->data_source->database;
        } else {
            throw new Kohana_Database_Exception("Bad configuration, need either a //host[:port][/service_name] or a database name scheme");
        }
        $username = $this->data_source->username;
        $password = $this->data_source->password;
        #echo $connection_string . "<br/>";
        $this->link_id = ($this->data_source->is_persistent())
            ? @oci_pconnect($username, $password, $connection_string)
            : @oci_connect($username, $password, $connection_string);
        if ($this->link_id === FALSE) {
            $oci_error = oci_error();
            $this->error = 'Message: Failed to establish connection. Reason: ' . $oci_error['message'];
            throw new Kohana_Database_Exception($this->error, array(':dsn' => $this->data_source->id));
        }
        $this->execution_mode = OCI_COMMIT_ON_SUCCESS;
    }
}
spadefoot commented 12 years ago

Awesome! I will integrate this code in today and make the necessary changes elsewhere in the code to allow for this.