Magento – Passing thesql protocol parameter in local.xml

local.xmlmagento-1.9MySQL

I have to connect to mysql database specifing the protocol as in this command line:

mysql -P port_number -u user -ppassword --protocl=tcp -D database -h hostname

Well, port number I think is possible to pass adding ":port_number" to the "hostname" in tag. User name, database and password have their own tag as in the next example:

<connection>
    <host><![CDATA[hostname:port_number]]></host>
    <username><![CDATA[user]]></username>
    <password><![CDATA[password]]></password>
    <dbname><![CDATA[pierpape_reciele]]></dbname>
    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
    <model><![CDATA[mysql4]]></model>
    <type><![CDATA[pdo_mysql]]></type>
    <pdoType><![CDATA[]]></pdoType>
    <active>1</active>
</connection>

What about some other parameter like "protocol"?

Best Answer

Adding

<protocol><![CDATA[tcp]]></protocol>

to the <connection> element should work, because in the end, any additional elements gets added to the PDO dsn string, as you can see in Zend_Db_Adapter_Pdo_Abstract::_dsn():

/**
 * Creates a PDO DSN for the adapter from $this->_config settings.
 *
 * @return string
 */
protected function _dsn()
{
    // baseline of DSN parts
    $dsn = $this->_config;

    // don't pass the username, password, charset, persistent and driver_options in the DSN
    unset($dsn['username']);
    unset($dsn['password']);
    unset($dsn['options']);
    unset($dsn['charset']);
    unset($dsn['persistent']);
    unset($dsn['driver_options']);

    // use all remaining parts in the DSN
    foreach ($dsn as $key => $val) {
        $dsn[$key] = "$key=$val";
    }

    return $this->_pdoType . ':' . implode(';', $dsn);
}

It's using a blacklist, to not add configurations that are passed differently but it doesn't restrict any other parameters. So the configuration will result in this dsn, which should work for you:

mysql:protocol=tcp;host=hostname:portnumber;dbname=pierpape_reciele
Related Topic