We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3350
    • 8 Posts
    I currently have two sites up and running Evolution 1.0.2 and I am trying to install a Revolution based site on the same webhost. However, when I try to install revolution and test the database connection I get the following errors.
    Connecting to mysql server:  
    Could not connect to the database server. Check the connection properties and try again.
    
    [2011-01-09 21:02:22] (ERROR in xPDO::connect @ /core/xpdo/xpdo.class.php : 331) SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (1) 
    
    [2011-01-09 21:02:22] (ERROR in xPDO::connect @ /xpdo/xpdo.class.php : 331) SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (1) 
    


    I use the same connection properties in Modx Evolution without problem. Also when I install the application on my local system, I don’t experience the same connection problems even though the one difference is that I don’t have to specify the socket for the mySQL sever. Has anyone else had experience problems connection to a MySQL database that specifies a socket path for a Revolution install?
      • 3749
      • 24,544 Posts
      Are you using just localhost for the server name. If not, try that. If you are, I’d suggest asking the host what to specify as the server name. I’ve never seen a case where localhost didn’t work, but I know they exist.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 3350
        • 8 Posts
        I have to specify as my server name: localhost:/tmp/mysql5.sock

        This works in my Evolution installs but not for the Revolution installation. I tried taking the socket path out and only supplied localhost but that doesn’t work. My web service provider does document that what I posted above is the correct way to to connect to my MySQL 5 database.

        Here are some more details
        Web Server: apache linux
        MySQL: 5.0.90
        MySQL Server: Localhost via UNIX socket
          • 3749
          • 24,544 Posts
          Sorry, I’m at a loss. Maybe someone else has an idea.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3350
            • 8 Posts
            I appreciate your feedback and at least attempting to provide an answer. Think I got my answer, now I have to figure out where to go next unless there is an alternative.

            I used the following test code and submitted a ticket to my web provider:
            <?php
            /* Connect to an ODBC database using driver invocation */
            $dsn = 'mysql:dbname=testdb;host=localhost:/tmp/mysql5.sock';
            $user = 'dbuser';
            $password = 'dbpass';
            
            try {
              $dbh = new PDO($dsn, $user, $password);
            } catch (PDOException $e) {
              echo 'Connection failed: ' . $e->getMessage();
            }
            ?>
            
            

            I got the same error as I received when I was allowing ModX to test my database connection. So my web host provider modified the script and was able to make the connection work. However, the line he change would make it seem like I would have to modify the ModX code to allow for me to use Revolution unless there is an alternative out there.

            For line 3 he changed:
            $dsn = 'mysql:unix_socket=/tmp/mysql5.sock; dbname=testdb';
            


            There isn’t a value for host and the unix_socket is supplied instead. This change allow for the code to work. Now I wonder if there is an alternative to this change?
              • 3749
              • 24,544 Posts
              The relevant code is in core/xpdo/xpdo.class.php:

              $this->pdo= new PDO($this->config['dsn'], $this->config['username'], $this->config['password'], $this->config['driverOptions']);


              The first argument is constructed like this in core/model/modx/dbapi.class.php:

              $dbtype . ':host=' . $host . ';dbname=' . str_replace('`', '', $dbase)


              I would say to try this as your sever (if you haven’t already):

              unix_socket=/tmp/mysql5.sock


              I don’t think it will work, MODx will put "host=" in front of it which will probably kill it.

              You would probably have to change the argument constructor line to:

              $dbtype . ':unix_socket=' . $host . ';dbname=' . str_replace('`', '', $dbase)


              And use your original value for server.

              There may be a way around this without hacking the core code, but I doubt it. Someone who knows more about server stuff might have a better idea, but it looks to me like "host=" is hardcoded in all the relevant places.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 22303 MODX Staff
                • 10,725 Posts
                For now you can add the additional setting to the hostname I believe—the whole value for hostname in the setup would be e.g.:
                localhost;unix_socket=/tmp/mysql5.sock