MySQL socket/pipe support

A place to talk about what is going on with Tera-WURFL's development, what will be included in upcoming releases and what you would like to see added to an upcoming version.

MySQL socket/pipe support

Postby dryabov » Sun Sep 12, 2010 4:59 pm

Sometimes for DB connections socket/pipe is used instead of tcp/ip. Whether it is possible to include support of socket/pipe connections in the TeraWURFL?

As an example of typical (but not ideal) procedure of DB connection, let me post the source code from Joomla!CMS (it allows to use both variant: non-standard tcp/ip port or the non-standard socket/pipe):
Code: Select all
   function __construct( $options )
   {
      $host      = array_key_exists('host', $options)   ? $options['host']      : 'localhost';
      $user      = array_key_exists('user', $options)   ? $options['user']      : '';
      $password   = array_key_exists('password',$options)   ? $options['password']   : '';
      $database   = array_key_exists('database',$options)   ? $options['database']   : '';
      $prefix      = array_key_exists('prefix', $options)   ? $options['prefix']   : 'jos_';
      $select      = array_key_exists('select', $options)   ? $options['select']   : true;

      // Unlike mysql_connect(), mysqli_connect() takes the port and socket
      // as separate arguments. Therefore, we have to extract them from the
      // host string.
      $port   = NULL;
      $socket   = NULL;
      $targetSlot = substr( strstr( $host, ":" ), 1 );
      if (!empty( $targetSlot )) {
         // Get the port number or socket name
         if (is_numeric( $targetSlot ))
            $port   = $targetSlot;
         else
            $socket   = $targetSlot;

         // Extract the host name only
         $host = substr( $host, 0, strlen( $host ) - (strlen( $targetSlot ) + 1) );
         // This will take care of the following notation: ":3306"
         if($host == '')
            $host = 'localhost';
      }

      // perform a number of fatality checks, then return gracefully
      if (!function_exists( 'mysqli_connect' )) {
         $this->_errorNum = 1;
         $this->_errorMsg = 'The MySQL adapter "mysqli" is not available.';
         return;
      }

      // connect to the server
      if (!($this->_resource = @mysqli_connect($host, $user, $password, NULL, $port, $socket))) {
         $this->_errorNum = 2;
         $this->_errorMsg = 'Could not connect to MySQL';
         return;
      }

      // finalize initialization
      parent::__construct($options);

      // select the database
      if ( $select ) {
         $this->select($database);
      }
   }



PS. Using TeraWURFL 2.1.2 we've been forced to use workaround with ini_set:
Code: Select all
      if(strpos($host, ':')!==false)
      {
         list($host, $port) = explode(':', $host);
         if(is_numeric($port))
            ini_set('mysqli.default_port', $port);
         else
            ini_set('mysqli.default_socket', $port);
      }
      if($host == '')
         $host = 'localhost';
      TeraWurflConfig::$DB_HOST   = $host;

but as you add support for nonstandard port to 2.1.3, we hope that support for nonstandard sockets/pipes will be added also.
dryabov
 
Posts: 4
Joined: Thu Sep 09, 2010 7:37 am

Re: MySQL socket/pipe support

Postby kamermans » Mon Sep 13, 2010 9:35 pm

Ok, support has been added in the trunk on GitHub :). I know it's working because I'm using it this way for Tera-WURFL Explorer now! Thanks for the good suggestion!

Commit:
http://github.com/kamermans/Tera-WURFL/ ... ab5c4bec2a

Usage:
http://github.com/kamermans/Tera-WURFL/ ... 9225c3e2bf
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: MySQL socket/pipe support

Postby dryabov » Tue Sep 14, 2010 8:23 am

Thank you very much!

PS. Steve, yesterday I sent you email titled "Question on WURFL_ID_MAX_LENGTH", did you receive it?
dryabov
 
Posts: 4
Joined: Thu Sep 09, 2010 7:37 am

Re: MySQL socket/pipe support

Postby kamermans » Tue Sep 14, 2010 7:41 pm

Ah yes, it went into my spam box - I got it now :)
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX

Re: MySQL socket/pipe support

Postby kamermans » Tue Sep 14, 2010 8:10 pm

FYI, I changed the default max id length to 64 in the MySQL4 connector as well to make this less confusing.

http://github.com/kamermans/Tera-WURFL/ ... dc01732e71
Thanks,

Steve Kamerman
Tera-WURFL Author
COO of ScientiaMobile

IMPORTANT ANNOUNCEMENT! Tera-WURFL and WURFL have joined forces! We have launched ScientiaMobile to provide commercial support for our device detection solutions.

Tera-WURFL.com | Device Explorer
kamermans
Site Admin
 
Posts: 323
Joined: Wed Mar 10, 2010 12:06 pm
Location: Fort Worth, TX


Return to Improvements / Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron