1: <?php
2: /**
3: * ManiaLive - TrackMania dedicated server manager in PHP
4: *
5: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
6: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
7: * @version $Revision: 440 $:
8: * @author $Author: martin.gwendal $:
9: * @date $Date: 2012-08-17 12:03:09 +0200 (ven., 17 août 2012) $:
10: */
11:
12: namespace ManiaLive\Database;
13:
14: abstract class Utils
15: {
16: /**
17: * Returns the "LIMIT x OFFSET x" string depending on both values
18: */
19: static function getLimitString($offset, $length)
20: {
21: if(!$length)
22: {
23: return '';
24: }
25: elseif(!$offset)
26: {
27: return 'LIMIT '.$length;
28: }
29: else
30: {
31: return 'LIMIT '.$length.' OFFSET '.$offset;
32: }
33: }
34:
35: /**
36: * Returns string like "(name1, name2) VALUES (value1, value2)"
37: */
38: static function getValuesString(array $values)
39: {
40: return
41: '('.implode(', ', array_keys($values)).') '.
42: 'VALUES '.
43: '('.implode(', ', $values).')';
44: }
45:
46: /**
47: * Returns string like "name1=VALUES(name1), name2=VALUES(name2)"
48: */
49: static function getOnDuplicateKeyUpdateValuesString(array $valueNames)
50: {
51: $strings = array();
52: foreach($valueNames as $valueName)
53: {
54: $strings[] = $valueName.'=VALUES('.$valueName.')';
55: }
56: return implode(', ', $strings);
57: }
58: }
59:
60: ?>