aboutsummaryrefslogtreecommitdiffstats
path: root/include/dblayer/functions_mysqli.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/dblayer/functions_mysqli.inc.php')
-rw-r--r--include/dblayer/functions_mysqli.inc.php71
1 files changed, 28 insertions, 43 deletions
diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php
index 2c7f0c6af..41ada251d 100644
--- a/include/dblayer/functions_mysqli.inc.php
+++ b/include/dblayer/functions_mysqli.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -36,8 +36,29 @@ define('DB_RANDOM_FUNCTION', 'RAND');
function pwg_db_connect($host, $user, $password, $database)
{
global $mysqli;
+
+ // $host can be:
+ //
+ // $host = localhost
+ // $host = 1.2.3.4:3405
+ // $host = /path/to/socket
+
+ $port = null;
+ $socket = null;
+
+ if (strpos($host, '/') === 0)
+ {
+ $socket = $host;
+ $host = null;
+ }
+ elseif (strpos($host, ':') !== false)
+ {
+ list($host, $port) = explode(':', $host);
+ }
+
+ $dbname = null;
- $mysqli = new mysqli($host, $user, $password);
+ $mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket);
if (mysqli_connect_error())
{
throw new Exception("Can't connect to server");
@@ -216,36 +237,6 @@ function pwg_db_close()
*
*/
-/**
- * creates an array based on a query, this function is a very common pattern
- * used here
- *
- * @param string $query
- * @param string $fieldname optional
- * @return array
- */
-function array_from_query($query, $fieldname=false)
-{
- $array = array();
-
- $result = pwg_query($query);
- if (false === $fieldname)
- {
- while ($row = pwg_db_fetch_assoc($result))
- {
- $array[] = $row;
- }
- }
- else
- {
- while ($row = pwg_db_fetch_assoc($result))
- {
- $array[] = $row[$fieldname];
- }
- }
- return $array;
-}
-
define('MASS_UPDATES_SKIP_EMPTY', 1);
/**
* updates multiple lines in a table
@@ -344,7 +335,7 @@ SHOW FULL COLUMNS FROM '.$tablename;
{
$column.= " collate '".$row['Collation']."'";
}
- array_push($columns, $column);
+ $columns[] = $column;
}
}
@@ -580,7 +571,7 @@ function do_maintenance_all_tables()
$result = pwg_query($query);
while ($row = pwg_db_fetch_row($result))
{
- array_push($all_tables, $row[0]);
+ $all_tables[] = $row[0];
}
// Repair all tables
@@ -598,7 +589,7 @@ function do_maintenance_all_tables()
{
if ($row['Key'] == 'PRI')
{
- array_push($all_primary_key, $row['Field']);
+ $all_primary_key[] = $row['Field'];
}
}
@@ -614,17 +605,11 @@ function do_maintenance_all_tables()
$mysqli_rc = $mysqli_rc && pwg_query($query);
if ($mysqli_rc)
{
- array_push(
- $page['infos'],
- l10n('All optimizations have been successfully completed.')
- );
+ $page['infos'][] = l10n('All optimizations have been successfully completed.');
}
else
{
- array_push(
- $page['errors'],
- l10n('Optimizations have been completed with some errors.')
- );
+ $page['errors'][] = l10n('Optimizations have been completed with some errors.');
}
}