aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2009-11-20 14:17:04 +0000
committernikrou <nikrou@piwigo.org>2009-11-20 14:17:04 +0000
commit924dd262ec3778277cf1efedee92fa5dd4fb2d32 (patch)
tree05176413aa5b4762dd72477099644c732389f971
parentc020cd0d7cb7710a6ffe04fc8b6d6ccfecb2c466 (diff)
Feature 1244 resolved
Replace all mysql functions in core code by ones independant of database engine Fix small php code synxtax : hash must be accessed with [ ] and not { }. git-svn-id: http://piwigo.org/svn/trunk@4325 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--action.php4
-rw-r--r--admin/cat_list.php2
-rw-r--r--admin/cat_modify.php12
-rw-r--r--admin/cat_perm.php10
-rw-r--r--admin/comments.php2
-rw-r--r--admin/configuration.php2
-rw-r--r--admin/element_set.php2
-rw-r--r--admin/element_set_global.php6
-rw-r--r--admin/element_set_ranks.php4
-rw-r--r--admin/element_set_unit.php4
-rw-r--r--admin/group_list.php12
-rw-r--r--admin/group_perm.php6
-rw-r--r--admin/history.php14
-rw-r--r--admin/include/c13y_internal.class.php6
-rw-r--r--admin/include/functions.php308
-rw-r--r--admin/include/functions_history.inc.php2
-rw-r--r--admin/include/functions_metadata.php4
-rw-r--r--admin/include/functions_notification_by_mail.inc.php4
-rw-r--r--admin/include/functions_permalinks.php8
-rw-r--r--admin/include/functions_upgrade.php6
-rw-r--r--admin/intro.php46
-rw-r--r--admin/notification_by_mail.php8
-rw-r--r--admin/permalinks.php6
-rw-r--r--admin/picture_modify.php8
-rw-r--r--admin/rating.php10
-rw-r--r--admin/site_manager.php6
-rw-r--r--admin/site_update.php58
-rw-r--r--admin/stats.php6
-rw-r--r--admin/tags.php4
-rw-r--r--admin/template/goto/intro.tpl2
-rw-r--r--admin/thumbnail.php2
-rw-r--r--admin/upload.php4
-rw-r--r--admin/user_list.php8
-rw-r--r--admin/user_perm.php10
-rw-r--r--comments.php6
-rw-r--r--feed.php4
-rw-r--r--include/calendar_monthly.class.php8
-rw-r--r--include/category_cats.inc.php14
-rw-r--r--include/category_default.inc.php2
-rw-r--r--include/common.inc.php20
-rw-r--r--include/dblayer/functions_mysql.inc.php463
-rw-r--r--include/functions.inc.php102
-rw-r--r--include/functions_category.inc.php16
-rw-r--r--include/functions_comment.inc.php8
-rw-r--r--include/functions_mail.inc.php10
-rw-r--r--include/functions_notification.inc.php10
-rw-r--r--include/functions_plugins.inc.php2
-rw-r--r--include/functions_rate.inc.php2
-rw-r--r--include/functions_search.inc.php8
-rw-r--r--include/functions_session.inc.php2
-rw-r--r--include/functions_tag.inc.php8
-rw-r--r--include/functions_user.inc.php44
-rw-r--r--include/picture_comment.inc.php4
-rw-r--r--include/picture_rate.inc.php6
-rw-r--r--include/ws_functions.inc.php36
-rw-r--r--install.php2
-rw-r--r--install/db/1-database.php2
-rw-r--r--install/db/12-database.php2
-rw-r--r--install/db/18-database.php2
-rw-r--r--install/db/19-database.php2
-rw-r--r--install/db/20-database.php2
-rw-r--r--install/db/65-database.php10
-rw-r--r--install/db/8-database.php2
-rw-r--r--install/db/9-database.php2
-rw-r--r--install/upgrade_1.3.0.php2
-rw-r--r--install/upgrade_1.3.1.php8
-rw-r--r--install/upgrade_1.4.0.php6
-rw-r--r--install/upgrade_1.5.0.php6
-rw-r--r--install/upgrade_1.7.0.php2
-rw-r--r--password.php6
-rw-r--r--picture.php10
-rw-r--r--profile.php4
-rw-r--r--qsearch.php2
-rw-r--r--search.php2
-rw-r--r--search_rules.php2
-rw-r--r--upgrade.php17
-rw-r--r--upgrade_feed.php12
-rw-r--r--upload.php4
78 files changed, 789 insertions, 691 deletions
diff --git a/action.php b/action.php
index 99f370b41..746ae1733 100644
--- a/action.php
+++ b/action.php
@@ -71,7 +71,7 @@ SELECT * FROM '. IMAGES_TABLE.'
;';
$result = pwg_query($query);
-$element_info = mysql_fetch_assoc($result);
+$element_info = pwg_db_fetch_assoc($result);
if ( empty($element_info) )
{
do_error(404, 'Requested id not found');
@@ -93,7 +93,7 @@ SELECT id
).'
LIMIT 1
;';
-if ( mysql_num_rows(pwg_query($query))<1 )
+if ( pwg_db_num_rows(pwg_query($query))<1 )
{
do_error(401, 'Access denied');
}
diff --git a/admin/cat_list.php b/admin/cat_list.php
index 3a9a1fc46..5b7733df2 100644
--- a/admin/cat_list.php
+++ b/admin/cat_list.php
@@ -119,7 +119,7 @@ SELECT id, name
(!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$categories[ $row['id'] ] = strtolower($row['name']);
}
diff --git a/admin/cat_modify.php b/admin/cat_modify.php
index 1ca146aa6..06a001253 100644
--- a/admin/cat_modify.php
+++ b/admin/cat_modify.php
@@ -193,7 +193,7 @@ SELECT *
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$_GET['cat_id'].'
;';
-$category = mysql_fetch_assoc( pwg_query( $query ) );
+$category = pwg_db_fetch_assoc( pwg_query( $query ) );
// nullable fields
foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
{
@@ -210,7 +210,7 @@ $query = 'SELECT DISTINCT category_id
WHERE category_id = '.$_GET['cat_id'].'
LIMIT 1';
$result = pwg_query($query);
-$category['has_images'] = mysql_num_rows($result)>0 ? true : false;
+$category['has_images'] = pwg_db_num_rows($result)>0 ? true : false;
// Navigation path
$navigation = get_cat_display_name_cache(
@@ -373,7 +373,7 @@ SELECT id,tn_ext,path
FROM '.IMAGES_TABLE.'
WHERE id = '.$category['representative_picture_id'].'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
$src = get_thumbnail_url($row);
$url = get_root_url().'admin.php?page=picture_modify';
$url.= '&amp;image_id='.$category['representative_picture_id'];
@@ -461,9 +461,9 @@ SELECT id, file, path, tn_ext
;';
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
- $element = mysql_fetch_assoc($result);
+ $element = pwg_db_fetch_assoc($result);
$img_url = '<a href="'.
make_picture_url(array(
@@ -511,7 +511,7 @@ SELECT
FROM '.GROUPS_TABLE.'
WHERE id = '.$_POST['group'].'
;';
- list($group_name) = mysql_fetch_row(pwg_query($query));
+ list($group_name) = pwg_db_fetch_row(pwg_query($query));
array_push(
$page['infos'],
diff --git a/admin/cat_perm.php b/admin/cat_perm.php
index 0107d6cc7..91711ddf1 100644
--- a/admin/cat_perm.php
+++ b/admin/cat_perm.php
@@ -45,7 +45,7 @@ SELECT status
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$_GET['cat'].'
;';
- list($status) = mysql_fetch_row(pwg_query($query));
+ list($status) = pwg_db_fetch_row(pwg_query($query));
if ('private' == $status)
{
@@ -62,7 +62,7 @@ SELECT id
LIMIT 0,1
;';
- list($page['cat']) = mysql_fetch_row(pwg_query($query));
+ list($page['cat']) = pwg_db_fetch_row(pwg_query($query));
}
// +-----------------------------------------------------------------------+
@@ -110,7 +110,7 @@ SELECT group_id, cat_id
AND group_id IN ('.implode(',', $_POST['grant_groups']).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($granteds[$row['cat_id']], $row['group_id']);
}
@@ -169,7 +169,7 @@ SELECT user_id, cat_id
AND user_id IN ('.implode(',', $_POST['grant_users']).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($granteds[$row['cat_id']], $row['user_id']);
}
@@ -274,7 +274,7 @@ SELECT user_id, group_id
WHERE group_id IN ('.implode(',', $group_granted_ids).')
';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if (!isset($granted_groups[$row['group_id']]))
{
diff --git a/admin/comments.php b/admin/comments.php
index d4fc89a66..84006088e 100644
--- a/admin/comments.php
+++ b/admin/comments.php
@@ -145,7 +145,7 @@ $conf['user_fields']['username'].' AS username, c.content, i.path, i.tn_ext
ORDER BY c.date DESC
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$thumb = get_thumbnail_url(
array(
diff --git a/admin/configuration.php b/admin/configuration.php
index d193f9f8d..9b4a7f0c2 100644
--- a/admin/configuration.php
+++ b/admin/configuration.php
@@ -138,7 +138,7 @@ if (isset($_POST['submit']) and !is_adviser())
{
//echo '<pre>'; print_r($_POST); echo '</pre>';
$result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if (isset($_POST[$row['param']]))
{
diff --git a/admin/element_set.php b/admin/element_set.php
index 9cbdb7eec..1c84854d5 100644
--- a/admin/element_set.php
+++ b/admin/element_set.php
@@ -192,7 +192,7 @@ elseif ('recent'== $_GET['cat'])
$page['title'] = l10n('recent_pics_cat');
$query = 'SELECT MAX(date_available) AS date
FROM '.IMAGES_TABLE;
- if ($row = mysql_fetch_assoc( pwg_query($query) ) )
+ if ($row = pwg_db_fetch_assoc( pwg_query($query) ) )
{
$query = 'SELECT id
FROM '.IMAGES_TABLE.'
diff --git a/admin/element_set_global.php b/admin/element_set_global.php
index 20a4c658b..3676309e5 100644
--- a/admin/element_set_global.php
+++ b/admin/element_set_global.php
@@ -245,7 +245,7 @@ SELECT id
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$data = array();
$data['id'] = $row['id'];
@@ -337,7 +337,7 @@ SELECT
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
AND storage_category_id IS NULL
;';
- list($counter) = mysql_fetch_row(pwg_query($query));
+ list($counter) = pwg_db_fetch_row(pwg_query($query));
if ($counter > 0)
{
@@ -481,7 +481,7 @@ SELECT id,path,tn_ext,file,filesize,level
// template thumbnail initialization
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$src = get_thumbnail_url($row);
diff --git a/admin/element_set_ranks.php b/admin/element_set_ranks.php
index 1bc0ab57f..57a1f6e0b 100644
--- a/admin/element_set_ranks.php
+++ b/admin/element_set_ranks.php
@@ -115,7 +115,7 @@ SELECT uppercats
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$page['category_id'].'
;';
-$category = mysql_fetch_assoc(pwg_query($query));
+$category = pwg_db_fetch_assoc(pwg_query($query));
// Navigation path
$navigation = get_cat_display_name_cache(
@@ -150,7 +150,7 @@ $result = pwg_query($query);
// template thumbnail initialization
$current_rank = 1;
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$src = get_thumbnail_url($row);
diff --git a/admin/element_set_unit.php b/admin/element_set_unit.php
index 7bc0e54b0..65206aba4 100644
--- a/admin/element_set_unit.php
+++ b/admin/element_set_unit.php
@@ -56,7 +56,7 @@ SELECT id, date_creation
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$data = array();
@@ -200,7 +200,7 @@ SELECT id,path,tn_ext,name,date_creation,comment,author,file
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
// echo '<pre>'; print_r($row); echo '</pre>';
array_push($element_ids, $row['id']);
diff --git a/admin/group_list.php b/admin/group_list.php
index 97ee5a8f3..eff20031d 100644
--- a/admin/group_list.php
+++ b/admin/group_list.php
@@ -60,7 +60,7 @@ SELECT name
FROM '.GROUPS_TABLE.'
WHERE id = '.$_GET['delete'].'
;';
- list($groupname) = mysql_fetch_row(pwg_query($query));
+ list($groupname) = pwg_db_fetch_row(pwg_query($query));
// destruction of the group
$query = '
@@ -94,7 +94,7 @@ SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
WHERE name = \''.$_POST['groupname'].'\'
;';
- list($count) = mysql_fetch_row(pwg_query($query));
+ list($count) = pwg_db_fetch_row(pwg_query($query));
if ($count != 0)
{
array_push($page['errors'], l10n('group_add_error2'));
@@ -107,7 +107,7 @@ SELECT COUNT(*)
INSERT INTO '.GROUPS_TABLE.'
(name)
VALUES
- (\''.mysql_real_escape_string($_POST['groupname']).'\')
+ (\''.pwg_db_real_escape_string($_POST['groupname']).'\')
;';
pwg_query($query);
@@ -129,7 +129,7 @@ SELECT name, is_default
FROM '.GROUPS_TABLE.'
WHERE id = '.$_GET['toggle_is_default'].'
;';
- list($groupname, $is_default) = mysql_fetch_row(pwg_query($query));
+ list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
// update of the group
$query = '
@@ -175,14 +175,14 @@ $del_url = $admin_url.'group_list&amp;delete=';
$members_url = $admin_url.'user_list&amp;group=';
$toggle_is_default_url = $admin_url.'group_list&amp;toggle_is_default=';
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$query = '
SELECT COUNT(*)
FROM '.USER_GROUP_TABLE.'
WHERE group_id = '.$row['id'].'
;';
- list($counter) = mysql_fetch_row(pwg_query($query));
+ list($counter) = pwg_db_fetch_row(pwg_query($query));
$template->append(
'groups',
diff --git a/admin/group_perm.php b/admin/group_perm.php
index 89a8b43ae..f664854e7 100644
--- a/admin/group_perm.php
+++ b/admin/group_perm.php
@@ -79,7 +79,7 @@ SELECT id
AND status = \'private\'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($private_uppercats, $row['id']);
}
@@ -96,7 +96,7 @@ SELECT cat_id
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($authorized_ids, $row['cat_id']);
}
@@ -157,7 +157,7 @@ display_select_cat_wrapper($query_true,array(),'category_option_true');
$result = pwg_query($query_true);
$authorized_ids = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($authorized_ids, $row['id']);
}
diff --git a/admin/history.php b/admin/history.php
index afc1712e1..86014fc7b 100644
--- a/admin/history.php
+++ b/admin/history.php
@@ -110,7 +110,7 @@ if (isset($_POST['submit']))
$search['fields']['filename'] = str_replace(
'*',
'%',
- mysql_real_escape_string($_POST['filename'])
+ pwg_db_real_escape_string($_POST['filename'])
);
}
@@ -136,7 +136,7 @@ INSERT INTO '.SEARCH_TABLE.'
;';
pwg_query($query);
- $search_id = mysql_insert_id();
+ $search_id = pwg_db_insert_id();
redirect(
PHPWG_ROOT_PATH.'admin.php?page=history&search_id='.$search_id
@@ -177,7 +177,7 @@ SELECT rules
FROM '.SEARCH_TABLE.'
WHERE id = '.$page['search_id'].'
;';
- list($serialized_rules) = mysql_fetch_row(pwg_query($query));
+ list($serialized_rules) = pwg_db_fetch_row(pwg_query($query));
$page['search'] = unserialize($serialized_rules);
@@ -198,7 +198,7 @@ INSERT INTO '.SEARCH_TABLE.'
;';
pwg_query($query);
- $search_id = mysql_insert_id();
+ $search_id = pwg_db_insert_id();
redirect(
PHPWG_ROOT_PATH.'admin.php?page=history&search_id='.$search_id
@@ -257,7 +257,7 @@ SELECT '.$conf['user_fields']['id'].' AS id
$result = pwg_query($query);
$username_of = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$username_of[$row['id']] = stripslashes($row['username']);
}
@@ -305,7 +305,7 @@ SELECT
$tn_ext_of_image = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$label_of_image[ $row['id'] ] = $row['label'];
@@ -341,7 +341,7 @@ SELECT
$name_of_tag = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$name_of_tag[ $row['id'] ] = $row['name'];
}
diff --git a/admin/include/c13y_internal.class.php b/admin/include/c13y_internal.class.php
index 6402c6516..1fe83c0df 100644
--- a/admin/include/c13y_internal.class.php
+++ b/admin/include/c13y_internal.class.php
@@ -42,8 +42,8 @@ class c13y_internal
$check_list[] = array('type' => 'PHP', 'current' => phpversion(), 'required' => REQUIRED_PHP_VERSION);
- list($mysql_version) = mysql_fetch_row(pwg_query('SELECT VERSION();'));
- $check_list[] = array('type' => 'MySQL', 'current' => $mysql_version, 'required' => REQUIRED_MYSQL_VERSION);
+ $db_version = pwg_get_db_version();
+ $check_list[] = array('type' => 'MySQL', 'current' => $db_version, 'required' => REQUIRED_MYSQL_VERSION);
foreach ($check_list as $elem)
{
@@ -126,7 +126,7 @@ class c13y_internal
$status = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$status[$row['id']] = $row['status'];
}
diff --git a/admin/include/functions.php b/admin/include/functions.php
index d1e82f15f..2b6bffa98 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -36,7 +36,7 @@ SELECT id
;';
$result = pwg_query($query);
$category_ids = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($category_ids, $row['id']);
}
@@ -77,7 +77,7 @@ SELECT id
;';
$result = pwg_query($query);
$element_ids = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($element_ids, $row['id']);
}
@@ -159,7 +159,7 @@ SELECT
AND storage_category_id IS NULL
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$file_path = $row['path'];
$thumbnail_path = get_thumbnail_path($row);
@@ -409,210 +409,6 @@ function get_fs_directories($path, $recursive = true)
}
/**
- * inserts multiple lines in a table
- *
- * @param string table_name
- * @param array dbfields
- * @param array inserts
- * @return void
- */
-function mass_inserts($table_name, $dbfields, $datas)
-{
- if (count($datas) != 0)
- {
- $first = true;
-
- $query = 'SHOW VARIABLES LIKE \'max_allowed_packet\'';
- list(, $packet_size) = mysql_fetch_row(pwg_query($query));
- $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/
- $query = '';
-
- foreach ($datas as $insert)
- {
- if (strlen($query) >= $packet_size)
- {
- pwg_query($query);
- $first = true;
- }
-
- if ($first)
- {
- $query = '
-INSERT INTO '.$table_name.'
- ('.implode(',', $dbfields).')
- VALUES';
- $first = false;
- }
- else
- {
- $query .= '
- , ';
- }
-
- $query .= '(';
- foreach ($dbfields as $field_id => $dbfield)
- {
- if ($field_id > 0)
- {
- $query .= ',';
- }
-
- if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
- {
- $query .= 'NULL';
- }
- else
- {
- $query .= "'".$insert[$dbfield]."'";
- }
- }
- $query .= ')';
- }
- pwg_query($query);
- }
-}
-
-define('MASS_UPDATES_SKIP_EMPTY', 1);
-/**
- * updates multiple lines in a table
- *
- * @param string table_name
- * @param array dbfields
- * @param array datas
- * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
- * @return void
- */
-function mass_updates($tablename, $dbfields, $datas, $flags=0)
-{
- if (count($datas) == 0)
- return;
- // depending on the MySQL version, we use the multi table update or N update queries
- if (count($datas) < 10 or version_compare(mysql_get_server_info(), '4.0.4') < 0)
- { // MySQL is prior to version 4.0.4, multi table update feature is not available
- foreach ($datas as $data)
- {
- $query = '
-UPDATE '.$tablename.'
- SET ';
- $is_first = true;
- foreach ($dbfields['update'] as $key)
- {
- $separator = $is_first ? '' : ",\n ";
-
- if (isset($data[$key]) and $data[$key] != '')
- {
- $query.= $separator.$key.' = \''.$data[$key].'\'';
- }
- else
- {
- if ($flags & MASS_UPDATES_SKIP_EMPTY )
- continue; // next field
- $query.= "$separator$key = NULL";
- }
- $is_first = false;
- }
- if (!$is_first)
- {// only if one field at least updated
- $query.= '
- WHERE ';
- $is_first = true;
- foreach ($dbfields['primary'] as $key)
- {
- if (!$is_first)
- {
- $query.= ' AND ';
- }
- if ( isset($data[$key]) )
- {
- $query.= $key.' = \''.$data[$key].'\'';
- }
- else
- {
- $query.= $key.' IS NULL';
- }
- $is_first = false;
- }
- pwg_query($query);
- }
- } // foreach update
- } // if mysql_ver or count<X
- else
- {
- // creation of the temporary table
- $query = '
-SHOW FULL COLUMNS FROM '.$tablename;
- $result = pwg_query($query);
- $columns = array();
- $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
- while ($row = mysql_fetch_assoc($result))
- {
- if (in_array($row['Field'], $all_fields))
- {
- $column = $row['Field'];
- $column.= ' '.$row['Type'];
-
- $nullable = true;
- if (!isset($row['Null']) or $row['Null'] == '' or $row['Null']=='NO')
- {
- $column.= ' NOT NULL';
- $nullable = false;
- }
- if (isset($row['Default']))
- {
- $column.= " default '".$row['Default']."'";
- }
- elseif ($nullable)
- {
- $column.= " default NULL";
- }
- if (isset($row['Collation']) and $row['Collation'] != 'NULL')
- {
- $column.= " collate '".$row['Collation']."'";
- }
- array_push($columns, $column);
- }
- }
-
- $temporary_tablename = $tablename.'_'.micro_seconds();
-
- $query = '
-CREATE TABLE '.$temporary_tablename.'
-(
- '.implode(",\n ", $columns).',
- UNIQUE KEY the_key ('.implode(',', $dbfields['primary']).')
-)';
-
- pwg_query($query);
- mass_inserts($temporary_tablename, $all_fields, $datas);
- if ( $flags & MASS_UPDATES_SKIP_EMPTY )
- $func_set = create_function('$s', 'return "t1.$s = IFNULL(t2.$s, t1.$s)";');
- else
- $func_set = create_function('$s', 'return "t1.$s = t2.$s";');
-
- // update of images table by joining with temporary table
- $query = '
-UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
- SET '.
- implode(
- "\n , ",
- array_map($func_set,$dbfields['update'])
- ).'
- WHERE '.
- implode(
- "\n AND ",
- array_map(
- create_function('$s', 'return "t1.$s = t2.$s";'),
- $dbfields['primary']
- )
- );
- pwg_query($query);
- $query = '
-DROP TABLE '.$temporary_tablename;
- pwg_query($query);
- }
-}
-
-/**
* order categories (update categories.rank and global_rank database fields)
* so that rank field are consecutive integers starting at 1 for each child
* @return void
@@ -630,7 +426,7 @@ SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, r
$current_uppercat = '';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if ($row['id_uppercat'] != $current_uppercat)
{
@@ -776,7 +572,7 @@ SELECT uppercats
WHERE id IN ('.implode(',', $cat_ids).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$uppercats = array_merge($uppercats,
explode(',', $row['uppercats']));
@@ -803,7 +599,7 @@ SELECT image_id
ORDER BY RAND()
LIMIT 0,1
;';
- list($representative) = mysql_fetch_row(pwg_query($query));
+ list($representative) = pwg_db_fetch_row(pwg_query($query));
array_push(
$datas,
@@ -863,7 +659,7 @@ SELECT id, uppercats, site_id
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($categories, $row);
}
@@ -1139,7 +935,7 @@ SELECT element_id,
$datas = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$datas,
@@ -1206,7 +1002,7 @@ SELECT id, id_uppercat, status, uppercats
WHERE id IN ('.implode(',', $category_ids).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$categories[$row['id']] =
array(
@@ -1225,7 +1021,7 @@ SELECT uppercats
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$new_parent.'
;';
- list($new_parent_uppercats) = mysql_fetch_row(pwg_query($query));
+ list($new_parent_uppercats) = pwg_db_fetch_row(pwg_query($query));
foreach ($categories as $category)
{
@@ -1270,7 +1066,7 @@ SELECT status
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$new_parent.'
;';
- list($parent_status) = mysql_fetch_row(pwg_query($query));
+ list($parent_status) = pwg_db_fetch_row(pwg_query($query));
}
if ('private' == $parent_status)
@@ -1355,7 +1151,7 @@ SELECT MAX(rank)
FROM '.CATEGORIES_TABLE.'
WHERE id_uppercat '.(is_numeric($parent_id) ? '= '.$parent_id : 'IS NULL').'
;';
- list($current_rank) = mysql_fetch_row(pwg_query($query));
+ list($current_rank) = pwg_db_fetch_row(pwg_query($query));
$insert = array(
'name' => $category_name,
@@ -1371,7 +1167,7 @@ SELECT id, uppercats, global_rank, visible, status
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$parent_id.'
;';
- $parent = mysql_fetch_assoc(pwg_query($query));
+ $parent = pwg_db_fetch_assoc(pwg_query($query));
$insert['id_uppercat'] = $parent['id'];
$insert['global_rank'] = $parent['global_rank'].'.'.$insert['rank'];
@@ -1417,7 +1213,7 @@ SELECT id, uppercats, global_rank, visible, status
array($insert)
);
- $inserted_id = mysql_insert_id();
+ $inserted_id = pwg_db_insert_id();
$query = '
UPDATE
@@ -1550,7 +1346,7 @@ SELECT id
)
);
- $page['tag_id_from_tag_name_cache'][$tag_name] = mysql_insert_id();
+ $page['tag_id_from_tag_name_cache'][$tag_name] = pwg_db_insert_id();
}
else
{
@@ -1596,70 +1392,6 @@ DELETE
}
/**
- * Do maintenance on all PWG tables
- *
- * @return none
- */
-function do_maintenance_all_tables()
-{
- global $prefixeTable, $page;
-
- $all_tables = array();
-
- // List all tables
- $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\'';
- $result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
- {
- array_push($all_tables, $row[0]);
- }
-
- // Repair all tables
- $query = 'REPAIR TABLE '.implode(', ', $all_tables);
- $mysql_rc = pwg_query($query);
-
- // Re-Order all tables
- foreach ($all_tables as $table_name)
- {
- $all_primary_key = array();
-
- $query = 'DESC '.$table_name.';';
- $result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
- {
- if ($row['Key'] == 'PRI')
- {
- array_push($all_primary_key, $row['Field']);
- }
- }
-
- if (count($all_primary_key) != 0)
- {
- $query = 'ALTER TABLE '.$table_name.' ORDER BY '.implode(', ', $all_primary_key).';';
- $mysql_rc = $mysql_rc && pwg_query($query);
- }
- }
-
- // Optimize all tables
- $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables);
- $mysql_rc = $mysql_rc && pwg_query($query);
- if ($mysql_rc)
- {
- array_push(
- $page['infos'],
- l10n('Optimizations completed')
- );
- }
- else
- {
- array_push(
- $page['errors'],
- l10n('Optimizations errors')
- );
- }
-}
-
-/**
* Associate a list of images to a list of categories.
*
* The function will not duplicate links
@@ -1889,7 +1621,7 @@ SELECT id
)
);
- $inserted_id = mysql_insert_id();
+ $inserted_id = pwg_db_insert_id();
return array(
'info' => sprintf(
@@ -2075,9 +1807,9 @@ SELECT name
WHERE id = '.intval($group_id).'
;';
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
- list($groupname) = mysql_fetch_row($result);
+ list($groupname) = pwg_db_fetch_row($result);
}
else
{
@@ -2103,9 +1835,9 @@ SELECT '.$conf['user_fields']['username'].'
WHERE '.$conf['user_fields']['id'].' = '.intval($user_id).'
;';
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
- list($username) = mysql_fetch_row($result);
+ list($username) = pwg_db_fetch_row($result);
}
else
{
diff --git a/admin/include/functions_history.inc.php b/admin/include/functions_history.inc.php
index bad4a0de5..824caed42 100644
--- a/admin/include/functions_history.inc.php
+++ b/admin/include/functions_history.inc.php
@@ -165,7 +165,7 @@ SELECT
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($data, $row);
}
diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php
index 5bf36439d..f1e9f2549 100644
--- a/admin/include/functions_metadata.php
+++ b/admin/include/functions_metadata.php
@@ -259,7 +259,7 @@ SELECT id
$query.= '
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($cat_ids, $row['id']);
}
@@ -284,7 +284,7 @@ SELECT id, path
$query.= '
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$files[$row['id']] = $row['path'];
}
diff --git a/admin/include/functions_notification_by_mail.inc.php b/admin/include/functions_notification_by_mail.inc.php
index 6a674c5e0..e50321de4 100644
--- a/admin/include/functions_notification_by_mail.inc.php
+++ b/admin/include/functions_notification_by_mail.inc.php
@@ -59,7 +59,7 @@ from
where
check_key = \''.$key.'\';';
- list($count) = mysql_fetch_row(pwg_query($query));
+ list($count) = pwg_db_fetch_row(pwg_query($query));
if ($count == 0)
{
return $key;
@@ -167,7 +167,7 @@ order by';
$result = pwg_query($query);
if (!empty($result))
{
- while ($nbm_user = mysql_fetch_assoc($result))
+ while ($nbm_user = pwg_db_fetch_assoc($result))
{
array_push($data_users, $nbm_user);
}
diff --git a/admin/include/functions_permalinks.php b/admin/include/functions_permalinks.php
index 85820dba2..f619e3b08 100644
--- a/admin/include/functions_permalinks.php
+++ b/admin/include/functions_permalinks.php
@@ -51,8 +51,8 @@ SELECT c.id
LIMIT 1';
$result = pwg_query($query);
$cat_id = null;
- if ( mysql_num_rows($result) )
- list( $cat_id ) = mysql_fetch_row($result);
+ if ( pwg_db_num_rows($result) )
+ list( $cat_id ) = pwg_db_fetch_row($result);
return $cat_id;
}
@@ -72,9 +72,9 @@ SELECT permalink
WHERE id="'.$cat_id.'"
;';
$result = pwg_query($query);
- if ( mysql_num_rows($result) )
+ if ( pwg_db_num_rows($result) )
{
- list($permalink) = mysql_fetch_row($result);
+ list($permalink) = pwg_db_fetch_row($result);
}
if ( !isset($permalink) )
{// no permalink; nothing to do
diff --git a/admin/include/functions_upgrade.php b/admin/include/functions_upgrade.php
index 1d0fbd969..6c653fe98 100644
--- a/admin/include/functions_upgrade.php
+++ b/admin/include/functions_upgrade.php
@@ -112,7 +112,7 @@ AND id NOT IN ("' . implode('","', $standard_plugins) . '")
$result = pwg_query($query);
$plugins = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($plugins, $row['id']);
}
@@ -138,7 +138,7 @@ function check_upgrade_access_rights($current_release, $username, $password)
if(!@get_magic_quotes_gpc())
{
- $username = mysql_real_escape_string($username);
+ $username = pwg_db_real_escape_string($username);
}
if (version_compare($current_release, '2.0', '<'))
@@ -165,7 +165,7 @@ ON u.'.$conf['user_fields']['id'].'=ui.user_id
WHERE '.$conf['user_fields']['username'].'="'.$username.'"
;';
}
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
if (!isset($conf['pass_convert']))
{
diff --git a/admin/intro.php b/admin/intro.php
index d2549b5db..c081e8918 100644
--- a/admin/intro.php
+++ b/admin/intro.php
@@ -53,24 +53,24 @@ if (isset($_GET['action']) and 'check_upgrade' == $_GET['action'])
// if the current version is a BSF (development branch) build, we check
// the first line, for stable versions, we check the second line
- if (preg_match('/^BSF/', $versions{'current'}))
+ if (preg_match('/^BSF/', $versions['current']))
{
- $versions{'latest'} = trim($lines[0]);
+ $versions['latest'] = trim($lines[0]);
// because integer are limited to 4,294,967,296 we need to split BSF
// versions in date.time
foreach ($versions as $key => $value)
{
- $versions{$key} =
+ $versions[$key] =
preg_replace('/BSF_(\d{8})(\d{4})/', '$1.$2', $value);
}
}
else
{
- $versions{'latest'} = trim($lines[1]);
+ $versions['latest'] = trim($lines[1]);
}
- if ('' == $versions{'latest'})
+ if ('' == $versions['latest'])
{
array_push(
$page['errors'],
@@ -79,14 +79,14 @@ if (isset($_GET['action']) and 'check_upgrade' == $_GET['action'])
}
// concatenation needed to avoid automatic transformation by release
// script generator
- else if ('%'.'PWGVERSION'.'%' == $versions{'current'})
+ else if ('%'.'PWGVERSION'.'%' == $versions['current'])
{
array_push(
$page['infos'],
l10n('You are running on development sources, no check possible.')
);
}
- else if (version_compare($versions{'current'}, $versions{'latest'}) < 0)
+ else if (version_compare($versions['current'], $versions['latest']) < 0)
{
array_push(
$page['infos'],
@@ -125,69 +125,70 @@ if ($conf['show_newsletter_subscription']) {
}
$php_current_timestamp = date("Y-m-d H:i:s");
-list($mysql_version, $db_current_timestamp) = mysql_fetch_row(pwg_query('SELECT VERSION(), CURRENT_TIMESTAMP;'));
+$db_version = pwg_get_db_version();
+list($db_current_timestamp) = pwg_db_fetch_row(pwg_query('SELECT CURRENT_TIMESTAMP;'));
$query = '
SELECT COUNT(*)
FROM '.IMAGES_TABLE.'
;';
-list($nb_elements) = mysql_fetch_row(pwg_query($query));
+list($nb_elements) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.CATEGORIES_TABLE.'
;';
-list($nb_categories) = mysql_fetch_row(pwg_query($query));
+list($nb_categories) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.CATEGORIES_TABLE.'
WHERE dir IS NULL
;';
-list($nb_virtual) = mysql_fetch_row(pwg_query($query));
+list($nb_virtual) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.CATEGORIES_TABLE.'
WHERE dir IS NOT NULL
;';
-list($nb_physical) = mysql_fetch_row(pwg_query($query));
+list($nb_physical) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.IMAGE_CATEGORY_TABLE.'
;';
-list($nb_image_category) = mysql_fetch_row(pwg_query($query));
+list($nb_image_category) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.TAGS_TABLE.'
;';
-list($nb_tags) = mysql_fetch_row(pwg_query($query));
+list($nb_tags) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.IMAGE_TAG_TABLE.'
;';
-list($nb_image_tag) = mysql_fetch_row(pwg_query($query));
+list($nb_image_tag) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.USERS_TABLE.'
;';
-list($nb_users) = mysql_fetch_row(pwg_query($query));
+list($nb_users) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.GROUPS_TABLE.'
;';
-list($nb_groups) = mysql_fetch_row(pwg_query($query));
+list($nb_groups) = pwg_db_fetch_row(pwg_query($query));
$query = '
SELECT COUNT(*)
FROM '.COMMENTS_TABLE.'
;';
-list($nb_comments) = mysql_fetch_row(pwg_query($query));
+list($nb_comments) = pwg_db_fetch_row(pwg_query($query));
$template->assign(
array(
@@ -195,7 +196,8 @@ $template->assign(
'PWG_VERSION' => PHPWG_VERSION,
'OS' => PHP_OS,
'PHP_VERSION' => phpversion(),
- 'MYSQL_VERSION' => $mysql_version,
+ 'DB_ENGINE' => 'MySQL',
+ 'DB_VERSION' => $db_version,
'DB_ELEMENTS' => l10n_dec('%d element', '%d elements', $nb_elements),
'DB_CATEGORIES' =>
l10n_dec('cat_inclu_part1_S', 'cat_inclu_part1_P',
@@ -223,7 +225,7 @@ if ($nb_elements > 0)
SELECT MIN(date_available)
FROM '.IMAGES_TABLE.'
;';
- list($first_date) = mysql_fetch_row(pwg_query($query));
+ list($first_date) = pwg_db_fetch_row(pwg_query($query));
$template->assign(
'first_added',
@@ -243,7 +245,7 @@ SELECT COUNT(*)
FROM '.WAITING_TABLE.'
WHERE validated=\'false\'
;';
-list($nb_waiting) = mysql_fetch_row(pwg_query($query));
+list($nb_waiting) = pwg_db_fetch_row(pwg_query($query));
if ($nb_waiting > 0)
{
@@ -262,7 +264,7 @@ SELECT COUNT(*)
FROM '.COMMENTS_TABLE.'
WHERE validated=\'false\'
;';
-list($nb_comments) = mysql_fetch_row(pwg_query($query));
+list($nb_comments) = pwg_db_fetch_row(pwg_query($query));
if ($nb_comments > 0)
{
diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php
index 95aea99ae..a165d54ea 100644
--- a/admin/notification_by_mail.php
+++ b/admin/notification_by_mail.php
@@ -145,12 +145,12 @@ order by
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
$inserts = array();
$check_key_list = array();
- while ($nbm_user = mysql_fetch_assoc($result))
+ while ($nbm_user = pwg_db_fetch_assoc($result))
{
// Calculate key
$nbm_user['check_key'] = find_available_check_key();
@@ -238,7 +238,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
if (in_array($action, array('list_to_send', 'send')))
{
- list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+ list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
$is_action_send = ($action == 'send');
@@ -512,7 +512,7 @@ switch ($page['mode'])
$updated_param_count = 0;
// Update param
$result = pwg_query('select param, value from '.CONFIG_TABLE.' where param like \'nbm\\_%\'');
- while ($nbm_user = mysql_fetch_assoc($result))
+ while ($nbm_user = pwg_db_fetch_assoc($result))
{
if (isset($_POST[$nbm_user['param']]))
{
diff --git a/admin/permalinks.php b/admin/permalinks.php
index bd56e69d8..b937a8016 100644
--- a/admin/permalinks.php
+++ b/admin/permalinks.php
@@ -99,7 +99,7 @@ DELETE FROM '.OLD_PERMALINKS_TABLE.'
WHERE permalink="'.$_GET['delete_permanent'].'"
LIMIT 1';
pwg_query($query);
- if (mysql_affected_rows()==0)
+ if (pwg_db_affected_rows()==0)
array_push($page['errors'], 'Cannot delete the old permalink !');
}
@@ -134,7 +134,7 @@ if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' )
}
$categories=array();
$result=pwg_query($query);
-while ( $row=mysql_fetch_assoc($result) )
+while ( $row = pwg_db_fetch_assoc($result) )
{
$row['name'] = get_cat_display_name_cache( $row['uppercats'] );
$categories[] = $row;
@@ -162,7 +162,7 @@ if ( count($sort_by) )
}
$result = pwg_query($query);
$deleted_permalinks=array();
-while ( $row=mysql_fetch_assoc($result) )
+while ( $row = pwg_db_fetch_assoc($result) )
{
$row['name'] = get_cat_display_name_cache($row['cat_id']);
$row['U_DELETE'] =
diff --git a/admin/picture_modify.php b/admin/picture_modify.php
index 30b9db972..912a94c1c 100644
--- a/admin/picture_modify.php
+++ b/admin/picture_modify.php
@@ -44,7 +44,7 @@ SELECT path
FROM '.IMAGES_TABLE.'
WHERE id = '.$_GET['image_id'].'
;';
- list($path) = mysql_fetch_row(pwg_query($query));
+ list($path) = pwg_db_fetch_row(pwg_query($query));
update_metadata(array($_GET['image_id'] => $path));
array_push($page['infos'], l10n('Metadata synchronized from file'));
@@ -175,7 +175,7 @@ SELECT *
FROM '.IMAGES_TABLE.'
WHERE id = '.$_GET['image_id'].'
;';
-$row = mysql_fetch_assoc(pwg_query($query));
+$row = pwg_db_fetch_assoc(pwg_query($query));
$storage_category_id = null;
if (!empty($row['storage_category_id']))
@@ -324,7 +324,7 @@ SELECT category_id, uppercats
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$name =
get_cat_display_name_cache(
@@ -417,7 +417,7 @@ if (isset($storage_category_id))
{
array_push($associateds, $storage_category_id);
}
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($associateds, $row['id']);
}
diff --git a/admin/rating.php b/admin/rating.php
index 99d703c72..5f3f93fa3 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -94,7 +94,7 @@ SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields'][
FROM '.USERS_TABLE.'
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$users[$row['id']]=stripslashes($row['username']);
}
@@ -104,7 +104,7 @@ $query = 'SELECT COUNT(DISTINCT(i.id))
FROM '.RATE_TABLE.' AS r, '.IMAGES_TABLE.' AS i
WHERE r.element_id=i.id'. $page['user_filter'] .
';';
-list($nb_images) = mysql_fetch_row(pwg_query($query));
+list($nb_images) = pwg_db_fetch_row(pwg_query($query));
// +-----------------------------------------------------------------------+
@@ -181,7 +181,7 @@ SELECT i.id,
$images = array();
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($images, $row);
}
@@ -199,7 +199,7 @@ FROM '.RATE_TABLE.' AS r
WHERE r.element_id='.$image['id'] . '
ORDER BY date DESC;';
$result = pwg_query($query);
- $nb_rates = mysql_num_rows($result);
+ $nb_rates = pwg_db_num_rows($result);
$tpl_image =
array(
@@ -214,7 +214,7 @@ ORDER BY date DESC;';
'rates' => array()
);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$url_del = PHPWG_ROOT_PATH.'admin.php'.
diff --git a/admin/site_manager.php b/admin/site_manager.php
index faec41166..2cc77bfbb 100644
--- a/admin/site_manager.php
+++ b/admin/site_manager.php
@@ -98,7 +98,7 @@ SELECT COUNT(id) AS count
FROM '.SITES_TABLE.'
WHERE galleries_url = \''.$url.'\'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
if ($row['count'] > 0)
{
array_push($page['errors'],
@@ -167,7 +167,7 @@ SELECT galleries_url
FROM '.SITES_TABLE.'
WHERE id = '.$page['site'].'
;';
- list($galleries_url) = mysql_fetch_row(pwg_query($query));
+ list($galleries_url) = pwg_db_fetch_row(pwg_query($query));
switch($_GET['action'])
{
case 'generate' :
@@ -236,7 +236,7 @@ SELECT *
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$is_remote = url_is_remote($row['galleries_url']);
$base_url = PHPWG_ROOT_PATH.'admin.php';
diff --git a/admin/site_update.php b/admin/site_update.php
index 543c7f718..84c6a8f87 100644
--- a/admin/site_update.php
+++ b/admin/site_update.php
@@ -43,14 +43,14 @@ $query='
SELECT galleries_url
FROM '.SITES_TABLE.'
WHERE id = '.$site_id;
-list($site_url) = mysql_fetch_row(pwg_query($query));
+list($site_url) = pwg_db_fetch_row(pwg_query($query));
if (!isset($site_url))
{
die('site '.$site_id.' does not exist');
}
$site_is_remote = url_is_remote($site_url);
-list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
define('CURRENT_DATE', $dbnow);
$error_labels = array(
@@ -185,7 +185,7 @@ SELECT id, uppercats, global_rank, status, visible
SELECT id
FROM '.CATEGORIES_TABLE;
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$next_rank[$row['id']] = 1;
}
@@ -196,7 +196,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
FROM '.CATEGORIES_TABLE.'
GROUP BY id_uppercat';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
// for the id_uppercat NULL, we write 'NULL' and not the empty string
if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
@@ -210,7 +210,7 @@ SELECT id_uppercat, MAX(rank)+1 AS next_rank
$query = '
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
FROM '.CATEGORIES_TABLE;
- list($next_id) = mysql_fetch_row(pwg_query($query));
+ list($next_id) = pwg_db_fetch_row(pwg_query($query));
// retrieve sub-directories fulldirs from the site reader
$fs_fulldirs = $site_reader->get_full_directories($basedir);
@@ -246,34 +246,34 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
'uploadable' => $site_is_remote
? 'false'
: boolean_to_string($conf['newcat_default_uploadable']),
- 'status' => $conf{'newcat_default_status'},
- 'visible' => boolean_to_string($conf{'newcat_default_visible'}),
+ 'status' => $conf['newcat_default_status'],
+ 'visible' => boolean_to_string($conf['newcat_default_visible']),
);
if (isset($db_fulldirs[dirname($fulldir)]))
{
$parent = $db_fulldirs[dirname($fulldir)];
- $insert{'id_uppercat'} = $parent;
- $insert{'uppercats'} =
- $db_categories[$parent]['uppercats'].','.$insert{'id'};
- $insert{'rank'} = $next_rank[$parent]++;
- $insert{'global_rank'} =
- $db_categories[$parent]['global_rank'].'.'.$insert{'rank'};
+ $insert['id_uppercat'] = $parent;
+ $insert['uppercats'] =
+ $db_categories[$parent]['uppercats'].','.$insert['id'];
+ $insert['rank'] = $next_rank[$parent]++;
+ $insert['global_rank'] =
+ $db_categories[$parent]['global_rank'].'.'.$insert['rank'];
if ('private' == $db_categories[$parent]['status'])
{
- $insert{'status'} = 'private';
+ $insert['status'] = 'private';
}
if ('false' == $db_categories[$parent]['visible'])
{
- $insert{'visible'} = 'false';
+ $insert['visible'] = 'false';
}
}
else
{
- $insert{'uppercats'} = $insert{'id'};
+ $insert['uppercats'] = $insert['id'];
$insert{'rank'} = $next_rank['NULL']++;
- $insert{'global_rank'} = $insert{'rank'};
+ $insert['global_rank'] = $insert['rank'];
}
array_push($inserts, $insert);
@@ -288,13 +288,13 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_id
// add the new category to $db_categories and $db_fulldirs array
$db_categories[$insert{'id'}] =
array(
- 'id' => $insert{'id'},
- 'status' => $insert{'status'},
- 'visible' => $insert{'visible'},
- 'uppercats' => $insert{'uppercats'},
- 'global_rank' => $insert{'global_rank'}
+ 'id' => $insert['id'],
+ 'status' => $insert['status'],
+ 'visible' => $insert['visible'],
+ 'uppercats' => $insert['uppercats'],
+ 'global_rank' => $insert['global_rank']
);
- $db_fulldirs[$fulldir] = $insert{'id'};
+ $db_fulldirs[$fulldir] = $insert['id'];
$next_rank[$insert{'id'}] = 1;
}
else
@@ -386,7 +386,7 @@ SELECT file,storage_category_id
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
AND validated = \'false\'';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$db_unvalidated,
@@ -402,7 +402,7 @@ SELECT file,storage_category_id
$query = '
SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
FROM '.IMAGES_TABLE;
- list($next_element_id) = mysql_fetch_row(pwg_query($query));
+ list($next_element_id) = pwg_db_fetch_row(pwg_query($query));
$start = get_moment();
@@ -470,7 +470,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
array_push(
$insert_links,
array(
- 'image_id' => $insert{'id'},
+ 'image_id' => $insert['id'],
'category_id' => $insert['storage_category_id'],
)
);
@@ -478,7 +478,7 @@ SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
array_push(
$infos,
array(
- 'path' => $insert{'path'},
+ 'path' => $insert['path'],
'info' => l10n('update_research_added')
)
);
@@ -555,7 +555,7 @@ SELECT id,file,storage_category_id,infos
$waiting_to_delete = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$data = array();
@@ -564,7 +564,7 @@ SELECT id
FROM '.IMAGES_TABLE.'
WHERE storage_category_id = '.$row['storage_category_id'].'
AND file = \''.$row['file'].'\'';
- list($data['id']) = mysql_fetch_row(pwg_query($query));
+ list($data['id']) = pwg_db_fetch_row(pwg_query($query));
foreach ($fields['update'] as $field)
{
diff --git a/admin/stats.php b/admin/stats.php
index 600cfcb6e..7a71e5927 100644
--- a/admin/stats.php
+++ b/admin/stats.php
@@ -95,7 +95,7 @@ SELECT
$result = pwg_query($query);
$output = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($output, $row);
}
@@ -133,7 +133,7 @@ $max_id = 0;
$is_first = true;
$first_time_key = null;
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$time_keys = array(
substr($row['date'], 0, 4), //yyyy
@@ -204,7 +204,7 @@ SELECT *
)
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$key = sprintf('%4u', $row['year']);
if ( isset($row['month']) )
diff --git a/admin/tags.php b/admin/tags.php
index 94c5bcb3d..949ccc22c 100644
--- a/admin/tags.php
+++ b/admin/tags.php
@@ -49,7 +49,7 @@ SELECT id, name
WHERE id IN ('.$_POST['edit_list'].')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$current_name_of[ $row['id'] ] = $row['name'];
}
@@ -220,7 +220,7 @@ SELECT id, name
WHERE id IN ('.implode(',', $_POST['tags']).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$name_of[ $row['id'] ] = $row['name'];
}
diff --git a/admin/template/goto/intro.tpl b/admin/template/goto/intro.tpl
index e529f3084..7d1d5b079 100644
--- a/admin/template/goto/intro.tpl
+++ b/admin/template/goto/intro.tpl
@@ -30,7 +30,7 @@ jQuery().ready(function(){ldelim}
<li>{'Operating system'|@translate}: {$OS}</li>
<li>PHP: {$PHP_VERSION} (<a href="{$U_PHPINFO}" onclick="window.open(this.href, '');
return false;">{'Show info'|@translate}</a>) [{$PHP_DATATIME}]</li>
- <li>MySQL: {$MYSQL_VERSION} [{$DB_DATATIME}]</li>
+ <li>{$DB_ENGINE}: {$DB_VERSION} [{$DB_DATATIME}]</li>
</ul>
</dd>
diff --git a/admin/thumbnail.php b/admin/thumbnail.php
index 635110303..7fc81dc3d 100644
--- a/admin/thumbnail.php
+++ b/admin/thumbnail.php
@@ -178,7 +178,7 @@ SELECT galleries_url FROM '.SITES_TABLE.'
WHERE galleries_url NOT LIKE "http://%"
;';
$result = pwg_query($query);
-while ( $row=mysql_fetch_assoc($result) )
+while ( $row=pwg_db_fetch_assoc($result) )
{
$basedir = preg_replace('#/*$#', '', $row['galleries_url']);
$fs = get_fs($basedir);
diff --git a/admin/upload.php b/admin/upload.php
index 94e526a35..12472810a 100644
--- a/admin/upload.php
+++ b/admin/upload.php
@@ -100,7 +100,7 @@ SELECT id, storage_category_id, file, tn_ext
WHERE id IN ('.implode(',', $to_reject).')
;';
$result = pwg_query($query);
- while($row = mysql_fetch_assoc($result))
+ while($row = pwg_db_fetch_assoc($result))
{
$dir = get_complete_dir($row['storage_category_id']);
unlink($dir.$row['file']);
@@ -153,7 +153,7 @@ $query.= " WHERE validated = 'false'";
$query.= ' ORDER BY storage_category_id';
$query.= ';';
$result = pwg_query( $query );
-while ( $row = mysql_fetch_assoc( $result ) )
+while ( $row = pwg_db_fetch_assoc( $result ) )
{
if ( !isset( $cat_names[$row['storage_category_id']] ) )
{
diff --git a/admin/user_list.php b/admin/user_list.php
index f679d95ce..c3956dc7b 100644
--- a/admin/user_list.php
+++ b/admin/user_list.php
@@ -49,7 +49,7 @@ function get_filtered_user_list()
if (isset($_GET['username']) and !empty($_GET['username']))
{
$username = str_replace('*', '%', $_GET['username']);
- $filter['username'] = mysql_real_escape_string($username);
+ $filter['username'] = pwg_db_real_escape_string($username);
}
if (isset($_GET['group'])
@@ -115,7 +115,7 @@ SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$user = $row;
$user['groups'] = array();
@@ -139,7 +139,7 @@ SELECT user_id, group_id
WHERE user_id IN ('.implode(',', $user_ids).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$users[$user_nums[$row['user_id']]]['groups'],
@@ -492,7 +492,7 @@ SELECT id, name
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$groups[$row['id']] = $row['name'];
}
diff --git a/admin/user_perm.php b/admin/user_perm.php
index 1d3b300f0..2156982c0 100644
--- a/admin/user_perm.php
+++ b/admin/user_perm.php
@@ -78,7 +78,7 @@ SELECT id
AND status = \'private\'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($private_uppercats, $row['id']);
}
@@ -95,7 +95,7 @@ SELECT cat_id
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($authorized_ids, $row['cat_id']);
}
@@ -155,10 +155,10 @@ SELECT DISTINCT cat_id, c.uppercats, c.global_rank
;';
$result = pwg_query($query);
-if (mysql_num_rows($result) > 0)
+if (pwg_db_num_rows($result) > 0)
{
$cats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($cats, $row);
array_push($group_authorized, $row['cat_id']);
@@ -191,7 +191,7 @@ display_select_cat_wrapper($query_true,array(),'category_option_true');
$result = pwg_query($query_true);
$authorized_ids = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($authorized_ids, $row['id']);
}
diff --git a/comments.php b/comments.php
index a9207da48..3300bc6aa 100644
--- a/comments.php
+++ b/comments.php
@@ -283,7 +283,7 @@ SELECT COUNT(DISTINCT(com.id))
WHERE '.implode('
AND ', $page['where_clauses']).'
;';
-list($counter) = mysql_fetch_row(pwg_query($query));
+list($counter) = pwg_db_fetch_row(pwg_query($query));
$url = PHPWG_ROOT_PATH
.'comments.php'
@@ -331,7 +331,7 @@ if ('all' != $page['items_number'])
$query.= '
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($comments, $row);
array_push($element_ids, $row['image_id']);
@@ -348,7 +348,7 @@ SELECT id, name, file, path, tn_ext
WHERE id IN ('.implode(',', $element_ids).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$elements[$row['id']] = $row;
}
diff --git a/feed.php b/feed.php
index cce6a1b1c..5f74d5091 100644
--- a/feed.php
+++ b/feed.php
@@ -75,7 +75,7 @@ SELECT user_id,
FROM '.USER_FEED_TABLE.'
WHERE id = \''.$feed_id.'\'
;';
- $feed_row = mysql_fetch_assoc(pwg_query($query));
+ $feed_row = pwg_db_fetch_assoc(pwg_query($query));
if ( empty($feed_row) )
{
page_not_found('Unknown/missing feed identifier');
@@ -97,7 +97,7 @@ else
// Check the status now after the user has been loaded
check_status(ACCESS_GUEST);
-list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index b4df9f5f8..e78824617 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -231,7 +231,7 @@ function build_global_calendar(&$tpl_var)
$result = pwg_query($query);
$items=array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$y = substr($row['period'], 0, 4);
$m = (int)substr($row['period'], 4, 2);
@@ -283,7 +283,7 @@ function build_year_calendar(&$tpl_var)
$result = pwg_query($query);
$items=array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$m = (int)substr($row['period'], 0, 2);
$d = substr($row['period'], 2, 2);
@@ -333,7 +333,7 @@ function build_month_calendar(&$tpl_var)
$items=array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$d = (int)$row['period'];
$items[$d] = array('nb_images'=>$row['count']);
@@ -351,7 +351,7 @@ SELECT id, file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 a
LIMIT 0,1';
unset ( $page['chronology_date'][CDAY] );
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
$items[$day]['tn_url'] = get_thumbnail_url($row);
$items[$day]['file'] = $row['file'];
$items[$day]['path'] = $row['path'];
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 1cd7c0407..0d35d4a85 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -75,7 +75,7 @@ $categories = array();
$category_ids = array();
$image_ids = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
@@ -108,9 +108,9 @@ SELECT image_id
LIMIT 0,1
;';
$subresult = pwg_query($query);
- if (mysql_num_rows($subresult) > 0)
+ if (pwg_db_num_rows($subresult) > 0)
{
- list($image_id) = mysql_fetch_row($subresult);
+ list($image_id) = pwg_db_fetch_row($subresult);
}
}
}
@@ -136,9 +136,9 @@ SELECT image_id
LIMIT 0,1
;';
$subresult = pwg_query($query);
- if (mysql_num_rows($subresult) > 0)
+ if (pwg_db_num_rows($subresult) > 0)
{
- list($image_id) = mysql_fetch_row($subresult);
+ list($image_id) = pwg_db_fetch_row($subresult);
}
}
}
@@ -178,7 +178,7 @@ SELECT
GROUP BY category_id
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$dates_of_category[ $row['category_id'] ] = array(
'from' => $row['date_creation_min'],
@@ -202,7 +202,7 @@ SELECT id, path, tn_ext
WHERE id IN ('.implode(',', $image_ids).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
}
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index ae24adec1..796a88989 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -45,7 +45,7 @@ SELECT *
WHERE id IN ('.implode(',', $selection).')
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['rank'] = $rank_of[ $row['id'] ];
diff --git a/include/common.inc.php b/include/common.inc.php
index a0ec209ef..9fdc014d5 100644
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -92,6 +92,7 @@ foreach( array(
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
+include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
{
@@ -104,22 +105,11 @@ include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
include( PHPWG_ROOT_PATH .'include/template.class.php');
// Database connection
-@mysql_connect( $conf['db_host'], $conf['db_user'], $conf['db_password'] ) or my_error( 'mysql_connect', true );
-@mysql_select_db( $conf['db_base'] ) or my_error( 'mysql_select_db', true );
+$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
+ $conf['db_password'], $conf['db_base'])
+ or my_error('pwg_db_connect', true);
-defined('PWG_CHARSET') and defined('DB_CHARSET')
- or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
-if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
-{
- if (DB_CHARSET!='')
- {
- pwg_query('SET NAMES "'.DB_CHARSET.'"');
- }
-}
-elseif ( strtolower(PWG_CHARSET)!='iso-8859-1' )
-{
- fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
-}
+pwg_db_check_charset();
load_conf_from_db();
load_plugins();
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
new file mode 100644
index 000000000..23d232675
--- /dev/null
+++ b/include/dblayer/functions_mysql.inc.php
@@ -0,0 +1,463 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 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 |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+/**
+ *
+ * simple functions
+ *
+ */
+
+function pwg_db_connect($host, $user, $password, $database)
+{
+ $link = mysql_connect($host, $user, $password) or my_error('mysql_connect', true);
+ mysql_select_db($database, $link) or my_error('mysql_select_db', true);
+
+ return $link;
+}
+
+function pwg_db_check_charset()
+{
+ defined('PWG_CHARSET') and defined('DB_CHARSET')
+ or fatal_error('PWG_CHARSET and/or DB_CHARSET is not defined');
+ if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
+ {
+ if (DB_CHARSET!='')
+ {
+ pwg_query('SET NAMES "'.DB_CHARSET.'"');
+ }
+ }
+ elseif ( strtolower(PWG_CHARSET)!='iso-8859-1' )
+ {
+ fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
+ }
+}
+
+function pwg_get_db_version()
+{
+ list($mysql_version) = pwg_db_fetch_row(pwg_query('SELECT VERSION();'));
+
+ return $mysql_version;
+}
+
+function pwg_query($query)
+{
+ global $conf,$page,$debug,$t2;
+
+ $start = get_moment();
+ ($result = mysql_query($query)) or my_error($query, $conf['die_on_sql_error']);
+
+ $time = get_moment() - $start;
+
+ if (!isset($page['count_queries']))
+ {
+ $page['count_queries'] = 0;
+ $page['queries_time'] = 0;
+ }
+
+ $page['count_queries']++;
+ $page['queries_time']+= $time;
+
+ if ($conf['show_queries'])
+ {
+ $output = '';
+ $output.= '<pre>['.$page['count_queries'].'] ';
+ $output.= "\n".$query;
+ $output.= "\n".'(this query time : ';
+ $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>';
+ $output.= "\n".'(total SQL time : ';
+ $output.= number_format($page['queries_time'], 3, '.', ' ').' s)';
+ $output.= "\n".'(total time : ';
+ $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)';
+ if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) )
+ {
+ $output.= "\n".'(num rows : ';
+ $output.= mysql_num_rows($result).' )';
+ }
+ elseif ( $result!=null
+ and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) )
+ {
+ $output.= "\n".'(affected rows : ';
+ $output.= mysql_affected_rows().' )';
+ }
+ $output.= "</pre>\n";
+
+ $debug .= $output;
+ }
+
+ return $result;
+}
+
+function pwg_db_changes($result)
+{
+ return mysql_affected_rows($result);
+}
+
+function pwg_db_num_rows($result)
+{
+ return mysql_num_rows($result);
+}
+
+function pwg_db_fetch_assoc($result)
+{
+ return mysql_fetch_assoc($result);
+}
+
+function pwg_db_fetch_row($result)
+{
+ return mysql_fetch_row($result);
+}
+
+function pwg_db_fetch_object($result)
+{
+ return mysql_fetch_object($result);
+}
+
+function pwg_free_result($result)
+{
+ return mysql_free_result($result);
+}
+
+function pwg_db_real_escape_string($s)
+{
+ return mysql_real_escape_string($s);
+}
+
+function pwg_db_insert_id()
+{
+ return mysql_insert_id();
+}
+
+/**
+ *
+ * complex functions
+ *
+ */
+
+/**
+ * creates an array based on a query, this function is a very common pattern
+ * used here
+ *
+ * @param string $query
+ * @param string $fieldname
+ * @return array
+ */
+function array_from_query($query, $fieldname)
+{
+ $array = array();
+
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_assoc($result))
+ {
+ array_push($array, $row[$fieldname]);
+ }
+
+ return $array;
+}
+
+define('MASS_UPDATES_SKIP_EMPTY', 1);
+/**
+ * updates multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array datas
+ * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
+ * @return void
+ */
+function mass_updates($tablename, $dbfields, $datas, $flags=0)
+{
+ if (count($datas) == 0)
+ return;
+ // depending on the MySQL version, we use the multi table update or N update queries
+ if (count($datas) < 10 or version_compare(mysql_get_server_info(), '4.0.4') < 0)
+ { // MySQL is prior to version 4.0.4, multi table update feature is not available
+ foreach ($datas as $data)
+ {
+ $query = '
+UPDATE '.$tablename.'
+ SET ';
+ $is_first = true;
+ foreach ($dbfields['update'] as $key)
+ {
+ $separator = $is_first ? '' : ",\n ";
+
+ if (isset($data[$key]) and $data[$key] != '')
+ {
+ $query.= $separator.$key.' = \''.$data[$key].'\'';
+ }
+ else
+ {
+ if ($flags & MASS_UPDATES_SKIP_EMPTY )
+ continue; // next field
+ $query.= "$separator$key = NULL";
+ }
+ $is_first = false;
+ }
+ if (!$is_first)
+ {// only if one field at least updated
+ $query.= '
+ WHERE ';
+ $is_first = true;
+ foreach ($dbfields['primary'] as $key)
+ {
+ if (!$is_first)
+ {
+ $query.= ' AND ';
+ }
+ if ( isset($data[$key]) )
+ {
+ $query.= $key.' = \''.$data[$key].'\'';
+ }
+ else
+ {
+ $query.= $key.' IS NULL';
+ }
+ $is_first = false;
+ }
+ pwg_query($query);
+ }
+ } // foreach update
+ } // if mysql_ver or count<X
+ else
+ {
+ // creation of the temporary table
+ $query = '
+SHOW FULL COLUMNS FROM '.$tablename;
+ $result = pwg_query($query);
+ $columns = array();
+ $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ if (in_array($row['Field'], $all_fields))
+ {
+ $column = $row['Field'];
+ $column.= ' '.$row['Type'];
+
+ $nullable = true;
+ if (!isset($row['Null']) or $row['Null'] == '' or $row['Null']=='NO')
+ {
+ $column.= ' NOT NULL';
+ $nullable = false;
+ }
+ if (isset($row['Default']))
+ {
+ $column.= " default '".$row['Default']."'";
+ }
+ elseif ($nullable)
+ {
+ $column.= " default NULL";
+ }
+ if (isset($row['Collation']) and $row['Collation'] != 'NULL')
+ {
+ $column.= " collate '".$row['Collation']."'";
+ }
+ array_push($columns, $column);
+ }
+ }
+
+ $temporary_tablename = $tablename.'_'.micro_seconds();
+
+ $query = '
+CREATE TABLE '.$temporary_tablename.'
+(
+ '.implode(",\n ", $columns).',
+ UNIQUE KEY the_key ('.implode(',', $dbfields['primary']).')
+)';
+
+ pwg_query($query);
+ mass_inserts($temporary_tablename, $all_fields, $datas);
+ if ( $flags & MASS_UPDATES_SKIP_EMPTY )
+ $func_set = create_function('$s', 'return "t1.$s = IFNULL(t2.$s, t1.$s)";');
+ else
+ $func_set = create_function('$s', 'return "t1.$s = t2.$s";');
+
+ // update of images table by joining with temporary table
+ $query = '
+UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
+ SET '.
+ implode(
+ "\n , ",
+ array_map($func_set,$dbfields['update'])
+ ).'
+ WHERE '.
+ implode(
+ "\n AND ",
+ array_map(
+ create_function('$s', 'return "t1.$s = t2.$s";'),
+ $dbfields['primary']
+ )
+ );
+ pwg_query($query);
+ $query = '
+DROP TABLE '.$temporary_tablename;
+ pwg_query($query);
+ }
+}
+
+
+/**
+ * inserts multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbfields
+ * @param array inserts
+ * @return void
+ */
+function mass_inserts($table_name, $dbfields, $datas)
+{
+ if (count($datas) != 0)
+ {
+ $first = true;
+
+ $query = 'SHOW VARIABLES LIKE \'max_allowed_packet\'';
+ list(, $packet_size) = pwg_db_fetch_row(pwg_query($query));
+ $packet_size = $packet_size - 2000; // The last list of values MUST not exceed 2000 character*/
+ $query = '';
+
+ foreach ($datas as $insert)
+ {
+ if (strlen($query) >= $packet_size)
+ {
+ pwg_query($query);
+ $first = true;
+ }
+
+ if ($first)
+ {
+ $query = '
+INSERT INTO '.$table_name.'
+ ('.implode(',', $dbfields).')
+ VALUES';
+ $first = false;
+ }
+ else
+ {
+ $query .= '
+ , ';
+ }
+
+ $query .= '(';
+ foreach ($dbfields as $field_id => $dbfield)
+ {
+ if ($field_id > 0)
+ {
+ $query .= ',';
+ }
+
+ if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
+ {
+ $query .= 'NULL';
+ }
+ else
+ {
+ $query .= "'".$insert[$dbfield]."'";
+ }
+ }
+ $query .= ')';
+ }
+ Log::getInstance()->debug($query);
+ pwg_query($query);
+ }
+}
+
+/**
+ * Do maintenance on all PWG tables
+ *
+ * @return none
+ */
+function do_maintenance_all_tables()
+{
+ global $prefixeTable, $page;
+
+ $all_tables = array();
+
+ // List all tables
+ $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\'';
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ array_push($all_tables, $row[0]);
+ }
+
+ // Repair all tables
+ $query = 'REPAIR TABLE '.implode(', ', $all_tables);
+ $mysql_rc = pwg_query($query);
+
+ // Re-Order all tables
+ foreach ($all_tables as $table_name)
+ {
+ $all_primary_key = array();
+
+ $query = 'DESC '.$table_name.';';
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ if ($row['Key'] == 'PRI')
+ {
+ array_push($all_primary_key, $row['Field']);
+ }
+ }
+
+ if (count($all_primary_key) != 0)
+ {
+ $query = 'ALTER TABLE '.$table_name.' ORDER BY '.implode(', ', $all_primary_key).';';
+ $mysql_rc = $mysql_rc && pwg_query($query);
+ }
+ }
+
+ // Optimize all tables
+ $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables);
+ $mysql_rc = $mysql_rc && pwg_query($query);
+ if ($mysql_rc)
+ {
+ array_push(
+ $page['infos'],
+ l10n('Optimizations completed')
+ );
+ }
+ else
+ {
+ array_push(
+ $page['errors'],
+ l10n('Optimizations errors')
+ );
+ }
+}
+
+// my_error returns (or send to standard output) the message concerning the
+// error occured for the last mysql query.
+function my_error($header, $die)
+{
+ $error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";
+ $error .= $header;
+
+ if ($die)
+ {
+ fatal_error($error);
+ }
+ echo("<pre>");
+ trigger_error($error, E_USER_WARNING);
+ echo("</pre>");
+}
+
+?> \ No newline at end of file
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 7353eda6a..a31c85f13 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -44,7 +44,7 @@ function get_enums($table, $field)
// retrieving the properties of the table. Each line represents a field :
// columns are 'Field', 'Type'
$result = pwg_query('desc '.$table);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
// we are only interested in the the field given in parameter for the
// function
@@ -59,7 +59,7 @@ function get_enums($table, $field)
}
}
}
- mysql_free_result($result);
+ pwg_db_free_result($result);
return $options;
}
@@ -596,54 +596,6 @@ function format_date($date, $show_time = false)
return $formated_date;
}
-function pwg_query($query)
-{
- global $conf,$page,$debug,$t2;
-
- $start = get_moment();
- ($result = mysql_query($query)) or my_error($query, $conf['die_on_sql_error']);
-
- $time = get_moment() - $start;
-
- if (!isset($page['count_queries']))
- {
- $page['count_queries'] = 0;
- $page['queries_time'] = 0;
- }
-
- $page['count_queries']++;
- $page['queries_time']+= $time;
-
- if ($conf['show_queries'])
- {
- $output = '';
- $output.= '<pre>['.$page['count_queries'].'] ';
- $output.= "\n".$query;
- $output.= "\n".'(this query time : ';
- $output.= '<b>'.number_format($time, 3, '.', ' ').' s)</b>';
- $output.= "\n".'(total SQL time : ';
- $output.= number_format($page['queries_time'], 3, '.', ' ').' s)';
- $output.= "\n".'(total time : ';
- $output.= number_format( ($time+$start-$t2), 3, '.', ' ').' s)';
- if ( $result!=null and preg_match('/\s*SELECT\s+/i',$query) )
- {
- $output.= "\n".'(num rows : ';
- $output.= mysql_num_rows($result).' )';
- }
- elseif ( $result!=null
- and preg_match('/\s*INSERT|UPDATE|REPLACE|DELETE\s+/i',$query) )
- {
- $output.= "\n".'(affected rows : ';
- $output.= mysql_affected_rows().' )';
- }
- $output.= "</pre>\n";
-
- $debug .= $output;
- }
-
- return $result;
-}
-
function pwg_debug( $string )
{
global $debug,$t2,$page;
@@ -905,44 +857,6 @@ function get_thumbnail_title($element_info)
return $thumbnail_title;
}
-// my_error returns (or send to standard output) the message concerning the
-// error occured for the last mysql query.
-function my_error($header, $die)
-{
- $error = "[mysql error ".mysql_errno().'] '.mysql_error()."\n";
- $error .= $header;
-
- if ($die)
- {
- fatal_error($error);
- }
- echo("<pre>");
- trigger_error($error, E_USER_WARNING);
- echo("</pre>");
-}
-
-
-/**
- * creates an array based on a query, this function is a very common pattern
- * used here
- *
- * @param string $query
- * @param string $fieldname
- * @return array
- */
-function array_from_query($query, $fieldname)
-{
- $array = array();
-
- $result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
- {
- array_push($array, $row[$fieldname]);
- }
-
- return $array;
-}
-
/**
* fill the current user caddie with given elements, if not already in
* caddie
@@ -1121,7 +1035,7 @@ SELECT '.$conf['user_fields']['email'].'
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].'
;';
- list($email) = mysql_fetch_row(pwg_query($query));
+ list($email) = pwg_db_fetch_row(pwg_query($query));
return $email;
}
@@ -1142,12 +1056,12 @@ SELECT param, value
;';
$result = pwg_query($query);
- if ((mysql_num_rows($result) == 0) and !empty($condition))
+ if ((pwg_db_num_rows($result) == 0) and !empty($condition))
{
fatal_error('No configuration data');
}
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : '';
@@ -1192,7 +1106,7 @@ function simple_hash_from_query($query, $keyname, $valuename)
$array = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$array[ $row[$keyname] ] = $row[$valuename];
}
@@ -1213,7 +1127,7 @@ function hash_from_query($query, $keyname)
{
$array = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$array[ $row[$keyname] ] = $row;
}
@@ -1584,7 +1498,7 @@ function get_icon($date, $is_child_date = false)
{
// Use MySql date in order to standardize all recent "actions/queries"
list($cache['get_icon']['sql_recent_date']) =
- mysql_fetch_row(pwg_query('select SUBDATE(
+ pwg_db_fetch_row(pwg_query('select SUBDATE(
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'));
}
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index dd2707b10..fb981fcbd 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -101,7 +101,7 @@ WHERE '.$where.'
$result = pwg_query($query);
$cats = array();
$selected_category = isset($page['category']) ? $page['category'] : null;
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$child_date_last = @$row['max_date_last']> @$row['date_last'];
$row = array_merge($row,
@@ -165,7 +165,7 @@ SELECT *
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$id.'
;';
- $cat = mysql_fetch_assoc(pwg_query($query));
+ $cat = pwg_db_fetch_assoc(pwg_query($query));
if (empty($cat))
return null;
@@ -240,7 +240,7 @@ function get_local_dir( $category_id )
$query = 'SELECT uppercats';
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
$query.= ';';
- $row = mysql_fetch_assoc( pwg_query( $query ) );
+ $row = pwg_db_fetch_assoc( pwg_query( $query ) );
$uppercats = $row['uppercats'];
}
@@ -251,7 +251,7 @@ function get_local_dir( $category_id )
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
$query.= ';';
$result = pwg_query( $query );
- while( $row = mysql_fetch_assoc( $result ) )
+ while( $row = pwg_db_fetch_assoc( $result ) )
{
$database_dirs[$row['id']] = $row['dir'];
}
@@ -275,7 +275,7 @@ SELECT galleries_url
WHERE s.id = c.site_id
AND c.id = '.$category_id.'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
return $row['galleries_url'];
}
@@ -344,7 +344,7 @@ function display_select_cat_wrapper($query, $selecteds, $blockname,
$categories = array();
if (!empty($result))
{
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($categories, $row);
}
@@ -384,7 +384,7 @@ SELECT DISTINCT(id)
$result = pwg_query($query);
$subcats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($subcats, $row['id']);
}
@@ -533,7 +533,7 @@ WHERE
).'
LIMIT 1';
- $show_link = mysql_num_rows(pwg_query($query)) <> 0;
+ $show_link = pwg_db_num_rows(pwg_query($query)) <> 0;
}
}
if ($show_link)
diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php
index aff7b9a35..f22aa3f6e 100644
--- a/include/functions_comment.inc.php
+++ b/include/functions_comment.inc.php
@@ -100,7 +100,7 @@ function insert_user_comment( &$comm, $key, &$infos )
SELECT COUNT(*) AS user_exists
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'";
- $row = mysql_fetch_assoc( pwg_query( $query ) );
+ $row = pwg_db_fetch_assoc( pwg_query( $query ) );
if ( $row['user_exists'] == 1 )
{
array_push($infos, l10n('comment_user_exists') );
@@ -138,7 +138,7 @@ SELECT COUNT(*) AS user_exists
SELECT id FROM '.COMMENTS_TABLE.'
WHERE date > FROM_UNIXTIME('.$reference_date.')
AND author_id = '.$comm['author_id'];
- if ( mysql_num_rows( pwg_query( $query ) ) > 0 )
+ if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 )
{
array_push( $infos, l10n('comment_anti-flood') );
$comment_action='reject';
@@ -168,7 +168,7 @@ INSERT INTO '.COMMENTS_TABLE.'
pwg_query($query);
- $comm['id'] = mysql_insert_id();
+ $comm['id'] = pwg_db_insert_id();
if (($comment_action=='validate' and $conf['email_admin_on_comment']) or
($comment_action!='validate' and $conf['email_admin_on_comment_validation']))
@@ -266,7 +266,7 @@ function update_user_comment($comment, $post_key)
SELECT id FROM '.COMMENTS_TABLE.'
WHERE date > FROM_UNIXTIME('.$reference_date.')
AND author_id = '.$comm['author_id'];
- if ( mysql_num_rows( pwg_query( $query ) ) > 0 )
+ if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 )
{
//?? array_push( $infos, l10n('comment_anti-flood') );
$comment_action='reject';
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index 50d342535..8ea8ec8ae 100644
--- a/include/functions_mail.inc.php
+++ b/include/functions_mail.inc.php
@@ -351,7 +351,7 @@ order by
$datas = pwg_query($query);
if (!empty($datas))
{
- while ($admin = mysql_fetch_assoc($datas))
+ while ($admin = pwg_db_fetch_assoc($datas))
{
if (!empty($admin['mail_address']))
{
@@ -447,10 +447,10 @@ WHERE
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
$list = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['template_theme'] = $row['template'];
list($row['template'], $row['theme']) = explode('/', $row['template_theme']);
@@ -476,10 +476,10 @@ WHERE
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
$Bcc = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if (!empty($row['mail_address']))
{
diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php
index 5bc3e56b8..b9789ee02 100644
--- a/include/functions_notification.inc.php
+++ b/include/functions_notification.inc.php
@@ -145,7 +145,7 @@ function custom_notification_query($action, $type, $start, $end)
}
$query = 'SELECT count(distinct '.$field_id.') as CountId
'.$query;
- list($count) = mysql_fetch_row(pwg_query($query));
+ list($count) = pwg_db_fetch_row(pwg_query($query));
return $count;
break;
@@ -178,7 +178,7 @@ function custom_notification_query($action, $type, $start, $end)
$infos = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($infos, $row);
}
@@ -448,7 +448,7 @@ SELECT date_available,
;';
$result = pwg_query($query);
$dates = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($dates, $row);
}
@@ -468,7 +468,7 @@ SELECT DISTINCT id, path, name, tn_ext, file
;';
$dates[$i]['elements'] = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($dates[$i]['elements'], $row);
}
@@ -488,7 +488,7 @@ SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
;';
$dates[$i]['categories'] = array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($dates[$i]['categories'], $row);
}
diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php
index 9f1ecac01..a6bbbb31f 100644
--- a/include/functions_plugins.inc.php
+++ b/include/functions_plugins.inc.php
@@ -238,7 +238,7 @@ SELECT * FROM '.PLUGINS_TABLE;
$result = pwg_query($query);
$plugins = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($plugins, $row);
}
diff --git a/include/functions_rate.inc.php b/include/functions_rate.inc.php
index 520c257c2..a9b6f804e 100644
--- a/include/functions_rate.inc.php
+++ b/include/functions_rate.inc.php
@@ -124,7 +124,7 @@ SELECT COUNT(rate) AS count
FROM '.RATE_TABLE.'
WHERE element_id = '.$image_id.'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
$query = '
UPDATE '.IMAGES_TABLE.'
SET average_rate = '.$row['average'].'
diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php
index d9e424471..bb9de6a64 100644
--- a/include/functions_search.inc.php
+++ b/include/functions_search.inc.php
@@ -41,7 +41,7 @@ SELECT rules
FROM '.SEARCH_TABLE.'
WHERE id = '.$search_id.'
;';
- list($serialized_rules) = mysql_fetch_row(pwg_query($query));
+ list($serialized_rules) = pwg_db_fetch_row(pwg_query($query));
return unserialize($serialized_rules);
}
@@ -458,7 +458,7 @@ SELECT i.id,
$by_weights=array();
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{ // weight is important when sorting images by relevance
if ($row['weight'])
{
@@ -489,7 +489,7 @@ SELECT image_id, COUNT(tag_id) AS weight
WHERE tag_id IN ('.implode(',',array_keys($tags)).')
GROUP BY image_id';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{ // weight is important when sorting images by relevance
$image_id=(int)$row['image_id'];
@$by_weights[$image_id] += $row['weight'];
@@ -510,7 +510,7 @@ SELECT id, name, permalink, nb_images
array( 'visible_categories' => 'cat_id' ), "\n AND"
);
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{ // weight is important when sorting images by relevance
if ($row['nb_images']==0)
{
diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php
index 1145d3dcc..79fe21c4d 100644
--- a/include/functions_session.inc.php
+++ b/include/functions_session.inc.php
@@ -121,7 +121,7 @@ SELECT data
$result = pwg_query($query);
if ($result)
{
- $row = mysql_fetch_assoc($result);
+ $row = pwg_db_fetch_assoc($result);
return $row['data'];
}
else
diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php
index 033967ca4..c3978ad39 100644
--- a/include/functions_tag.inc.php
+++ b/include/functions_tag.inc.php
@@ -63,7 +63,7 @@ SELECT *
FROM '.TAGS_TABLE;
$result = pwg_query($query);
$tags = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$counter = @$tag_counters[ $row['id'] ];
if ( $counter )
@@ -88,7 +88,7 @@ SELECT *
;';
$result = pwg_query($query);
$tags = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($tags, $row);
}
@@ -249,7 +249,7 @@ SELECT t.*, count(*) counter
$result = pwg_query($query);
$tags = array();
- while($row = mysql_fetch_assoc($result))
+ while($row = pwg_db_fetch_assoc($result))
{
array_push($tags, $row);
}
@@ -311,7 +311,7 @@ SELECT *
$result = pwg_query($query);
$tags = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($tags, $row);
}
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index f8f02719f..51f8420c9 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -58,7 +58,7 @@ from '.USERS_TABLE.'
where upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\')
'.(is_numeric($user_id) ? 'and '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').'
;';
- list($count) = mysql_fetch_row(pwg_query($query));
+ list($count) = pwg_db_fetch_row(pwg_query($query));
if ($count != 0)
{
return l10n('reg_err_mail_address_dbl');
@@ -110,12 +110,12 @@ function register_user($login, $password, $mail_address,
SELECT MAX('.$conf['user_fields']['id'].') + 1
FROM '.USERS_TABLE.'
;';
- list($next_id) = mysql_fetch_row(pwg_query($query));
+ list($next_id) = pwg_db_fetch_row(pwg_query($query));
$insert =
array(
$conf['user_fields']['id'] => $next_id,
- $conf['user_fields']['username'] => mysql_real_escape_string($login),
+ $conf['user_fields']['username'] => pwg_db_real_escape_string($login),
$conf['user_fields']['password'] => $conf['pass_convert']($password),
$conf['user_fields']['email'] => $mail_address
);
@@ -134,7 +134,7 @@ SELECT id
$result = pwg_query($query);
$inserts = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push
(
@@ -249,7 +249,7 @@ SELECT ';
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
while (true)
{
@@ -259,7 +259,7 @@ SELECT ui.*, uc.*
ON ui.user_id = uc.user_id
WHERE ui.user_id = \''.$user_id.'\'';
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
break;
}
@@ -269,7 +269,7 @@ SELECT ui.*, uc.*
}
}
- $row = array_merge($row, mysql_fetch_assoc($result));
+ $row = array_merge($row, pwg_db_fetch_assoc($result));
foreach ($row as $key => $value)
{
@@ -324,7 +324,7 @@ SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')';
- list($userdata['nb_total_images']) = mysql_fetch_row(pwg_query($query));
+ list($userdata['nb_total_images']) = pwg_db_fetch_row(pwg_query($query));
// now we update user cache categories
@@ -428,7 +428,7 @@ SELECT DISTINCT f.image_id
;';
$result = pwg_query($query);
$authorizeds = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($authorizeds, $row['image_id']);
}
@@ -440,7 +440,7 @@ SELECT image_id
;';
$result = pwg_query($query);
$favorites = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($favorites, $row['image_id']);
}
@@ -481,7 +481,7 @@ SELECT id
WHERE status = \'private\'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($private_array, $row['id']);
}
@@ -523,7 +523,7 @@ SELECT id
WHERE visible = \'false\'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($forbidden_array, $row['id']);
}
@@ -647,7 +647,7 @@ FROM '.CATEGORIES_TABLE.' as c
$result = pwg_query($query);
$cats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['user_id'] = $userdata['id'];
$row['count_categories'] = 0;
@@ -692,7 +692,7 @@ function get_userid($username)
{
global $conf;
- $username = mysql_real_escape_string($username);
+ $username = pwg_db_real_escape_string($username);
$query = '
SELECT '.$conf['user_fields']['id'].'
@@ -701,13 +701,13 @@ SELECT '.$conf['user_fields']['id'].'
;';
$result = pwg_query($query);
- if (mysql_num_rows($result) == 0)
+ if (pwg_db_num_rows($result) == 0)
{
return false;
}
else
{
- list($user_id) = mysql_fetch_row($result);
+ list($user_id) = pwg_db_fetch_row($result);
return $user_id;
}
}
@@ -727,7 +727,7 @@ SELECT COUNT(*)
FROM '.USER_FEED_TABLE.'
WHERE id = \''.$key.'\'
;';
- list($count) = mysql_fetch_row(pwg_query($query));
+ list($count) = pwg_db_fetch_row(pwg_query($query));
if (0 == $count)
{
return $key;
@@ -750,7 +750,7 @@ function get_default_user_info($convert_str = true)
' WHERE user_id = '.$conf['default_user_id'].';';
$result = pwg_query($query);
- $cache['default_user'] = mysql_fetch_assoc($result);
+ $cache['default_user'] = pwg_db_fetch_assoc($result);
if ($cache['default_user'] !== false)
{
@@ -865,7 +865,7 @@ function create_user_infos($arg_id, $override_values = null)
if (!empty($user_ids))
{
$inserts = array();
- list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+ list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
$default_user = get_default_user_info(false);
if ($default_user === false)
@@ -930,9 +930,9 @@ SELECT '.$conf['user_fields']['username'].' AS username
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['id'].' = '.$user_id;
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
- $row = mysql_fetch_assoc($result);
+ $row = pwg_db_fetch_assoc($result);
$username = stripslashes($row['username']);
$data = $time.stripslashes($row['username']).$row['password'];
$key = base64_encode(
@@ -1041,7 +1041,7 @@ SELECT '.$conf['user_fields']['id'].' AS id,
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['username'].' = \''.mysql_real_escape_string($username).'\'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
if ($row['password'] == $conf['pass_convert']($password))
{
log_user($row['id'], $remember_me);
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index 599f2229d..c8891493e 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -93,7 +93,7 @@ if ($page['show_comments'])
SELECT COUNT(*) AS nb_comments
FROM '.COMMENTS_TABLE.'
WHERE image_id='.$page['image_id']." AND validated = 'true'";
- $row = mysql_fetch_assoc( pwg_query( $query ) );
+ $row = pwg_db_fetch_assoc( pwg_query( $query ) );
// navigation bar creation
if (!isset($page['start']))
@@ -140,7 +140,7 @@ $validated_clause.'
;';
$result = pwg_query( $query );
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if (!empty($row['author']))
{
diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php
index 3543cfa37..9c4758241 100644
--- a/include/picture_rate.inc.php
+++ b/include/picture_rate.inc.php
@@ -37,7 +37,7 @@ SELECT COUNT(rate) AS count
FROM '.RATE_TABLE.'
WHERE element_id = '.$picture['current']['id'].'
;';
- $row = mysql_fetch_assoc(pwg_query($query));
+ $row = pwg_db_fetch_assoc(pwg_query($query));
}
else
{ // avg rate null -> no rate -> no need to query db
@@ -67,9 +67,9 @@ SELECT COUNT(rate) AS count
}
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
- $row = mysql_fetch_assoc($result);
+ $row = pwg_db_fetch_assoc($result);
$user_rate = $row['rate'];
}
}
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index bfb62b913..49dfdc47e 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -256,7 +256,7 @@ SELECT id, name, permalink, image_order
AND ', $where_clauses);
$result = pwg_query($query);
$cats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['id'] = (int)$row['id'];
$cats[ $row['id'] ] = $row;
@@ -295,7 +295,7 @@ GROUP BY i.id
LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$image = array();
foreach ( array('id', 'width', 'height', 'hit') as $k )
@@ -405,7 +405,7 @@ SELECT id, name, permalink, uppercats, global_rank,
$result = pwg_query($query);
$cats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['url'] = make_index_url(
array(
@@ -471,7 +471,7 @@ SELECT
$result = pwg_query($query);
$cats = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$id = $row['id'];
$row['nb_images'] = isset($nb_images_of[$id]) ? $nb_images_of[$id] : 0;
@@ -517,7 +517,7 @@ SELECT DISTINCT image_id
),
' AND'
);
- if ( !mysql_num_rows( pwg_query( $query ) ) )
+ if ( !pwg_db_num_rows( pwg_query( $query ) ) )
{
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
}
@@ -577,7 +577,7 @@ SELECT * FROM '.IMAGES_TABLE.'
).'
LIMIT 1';
- $image_row = mysql_fetch_assoc(pwg_query($query));
+ $image_row = pwg_db_fetch_assoc(pwg_query($query));
if ($image_row==null)
{
return new PwgError(404, "image_id not found");
@@ -598,7 +598,7 @@ SELECT id, name, permalink, uppercats, global_rank, commentable
$result = pwg_query($query);
$is_commentable = false;
$related_categories = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if ($row['commentable']=='true')
{
@@ -655,7 +655,7 @@ SELECT COUNT(rate) AS count
FROM '.RATE_TABLE.'
WHERE element_id = '.$image_row['id'].'
;';
- $rating = mysql_fetch_assoc(pwg_query($query));
+ $rating = pwg_db_fetch_assoc(pwg_query($query));
$rating['count'] = (int)$rating['count'];
//---------------------------------------------------------- related comments
@@ -686,7 +686,7 @@ SELECT id, date, author, content
','.(int)$params['comments_per_page'];
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$row['id']=(int)$row['id'];
array_push($related_comments, $row);
@@ -757,7 +757,7 @@ SELECT DISTINCT id FROM '.IMAGES_TABLE.'
' AND'
).'
LIMIT 1';
- if ( mysql_num_rows( pwg_query($query) )==0 )
+ if ( pwg_db_num_rows( pwg_query($query) )==0 )
{
return new PwgError(404, "Invalid image_id or access denied" );
}
@@ -813,7 +813,7 @@ SELECT * FROM '.IMAGES_TABLE.'
$image_ids = array_flip($image_ids);
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$image = array();
foreach ( array('id', 'width', 'height', 'hit') as $k )
@@ -870,7 +870,7 @@ UPDATE '.IMAGES_TABLE.'
SET level='.(int)$params['level'].'
WHERE id IN ('.implode(',',$params['image_id']).')';
$result = pwg_query($query);
- $affected_rows = mysql_affected_rows();
+ $affected_rows = pwg_db_affected_rows();
if ($affected_rows)
{
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
@@ -1007,13 +1007,13 @@ SELECT
FROM '.IMAGES_TABLE.'
WHERE md5sum = \''.$params['original_sum'].'\'
;';
- list($counter) = mysql_fetch_row(pwg_query($query));
+ list($counter) = pwg_db_fetch_row(pwg_query($query));
if ($counter != 0) {
return new PwgError(500, 'file already exists');
}
// current date
- list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+ list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
// upload directory hierarchy
@@ -1199,7 +1199,7 @@ SELECT
array($insert)
);
- $image_id = mysql_insert_id();
+ $image_id = pwg_db_insert_id();
// let's add links between the image and the categories
if (isset($params['categories']))
@@ -1358,7 +1358,7 @@ SELECT image_id, GROUP_CONCAT(tag_id) tag_ids
WHERE tag_id IN ('.implode(',',$tag_ids).')
GROUP BY image_id';
$result = pwg_query($query);
- while ( $row=mysql_fetch_assoc($result) )
+ while ( $row=pwg_db_fetch_assoc($result) )
{
$row['image_id'] = (int)$row['image_id'];
array_push( $image_ids, $row['image_id'] );
@@ -1401,7 +1401,7 @@ SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i
LIMIT '.(int)($params['per_page']*$params['page']).','.(int)$params['per_page'];
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$image = array();
foreach ( array('id', 'width', 'height', 'hit') as $k )
@@ -1572,7 +1572,7 @@ SELECT *
WHERE id = '.$params['image_id'].'
;';
- $image_row = mysql_fetch_assoc(pwg_query($query));
+ $image_row = pwg_db_fetch_assoc(pwg_query($query));
if ($image_row == null)
{
return new PwgError(404, "image_id not found");
diff --git a/install.php b/install.php
index 135c7fb47..a031d1bca 100644
--- a/install.php
+++ b/install.php
@@ -364,7 +364,7 @@ define(\'DB_COLLATE\', \'\');
// Available upgrades must be ignored after a fresh installation. To
// make PWG avoid upgrading, we must tell it upgrades have already been
// made.
- list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+ list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
define('CURRENT_DATE', $dbnow);
$datas = array();
foreach (get_available_upgrade_ids() as $upgrade_id)
diff --git a/install/db/1-database.php b/install/db/1-database.php
index bd3441a3e..11554645f 100644
--- a/install/db/1-database.php
+++ b/install/db/1-database.php
@@ -32,7 +32,7 @@ $upgrade_description = 'Just a beginning test';
// | Upgrade content |
// +-----------------------------------------------------------------------+
-list($now) = mysql_fetch_row(pwg_query('SELECT NOW()'));
+list($now) = pwg_db_fetch_row(pwg_query('SELECT NOW()'));
echo
$now
."\n"
diff --git a/install/db/12-database.php b/install/db/12-database.php
index 5ccadd324..a6402f7f5 100644
--- a/install/db/12-database.php
+++ b/install/db/12-database.php
@@ -66,7 +66,7 @@ $result = pwg_query($query);
$datas = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$datas,
diff --git a/install/db/18-database.php b/install/db/18-database.php
index 9843fb6af..c93249611 100644
--- a/install/db/18-database.php
+++ b/install/db/18-database.php
@@ -47,7 +47,7 @@ $result = pwg_query($query);
$datas = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$datas,
diff --git a/install/db/19-database.php b/install/db/19-database.php
index 709e23bde..ada51b809 100644
--- a/install/db/19-database.php
+++ b/install/db/19-database.php
@@ -68,7 +68,7 @@ SELECT id, keywords
WHERE keywords IS NOT NULL
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
foreach(preg_split('/[,]+/', $row['keywords']) as $keyword)
{
diff --git a/install/db/20-database.php b/install/db/20-database.php
index 9a29624b1..cf5ba0e73 100644
--- a/install/db/20-database.php
+++ b/install/db/20-database.php
@@ -47,7 +47,7 @@ SELECT category_id, image_id
$result = pwg_query($query);
$datas = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$datas,
diff --git a/install/db/65-database.php b/install/db/65-database.php
index 2d445ea3f..a43f433ee 100644
--- a/install/db/65-database.php
+++ b/install/db/65-database.php
@@ -108,7 +108,7 @@ if ( !defined('PWG_CHARSET') )
SELECT language, COUNT(user_id) AS count FROM '.USER_INFOS_TABLE.'
GROUP BY language';
$result = pwg_query($query);
- while ( $row=mysql_fetch_assoc($result) )
+ while ( $row=pwg_db_fetch_assoc($result) )
{
$language = $row["language"];
$lang_def = explode('.', $language);
@@ -141,7 +141,7 @@ SELECT language, COUNT(user_id) AS count FROM '.USER_INFOS_TABLE.'
SELECT language FROM '.USER_INFOS_TABLE.'
WHERE user_id='.$conf['webmaster_id'];
$result = pwg_query($query);
- if (mysql_num_rows($result)==0)
+ if (pwg_db_num_rows($result)==0)
{
$query='
SELECT language FROM '.USER_INFOS_TABLE.'
@@ -150,7 +150,7 @@ SELECT language FROM '.USER_INFOS_TABLE.'
$result = pwg_query($query);
}
- if ( $row=mysql_fetch_assoc($result) )
+ if ( $row=pwg_db_fetch_assoc($result) )
{
$admin_charset = $all_langs[$row['language']]['charset'];
}
@@ -165,7 +165,7 @@ SELECT language FROM '.USER_INFOS_TABLE.'
$all_tables = array();
$query = 'SHOW TABLES LIKE "'.$prefixeTable.'%"';
$result = pwg_query($query);
- while ( $row=mysql_fetch_assoc($result) )
+ while ( $row=pwg_db_fetch_assoc($result) )
{
array_push($all_tables, $row[0]);
}
@@ -176,7 +176,7 @@ SELECT language FROM '.USER_INFOS_TABLE.'
$query = 'SHOW FULL COLUMNS FROM '.$table;
$result = pwg_query($query);
$field_definitions=array();
- while ( $row=mysql_fetch_assoc($result) )
+ while ( $row=pwg_db_fetch_assoc($result) )
{
if ( !isset($row['Collation']) or $row['Collation']=='NULL' )
continue;
diff --git a/install/db/8-database.php b/install/db/8-database.php
index de742dcf7..89f92104b 100644
--- a/install/db/8-database.php
+++ b/install/db/8-database.php
@@ -60,7 +60,7 @@ $conf = $conf_save;
// +-Do I already have them in DB ?----------------------------------------+
$query = 'SELECT param FROM '.PREFIX_TABLE.'config';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
unset( $params[ $row['param'] ] );
}
diff --git a/install/db/9-database.php b/install/db/9-database.php
index 77f92c008..a21a99e89 100644
--- a/install/db/9-database.php
+++ b/install/db/9-database.php
@@ -47,7 +47,7 @@ $result = pwg_query($query);
$datas = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push(
$datas,
diff --git a/install/upgrade_1.3.0.php b/install/upgrade_1.3.0.php
index 761e016b0..c924dfecf 100644
--- a/install/upgrade_1.3.0.php
+++ b/install/upgrade_1.3.0.php
@@ -84,7 +84,7 @@ SELECT id, id_uppercat
FROM '.CATEGORIES_TABLE.'
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '')
{
diff --git a/install/upgrade_1.3.1.php b/install/upgrade_1.3.1.php
index 40657c7f7..8cd57538b 100644
--- a/install/upgrade_1.3.1.php
+++ b/install/upgrade_1.3.1.php
@@ -42,7 +42,7 @@ $query = '
SELECT prefix_thumbnail, mail_webmaster
FROM '.PREFIX_TABLE.'config
;';
-$save = mysql_fetch_assoc(pwg_query($query));
+$save = pwg_db_fetch_assoc(pwg_query($query));
$queries = array(
"
@@ -344,7 +344,7 @@ SHOW INDEX
FROM '.PREFIX_TABLE.$table.'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
if ($row['Key_name'] != 'PRIMARY')
{
@@ -536,7 +536,7 @@ SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
FROM '.IMAGES_TABLE.'
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($cat_ids, $row['unique_storage_category_id']);
}
@@ -561,7 +561,7 @@ SELECT id
WHERE status = \'private\'
;';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($cat_ids, $row['id']);
}
diff --git a/install/upgrade_1.4.0.php b/install/upgrade_1.4.0.php
index 78ff1d5f7..05e59a132 100644
--- a/install/upgrade_1.4.0.php
+++ b/install/upgrade_1.4.0.php
@@ -42,7 +42,7 @@ SELECT value
FROM '.CONFIG_TABLE.'
WHERE param = \'prefix_thumbnail\'
;';
-list($prefix_thumbnail) = mysql_fetch_row(pwg_query($query));
+list($prefix_thumbnail) = pwg_db_fetch_row(pwg_query($query));
// delete obsolete configuration
$query = '
@@ -191,10 +191,10 @@ SELECT *
;';
$datas = array();
-list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
$row['user_id'] = $row['id'];
$row['registration_date'] = $dbnow;
diff --git a/install/upgrade_1.5.0.php b/install/upgrade_1.5.0.php
index 87f9a0c7c..c1ea2e344 100644
--- a/install/upgrade_1.5.0.php
+++ b/install/upgrade_1.5.0.php
@@ -79,7 +79,7 @@ SELECT id, keywords
WHERE keywords IS NOT NULL
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
foreach(preg_split('/[,]+/', $row['keywords']) as $keyword)
{
@@ -351,7 +351,7 @@ $conf = $conf_save;
// Do I already have them in DB ?
$query = 'SELECT param FROM '.PREFIX_TABLE.'config';
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
unset( $params[ $row['param'] ] );
}
@@ -452,7 +452,7 @@ DESC '.PREFIX_TABLE.'users
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
if (!in_array($row['Field'], $to_keep))
{
diff --git a/install/upgrade_1.7.0.php b/install/upgrade_1.7.0.php
index af8ca6103..a1bbb18f3 100644
--- a/install/upgrade_1.7.0.php
+++ b/install/upgrade_1.7.0.php
@@ -35,7 +35,7 @@ else
define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db');
-list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
+list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
define('CURRENT_DATE', $dbnow);
// +-----------------------------------------------------------------------+
diff --git a/password.php b/password.php
index ffa8f4f61..33d04be8c 100644
--- a/password.php
+++ b/password.php
@@ -56,7 +56,7 @@ if (isset($_POST['submit']))
}
else if (isset($_POST['mail_address']) and !empty($_POST['mail_address']))
{
- $mail_address = mysql_real_escape_string($_POST['mail_address']);
+ $mail_address = pwg_db_real_escape_string($_POST['mail_address']);
$query = '
SELECT '.$conf['user_fields']['id'].' AS id
@@ -74,12 +74,12 @@ WHERE '
;';
$result = pwg_query($query);
- if (mysql_num_rows($result) > 0)
+ if (pwg_db_num_rows($result) > 0)
{
$error_on_mail = false;
$datas = array();
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
$new_password = generate_key(6);
diff --git a/picture.php b/picture.php
index d98fcfc21..f7f065a9b 100644
--- a/picture.php
+++ b/picture.php
@@ -57,7 +57,7 @@ SELECT id, file, level
str_replace(array('_','%'), array('/_','/%'), $page['image_file'] ).
'.%" ESCAPE "/" LIMIT 1';
}
- if ( ! ( $row = mysql_fetch_assoc(pwg_query($query)) ) )
+ if ( ! ( $row = pwg_db_fetch_assoc(pwg_query($query)) ) )
{// element does not exist
page_not_found( 'The requested image does not exist',
duplicate_index_url()
@@ -93,7 +93,7 @@ SELECT id
" AND"
).'
LIMIT 1';
- if ( mysql_num_rows( pwg_query($query) ) == 0 )
+ if ( pwg_db_num_rows( pwg_query($query) ) == 0 )
{
access_denied();
}
@@ -387,7 +387,7 @@ SELECT category_id,uppercats,commentable,global_rank
;';
$result = pwg_query($query);
$related_categories = array();
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
array_push($related_categories, $row);
}
@@ -415,7 +415,7 @@ SELECT *
$result = pwg_query($query);
-while ($row = mysql_fetch_assoc($result))
+while ($row = pwg_db_fetch_assoc($result))
{
if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
{
@@ -767,7 +767,7 @@ SELECT COUNT(*) AS nb_fav
AND user_id = '.$user['id'].'
;';
$result = pwg_query($query);
- $row = mysql_fetch_assoc($result);
+ $row = pwg_db_fetch_assoc($result);
if ($row['nb_fav'] == 0)
{
diff --git a/profile.php b/profile.php
index 214fc461d..636dcd29c 100644
--- a/profile.php
+++ b/profile.php
@@ -55,7 +55,7 @@ SELECT '.implode(',', $fields).'
WHERE user_id = '.$conf['default_user_id'].'
;';
$result = pwg_query($query);
- $default_user = mysql_fetch_assoc($result);
+ $default_user = pwg_db_fetch_assoc($result);
$userdata = array_merge($userdata, $default_user);
}
@@ -162,7 +162,7 @@ function save_profile_from_post($userdata, &$errors)
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
;';
- list($current_password) = mysql_fetch_row(pwg_query($query));
+ list($current_password) = pwg_db_fetch_row(pwg_query($query));
if ($conf['pass_convert']($_POST['password']) != $current_password)
{
diff --git a/qsearch.php b/qsearch.php
index 6a476f4af..feb549b55 100644
--- a/qsearch.php
+++ b/qsearch.php
@@ -60,7 +60,7 @@ INSERT INTO '.SEARCH_TABLE.'
(\''.addslashes(serialize($search)).'\', NOW() )
;';
pwg_query($query);
- $search_id = mysql_insert_id();
+ $search_id = pwg_db_insert_id();
}
redirect(
diff --git a/search.php b/search.php
index 9d967ea49..fdcbab701 100644
--- a/search.php
+++ b/search.php
@@ -136,7 +136,7 @@ INSERT INTO '.SEARCH_TABLE.'
;';
pwg_query($query);
- $search_id = mysql_insert_id();
+ $search_id = pwg_db_insert_id();
}
else
{
diff --git a/search_rules.php b/search_rules.php
index fb2fd612b..e78c7aac6 100644
--- a/search_rules.php
+++ b/search_rules.php
@@ -135,7 +135,7 @@ SELECT id, uppercats, global_rank
$categories = array();
if (!empty($result))
{
- while ($row = mysql_fetch_assoc($result))
+ while ($row = pwg_db_fetch_assoc($result))
{
array_push($categories, $row);
}
diff --git a/upgrade.php b/upgrade.php
index a425ec731..817f8db93 100644
--- a/upgrade.php
+++ b/upgrade.php
@@ -43,6 +43,7 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
include(PHPWG_ROOT_PATH.'include/config_database.inc.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
+include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
prepare_conf_upgrade();
@@ -50,13 +51,11 @@ include_once(PHPWG_ROOT_PATH.'include/constants.php');
define('PREFIX_TABLE', $prefixeTable);
// Database connection
-mysql_connect( $conf['db_host'], $conf['db_user'], $conf['db_password'] ) or die ( "Could not connect to database server" );
-mysql_select_db( $conf['db_base'] ) or die ( "Could not connect to database" );
-if ( version_compare(mysql_get_server_info(), '4.1.0', '>=')
- and defined('DB_CHARSET') and DB_CHARSET!='' )
-{
- pwg_query('SET NAMES "'.DB_CHARSET.'"');
-}
+$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
+ $conf['db_password'], $conf['db_base'])
+ or my_error('pwg_db_connect', true);
+
+pwg_db_check_charset();
// +-----------------------------------------------------------------------+
// | functions |
@@ -76,7 +75,7 @@ SHOW TABLES
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_row($result))
+ while ($row = pwg_db_fetch_row($result))
{
if (preg_match('/^'.PREFIX_TABLE.'/', $row[0]))
{
@@ -105,7 +104,7 @@ DESC '.$table.'
$columns_of[$table] = array();
- while ($row = mysql_fetch_row($result))
+ while ($row = pwg_db_fetch_row($result))
{
array_push($columns_of[$table], $row[0]);
}
diff --git a/upgrade_feed.php b/upgrade_feed.php
index 21b10393d..ccb91e681 100644
--- a/upgrade_feed.php
+++ b/upgrade_feed.php
@@ -35,6 +35,7 @@ include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
include(PHPWG_ROOT_PATH.'include/config_database.inc.php');
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
+include(PHPWG_ROOT_PATH .'include/dblayer/functions_mysql.inc.php');
// +-----------------------------------------------------------------------+
// | Check Access and exit when it is not ok |
@@ -54,14 +55,11 @@ define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db');
// | Database connection |
// +-----------------------------------------------------------------------+
-mysql_connect($conf['db_host'], $conf['db_user'], $conf['db_password']) or die("Could not connect to database server");
-mysql_select_db($conf['db_base']) or die("Could not connect to database");
-if ( version_compare(mysql_get_server_info(), '4.1.0', '>=')
- and defined('DB_CHARSET') and DB_CHARSET!='' )
-{
- pwg_query('SET NAMES "'.DB_CHARSET.'"');
-}
+$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
+ $conf['db_password'], $conf['db_base'])
+ or my_error('pwg_db_connect', true);
+pwg_db_check_charset();
// +-----------------------------------------------------------------------+
// | Upgrades |
diff --git a/upload.php b/upload.php
index 036ddc9e7..5e595f90c 100644
--- a/upload.php
+++ b/upload.php
@@ -248,7 +248,7 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
$query.= ",'".$_POST['mail_address']."',".time().",'".$xml_infos."')";
$query.= ';';
pwg_query( $query );
- $page['waiting_id'] = mysql_insert_id();
+ $page['waiting_id'] = pwg_db_insert_id();
if ($conf['email_admin_on_picture_uploaded'])
{
@@ -288,7 +288,7 @@ if ( isset( $_POST['submit'] ) and isset( $_GET['waiting_id'] ) )
$query.= ' where id = '.$_GET['waiting_id'];
$query.= ';';
$result= pwg_query( $query );
- $row = mysql_fetch_assoc( $result );
+ $row = pwg_db_fetch_assoc( $result );
$file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
$extension = get_extension( $_FILES['picture']['name'] );