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

Passing Options to Connection and other Issue #84

Open
anvaya opened this issue Aug 12, 2021 · 1 comment
Open

Passing Options to Connection and other Issue #84

anvaya opened this issue Aug 12, 2021 · 1 comment

Comments

@anvaya
Copy link

anvaya commented Aug 12, 2021

Hi,

We were trying to enable SSL for our MySQL connection by setting up PDO::MYSQL_ATTR_SSL_CA and other attributes, turns out there is no way to achieve it using databases.yml. While there seems to be attributes and an a vague "other" option being used in code, nothing gets passed to the actual connection.

lexpress/doctrine1/lib/Doctrine/Connection.php Line 215 in constructor:

$this->options['other'] = array();
if (isset($adapter['other'])) {
    $this->options['other'] = array(Doctrine_Core::ATTR_PERSISTENT => $adapter['persistent']);
}

First of all, if $adaptor["other"] is being checked, not sure why values in $adaptor["other"] are not being passed on to this->options. Secondly, why would $adaptor["other"] guarantee the presence of $adaptor["persistent"] is beyond me. Clearly seems to be an error.

There is also an issue with getOption method code (Line 262). If the option is not set, the code has no return value, making it a method that can be void and returning a value at the same time. Shouldn't it return null or false?

/**
     * getOption
     *
     * Retrieves option
     *
     * @param string $option
     * @return void
     */
    public function getOption($option)
    {
        if (isset($this->options[$option])) {
            return $this->options[$option];
        }
    }

We had to ultimately use the event doctrine.configure_connection in order to add PDO::MYSQL_ATTR_SSL_CA to the connection's other property in order to get the SSL connection. I think there has to be some way to pass additional options to the connection through databases.yml.

@alquerci
Copy link

alquerci commented Aug 15, 2021

Hello @anvaya,

Problematic

As I understand, you want to use the SSL connection.

As you said, currently, Doctrine1 does not support SSL connection.

There is the list of supported PDO attributes,

Possible solution

Extends doctrine to add the feature.

  1. Extends the doctrine driver used

    class My_Connection_Mysql extends Doctrine_Connection_Mysql
    {
        public function __construct(Doctrine_Manager $manager, $adapter, $user = null, $pass = null)
        {
             parent::__construct($manager, $adapter, $user, $pass);
    
            // here you can hydrate `$this->options['other']` from parameters of $adapter
        }
    }
  2. Listen to doctrine.configure event (the subject is an instance of Doctrine_Manager)

    Doctrine_Manager::registerConnectionDriver('mysql', 'My_Connection_Mysql')
  3. You can pass option to the DSN on attributes.yml.

        dsn: 'mysql://user:pass@localhost/foo_dbname?key=client-key.pem&cert=client-cert.pem'

Example

With

    dsn: 'mysql://localhost/jobeet?foo=bar&key=foo'

$adapter

array:10 [▼
  "scheme" => "mysql"
  "host" => "localhost"
  "path" => "/jobeet"
  "query" => "foo=bar&key=foo"
  "dsn" => "mysql:host=localhost;dbname=jobeet"
  "port" => null
  "user" => null
  "pass" => null
  "fragment" => null
  "database" => "jobeet"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants