Project

General

Profile

« Previous | Next » 

Revision 1364

Added by Dietmar almost 14 years ago

added function 'db_update_key_value()'

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12

  
13 13
------------------------------------- 2.8.2 -------------------------------------
14
29 Dec-2010 Build 1364 Dietmar Woellbrink (Luisehahne)
15
! added function 'db_update_key_value()'
14 16
29 Dec-2010 Build 1363 Dietmar Woellbrink (Luisehahne)
15 17
# Ticket #1053, Ticket #941 show_breadcrumb
16 18
29 Dec-2010 Build 1362 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.2.RC2');
55
if(!defined('REVISION')) define('REVISION', '1363');
55
if(!defined('REVISION')) define('REVISION', '1364');
56 56

  
57 57
?>
branches/2.8.x/wb/framework/class.database.php
315 315
	}
316 316

  
317 317
}
318

  
318
/* this function is placed inside this file temporarely until a better place is found */
319
/*  function to update a var/value-pair(s) in table ****************************
320
 *  nonexisting keys are inserted
321
 *  @param string $table: name of table to use (without prefix)
322
 *  @param mixed $key:    a array of key->value pairs to update
323
 *                        or a string with name of the key to update
324
 *  @param string $value: a sting with needed value, if $key is a string too
325
 *  @return bool:  true if any keys are updated, otherwise false
326
 */
327
	function db_update_key_value($table, $key, $value = '')
328
	{
329
		global $database;
330
		if( !is_array($key))
331
		{
332
			if( trim($key) != '' )
333
			{
334
				$key = array( trim($key) => trim($value) );
335
			} else {
336
				$key = array();
337
			}
338
		}
339
		$retval = true;
340
		foreach( $key as $index=>$val)
341
		{
342
			$index = strtolower($index);
343
			$sql = 'SELECT COUNT(`setting_id`) FROM `'.TABLE_PREFIX.$table.'` WHERE `name` = \''.$index.'\' ';
344
			if($database->get_one($sql))
345
			{
346
				$sql = 'UPDATE ';
347
				$sql_where = 'WHERE `name` = \''.$index.'\'';
348
			}else {
349
				$sql = 'INSERT INTO ';
350
				$sql_where = '';
351
			}
352
			$sql .= '`'.TABLE_PREFIX.$table.'` ';
353
			$sql .= 'SET `name` = \''.$index.'\', ';
354
			$sql .= '`value` = \''.$val.'\' '.$sql_where;
355
			if( !$database->query($sql) )
356
			{
357
				$retval = false;
358
			}
359
		}
360
		return $retval;
361
	}
319 362
?>

Also available in: Unified diff