3 * QueryUtils. This class contains static convenience functions for generating
4 * SQL and executing it. It is up to the caller to ensure the SQL is properly
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Matthew Vita <matthewvita48@gmail.com>
20 * @link http://www.open-emr.org
23 namespace OpenEMR\Common\Utils
;
28 * Shared getter for SQL selects.
30 * @param $sqlUpToFromStatement - The sql string up to (and including) the FROM line.
31 * @param $map - Query information (where clause(s), join clause(s), order, data, etc).
32 * @return array of associative arrays | one associative array.
34 public static function selectHelper($sqlUpToFromStatement, $map)
36 $where = isset($map["where"]) ?
$map["where"] : null;
37 $data = isset($map["data"]) ?
$map["data"] : null;
38 $join = isset($map["join"]) ?
$map["join"] : null;
39 $order = isset($map["order"]) ?
$map["order"] : null;
40 $limit = isset($map["limit"]) ?
$map["limit"] : null;
42 $sql = $sqlUpToFromStatement;
44 $sql .= !empty($join) ?
" " . $join : "";
45 $sql .= !empty($where) ?
" " . $where : "";
46 $sql .= !empty($order) ?
" " . $order : "";
47 $sql .= !empty($limit) ?
" LIMIT " . $limit : "";
50 if (empty($limit) ||
$limit > 1) {
51 $multipleResults = sqlStatement($sql, $data);
54 while ($row = sqlFetchArray($multipleResults)) {
55 array_push($results, $row);
61 return sqlQuery($sql, $data);
64 if (empty($limit) ||
$limit > 1) {
65 $multipleResults = sqlStatement($sql);
68 while ($row = sqlFetchArray($multipleResults)) {
69 array_push($results, $row);
75 return sqlQuery($sql);