Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Driver / IbmDb2 / Statement.php
blob362f7a8896fbdd3c6883ce355adbd49b0a66947c
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Adapter\Driver\IbmDb2;
12 use Zend\Db\Adapter\Driver\StatementInterface;
13 use Zend\Db\Adapter\Exception;
14 use Zend\Db\Adapter\ParameterContainer;
15 use Zend\Db\Adapter\Profiler;
17 class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
19 /**
20 * @var resource
22 protected $db2 = null;
24 /**
25 * @var IbmDb2
27 protected $driver = null;
29 /**
30 * @var Profiler\ProfilerInterface
32 protected $profiler = null;
34 /**
35 * @var string
37 protected $sql = '';
39 /**
40 * @var ParameterContainer
42 protected $parameterContainer = null;
44 /**
45 * @var bool
47 protected $isPrepared = false;
49 /**
50 * @var resource
52 protected $resource = null;
54 /**
55 * @param $resource
56 * @return Statement
58 public function initialize($resource)
60 $this->db2 = $resource;
61 return $this;
64 /**
65 * @param IbmDb2 $driver
66 * @return Statement
68 public function setDriver(IbmDb2 $driver)
70 $this->driver = $driver;
71 return $this;
74 /**
75 * @param Profiler\ProfilerInterface $profiler
76 * @return Statement
78 public function setProfiler(Profiler\ProfilerInterface $profiler)
80 $this->profiler = $profiler;
81 return $this;
84 /**
85 * @return null|Profiler\ProfilerInterface
87 public function getProfiler()
89 return $this->profiler;
92 /**
93 * Set sql
95 * @param $sql
96 * @return mixed
98 public function setSql($sql)
100 $this->sql = $sql;
101 return $this;
105 * Get sql
107 * @return mixed
109 public function getSql()
111 return $this->sql;
115 * Set parameter container
117 * @param ParameterContainer $parameterContainer
118 * @return mixed
120 public function setParameterContainer(ParameterContainer $parameterContainer)
122 $this->parameterContainer = $parameterContainer;
123 return $this;
127 * Get parameter container
129 * @return mixed
131 public function getParameterContainer()
133 return $this->parameterContainer;
137 * @param $resource
138 * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
140 public function setResource($resource)
142 if (get_resource_type($resource) !== 'DB2 Statement') {
143 throw new Exception\InvalidArgumentException('Resource must be of type DB2 Statement');
145 $this->resource = $resource;
149 * Get resource
151 * @return resource
153 public function getResource()
155 return $this->resource;
159 * Prepare sql
161 * @param string|null $sql
162 * @return Statement
164 public function prepare($sql = null)
166 if ($this->isPrepared) {
167 throw new Exception\RuntimeException('This statement has been prepared already');
170 if ($sql == null) {
171 $sql = $this->sql;
174 $this->resource = db2_prepare($this->db2, $sql);
176 if ($this->resource === false) {
177 throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error());
180 $this->isPrepared = true;
181 return $this;
185 * Check if is prepared
187 * @return bool
189 public function isPrepared()
191 return $this->isPrepared;
195 * Execute
197 * @param null $parameters
198 * @return Result
200 public function execute($parameters = null)
202 if (!$this->isPrepared) {
203 $this->prepare();
206 /** START Standard ParameterContainer Merging Block */
207 if (!$this->parameterContainer instanceof ParameterContainer) {
208 if ($parameters instanceof ParameterContainer) {
209 $this->parameterContainer = $parameters;
210 $parameters = null;
211 } else {
212 $this->parameterContainer = new ParameterContainer();
216 if (is_array($parameters)) {
217 $this->parameterContainer->setFromArray($parameters);
219 /** END Standard ParameterContainer Merging Block */
221 if ($this->profiler) {
222 $this->profiler->profilerStart($this);
225 set_error_handler(function () {}, E_WARNING); // suppress warnings
226 $response = db2_execute($this->resource, $this->parameterContainer->getPositionalArray());
227 restore_error_handler();
229 if ($this->profiler) {
230 $this->profiler->profilerFinish();
233 if ($response === false) {
234 throw new Exception\RuntimeException(db2_stmt_errormsg($this->resource));
237 $result = $this->driver->createResult($this->resource);
238 return $result;