From e01b40c529245e9ead5243a7505d909ca0131c96 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 10 Nov 2013 17:03:25 +0000 Subject: move array_from_query to functions.inc.php git-svn-id: http://piwigo.org/svn/trunk@25427 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/dblayer/functions_mysql.inc.php | 30 ------------------------------ include/dblayer/functions_mysqli.inc.php | 30 ------------------------------ include/functions.inc.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 60 deletions(-) diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php index 3992ed6c2..760587094 100644 --- a/include/dblayer/functions_mysql.inc.php +++ b/include/dblayer/functions_mysql.inc.php @@ -200,36 +200,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 = mysql_fetch_assoc($result)) - { - $array[] = $row; - } - } - else - { - while ($row = mysql_fetch_assoc($result)) - { - $array[] = $row[$fieldname]; - } - } - return $array; -} - define('MASS_UPDATES_SKIP_EMPTY', 1); /** * updates multiple lines in a table diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index 8dc4e46ce..1a05820dc 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -237,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 diff --git a/include/functions.inc.php b/include/functions.inc.php index 18511a6be..5425b797c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1313,6 +1313,37 @@ function hash_from_query($query, $keyname) return $array; } +/** + * creates a numeric array based on a SQL query. + * if _$fieldname_ is empty the returned value will be an array of arrays + * if _$fieldname_ is provided the returned value will be a one dimension array + * + * @param string $query + * @param string $fieldname + * @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; +} + /** * Return the basename of the current script. * The lowercase case filename of the current script without extension -- cgit v1.2.3