Announcement

#1 2013-03-11 22:02:52

fisharebest
Member
2012-07-10
6

v2.5 upgrade script fails due to lack of support for mysql sockets

A user on my system has reported that the upgrade to piwigo 2.5 gives a database error.  Investigations reveal that this is because the file includes/dblayer/functions_mysqli.inc.php assumes a network based connection to the mysql database.  This is the line:

    $mysqli = new mysqli($host, $user, $password);

Support for sockets can easily be added by changing this to:

if (substr($host, 0, 1)==':')
  {
    $mysqli = new mysqli('localhost', $user, $password, null, null, substr($host, 1));
  }
  else
  {
    $mysqli = new mysqli($host, $user, $password);
  }

It uses the (fairly standard) approach of specifying ":/path/to/socket" as a hostname.

Regards,

Greg

Offline

 

#2 2013-03-11 22:41:29

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: v2.5 upgrade script fails due to lack of support for mysql sockets

I even didn't know this exists

We will add it for Piwigo 2.5.1

[Bugtracker] ticket 2865

Offline

 

#3 2013-03-14 16:16:01

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: v2.5 upgrade script fails due to lack of support for mysql sockets

I can find any documentation on how to use mysql sockets
is the host always "localhost" ?


also I realized that mysqli has a specific field for the port, but doesn't the syntax "myhost:3307" for the host field works too ?


if teh answer is no to both questions, we need to add some string parser to transform $host into host, port and socket

Offline

 

#4 2013-03-19 18:41:54

fisharebest
Member
2012-07-10
6

Re: v2.5 upgrade script fails due to lack of support for mysql sockets

Looking at some other projects, there seem to be two ways to identify sockets.

The first is to prefix the path with a colon.
The second is to look for the leading "/" in the path.

If you cannot decide, I would vote for the second option.

<<I can find any documentation on how to use mysql sockets
is the host always "localhost" ?>>

The host field is ignored.  NULL works, and is probably the cleanest solution.

I'm currently using this in piwigo

  if (substr($host, 0, 1)=='/')
  {
    $mysqli = new mysqli(null, $user, $password, null, null, $host);
  }
  else
  {
    $mysqli = new mysqli($host, $user, $password);
  }


FYI, with the PHP/PDO interface, there is actually a different connection string completely.  Use code like this

    $pdo=new PDO(
        (substr($DBHOST, 0, 1)=='/' ?
        "mysql:unix_socket={$DBHOST};dbname={$DBNAME}" :
        "mysql:host={$DBHOST};dbname={$DBNAME};port={$DBPORT}"
        ),
        ...
    );

If you don't have a suitable machine for testing (i.e. a unix server with MySQL listening on a socket), I can test this for you.

Last edited by fisharebest (2013-03-19 18:43:02)

Offline

 

#5 2013-04-12 23:58:47

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13790

Re: v2.5 upgrade script fails due to lack of support for mysql sockets

Hi fisharebest,

fisharebest wrote:

If you don't have a suitable machine for testing (i.e. a unix server with MySQL listening on a socket), I can test this for you.

Can you please test this version of include/dblayer/functions_mysqli.inc.php ?

http://piwigo.org/dev/export/22181/bran … li.inc.php

(related to [Subversion] r22181)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact