|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* If finder class is not powerful enough use this one |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package Datamapper |
|
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
11
|
|
|
* @copyright 2013 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\datamapper; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* If finder class is not powerful enough use this one |
|
20
|
|
|
* |
|
21
|
|
|
* @category Core |
|
22
|
|
|
* @package Datamapper |
|
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
24
|
|
|
* @copyright 2013 cSphere Team |
|
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
26
|
|
|
* @link http://www.csphere.eu |
|
27
|
|
|
**/ |
|
28
|
|
|
|
|
29
|
|
|
class SQL |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Database service object |
|
33
|
|
|
**/ |
|
34
|
|
|
private $_database = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Prepare values that are needed for later usage |
|
38
|
|
|
* |
|
39
|
|
|
* @return \csphere\core\datamapper\SQL |
|
40
|
|
|
**/ |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
// Get database service object |
|
45
|
|
|
$loader = \csphere\core\service\Locator::get(); |
|
46
|
|
|
|
|
47
|
|
|
$this->_database = $loader->load('database'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Send direct SQL requests to the database |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $prepare Prepared query string with placeholders |
|
54
|
|
|
* @param array $assoc Array with columns and values |
|
55
|
|
|
* @param integer $first Number of the first dataset to show |
|
56
|
|
|
* @param integer $max Number of datasets to show from first on |
|
57
|
|
|
* |
|
58
|
|
|
* @return array |
|
59
|
|
|
**/ |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function query($prepare, array $assoc, $first = 0, $max = 1) |
|
62
|
|
|
{ |
|
63
|
|
|
// Pass query to database driver |
|
64
|
|
|
$result = $this->_database->query($prepare, $assoc, $first, $max); |
|
65
|
|
|
|
|
66
|
|
|
// Handle array dimension for max=1 since db layer uses fetch for that case |
|
67
|
|
|
if ($max == 1 && $result != []) { |
|
68
|
|
|
|
|
69
|
|
|
$result = [$result]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $result; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.