From 924dd262ec3778277cf1efedee92fa5dd4fb2d32 Mon Sep 17 00:00:00 2001 From: nikrou Date: Fri, 20 Nov 2009 14:17:04 +0000 Subject: 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 --- admin/include/functions.php | 308 +++----------------------------------------- 1 file changed, 20 insertions(+), 288 deletions(-) (limited to 'admin/include/functions.php') 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); @@ -408,210 +408,6 @@ function get_fs_directories($path, $recursive = true) return $dirs; } -/** - * 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 $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 { @@ -1595,70 +1391,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. * @@ -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 { -- cgit v1.2.3