Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
mysqli.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Database
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Query Building Class.
14  *
15  * @package Joomla.Platform
16  * @subpackage Database
17  * @since 11.1
18  */
20 {
21  /**
22  * @var integer The offset for the result set.
23  * @since 12.1
24  */
25  protected $offset;
26 
27  /**
28  * @var integer The limit for the result set.
29  * @since 12.1
30  */
31  protected $limit;
32 
33  /**
34  * Method to modify a query already in string format with the needed
35  * additions to make the query limited to a particular number of
36  * results, or start at a particular offset.
37  *
38  * @param string $query The query in string format
39  * @param integer $limit The limit for the result set
40  * @param integer $offset The offset for the result set
41  *
42  * @return string
43  *
44  * @since 12.1
45  */
46  public function processLimit($query, $limit, $offset = 0)
47  {
48  if ($limit > 0 || $offset > 0)
49  {
50  $query .= ' LIMIT ' . $offset . ', ' . $limit;
51  }
52 
53  return $query;
54  }
55 
56  /**
57  * Concatenates an array of column names or values.
58  *
59  * @param array $values An array of values to concatenate.
60  * @param string $separator As separator to place between each value.
61  *
62  * @return string The concatenated values.
63  *
64  * @since 11.1
65  */
66  public function concatenate($values, $separator = null)
67  {
68  if ($separator)
69  {
70  $concat_string = 'CONCAT_WS(' . $this->quote($separator);
71 
72  foreach ($values as $value)
73  {
74  $concat_string .= ', ' . $value;
75  }
76 
77  return $concat_string . ')';
78  }
79  else
80  {
81  return 'CONCAT(' . implode(',', $values) . ')';
82  }
83  }
84 
85  /**
86  * Sets the offset and limit for the result set, if the database driver supports it.
87  *
88  * Usage:
89  * $query->setLimit(100, 0); (retrieve 100 rows, starting at first record)
90  * $query->setLimit(50, 50); (retrieve 50 rows, starting at 50th record)
91  *
92  * @param integer $limit The limit for the result set
93  * @param integer $offset The offset for the result set
94  *
95  * @return JDatabaseQuery Returns this object to allow chaining.
96  *
97  * @since 12.1
98  */
99  public function setLimit($limit = 0, $offset = 0)
100  {
101  $this->limit = (int) $limit;
102  $this->offset = (int) $offset;
103 
104  return $this;
105  }
106 }