ccampbell / sonic

fast, lightweight PHP 5.3 MVC framework
http://www.sonicframework.com
Apache License 2.0
63 stars 11 forks source link

expand the appropriate database extension classes to include port/socket options #31

Open csurf opened 11 years ago

csurf commented 11 years ago

the mysql* classes currently only try to make connections with the basic/minimum parameters (username, password, dbname) and passing additional parameters such as host, port/socket,etc. through the dsn doesnt work because the extra parameters are simply ignored; they are never passed through to the 'mysql*_connect()' function.

my hacked solution to this was: -make the following change in the 'Factory' _parseDsn method @ around line 93: // $server['dsn'] = 'mysql:dbname=' . $schema . ';host=' . $server['host']; $server['dsn']=$dsn; *this should allow the full dsn to be passed through & parsed, and the necessary values be populated in the query class.

-add additional properties to the 'Mysql' class protected $_port; protected $_socket;

-add the following to the 'Mysql' constructor $this->_port = (isset($dsn['port']))?$dsn['port']:null; $this->_socket = (isset($dsn['socket']))?$dsn['socket']:'';

-make the following change in the Mysql & Mysqli 'prepare' function if ($this->_link === null) { $this->_link = mysqli_connect($this->_host, $this->_user, $this->_password,$this->_dbname,$this->_port,$this->_socket); *this will allow custom connections to a mysql server (either via tcp or a custom socket)

csurf commented 11 years ago

just realized that the 'mysql_connect()' is rather different from the 'mysqli_connect()' in that it doesnt specify the host/port/socket as distinct parameters; the first param to 'mysql_connect()' should be [ host [:port] | socket ]. So, additional logic would need to be added to create the appropriate 'host' param string for the 'mysql_connect()' call within the 'Mysql::prepare()' method. perhaps something like this? protected function _getHost(){ if (!is_null($this->_socket)) return $this->_socket $host=(!is_null($this->_host)) ? $this->_host : 'localhost'; if(!is_null($this->_port)) $host.=':'.$this->_port; return $host; }