@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function __construct(array $params = null) |
| 24 | 24 | { |
| 25 | - if (!empty($params)) |
|
| 26 | - $this->fromMapToModel($params); |
|
| 25 | + if (!empty($params)) {
|
|
| 26 | + $this->fromMapToModel($params); |
|
| 27 | + } |
|
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | /** |
@@ -82,7 +83,9 @@ discard block |
||
| 82 | 83 | $data = (object) $this->toMap(); |
| 83 | 84 | $re_2 = new ReflectionObject($data); |
| 84 | 85 | $classname = get_class($this); |
| 85 | - if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
|
| 86 | + if ($pos = strrpos($classname, '\\')) {
|
|
| 87 | + $classname = substr($classname, $pos + 1); |
|
| 88 | + } |
|
| 86 | 89 | return $classname .' {' . implode(', ', array_map( |
| 87 | 90 | function($p_0) use ($data) |
| 88 | 91 | { |
@@ -51,8 +51,9 @@ discard block |
||
| 51 | 51 | $sql = "INSERT INTO {$this->tableName} ({$fields}) VALUES ({$numparams})";
|
| 52 | 52 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; }
|
| 53 | 53 | $result = $this->executeSQL($sql, $values); |
| 54 | - if (empty($result)) |
|
| 55 | - return false; |
|
| 54 | + if (empty($result)) {
|
|
| 55 | + return false; |
|
| 56 | + } |
|
| 56 | 57 | return true; |
| 57 | 58 | } |
| 58 | 59 | |
@@ -84,8 +85,9 @@ discard block |
||
| 84 | 85 | $query = "INSERT INTO $this->tableName"; |
| 85 | 86 | $values = []; |
| 86 | 87 | $dataColumns = array_keys($params); |
| 87 | - if (isset ($dataColumns[0])) |
|
| 88 | - $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 88 | + if (isset ($dataColumns[0])) {
|
|
| 89 | + $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 90 | + } |
|
| 89 | 91 | $query .= ' VALUES (';
|
| 90 | 92 | |
| 91 | 93 | foreach ($dataColumns as $index => $column) {
|
@@ -97,8 +99,9 @@ discard block |
||
| 97 | 99 | $query .= ')'; |
| 98 | 100 | |
| 99 | 101 | $result = $this->executeSQL($query, $values); |
| 100 | - if (empty($result)) |
|
| 101 | - return false; |
|
| 102 | + if (empty($result)) {
|
|
| 103 | + return false; |
|
| 104 | + } |
|
| 102 | 105 | return true; |
| 103 | 106 | } else {
|
| 104 | 107 | return false; |
@@ -123,8 +126,9 @@ discard block |
||
| 123 | 126 | if (isset($where)) { $sql .= " WHERE $where"; }
|
| 124 | 127 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; }
|
| 125 | 128 | $result = $this->executeSQL($sql, $values); |
| 126 | - if (empty($result)) |
|
| 127 | - return false; |
|
| 129 | + if (empty($result)) {
|
|
| 130 | + return false; |
|
| 131 | + } |
|
| 128 | 132 | return true; |
| 129 | 133 | } |
| 130 | 134 | |
@@ -165,12 +169,14 @@ discard block |
||
| 165 | 169 | } |
| 166 | 170 | $query = rtrim($query, ", "); |
| 167 | 171 | |
| 168 | - if (!empty($where)) |
|
| 169 | - $query .= " WHERE {$where}";
|
|
| 172 | + if (!empty($where)) {
|
|
| 173 | + $query .= " WHERE {$where}";
|
|
| 174 | + } |
|
| 170 | 175 | |
| 171 | 176 | $result = $this->executeSQL($query, $values); |
| 172 | - if (empty($result)) |
|
| 173 | - return false; |
|
| 177 | + if (empty($result)) {
|
|
| 178 | + return false; |
|
| 179 | + } |
|
| 174 | 180 | return true; |
| 175 | 181 | } else {
|
| 176 | 182 | return false; |
@@ -190,8 +196,9 @@ discard block |
||
| 190 | 196 | if (!empty($where)) { $sql .= " WHERE $where"; }
|
| 191 | 197 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; return; }
|
| 192 | 198 | $result = $this->executeSQL($sql, $values); |
| 193 | - if (empty($result)) |
|
| 194 | - return false; |
|
| 199 | + if (empty($result)) {
|
|
| 200 | + return false; |
|
| 201 | + } |
|
| 195 | 202 | return true; |
| 196 | 203 | } |
| 197 | 204 | |
@@ -277,18 +277,26 @@ |
||
| 277 | 277 | $indexed = $params == array_values($params); |
| 278 | 278 | foreach($params as $k=>$v) {
|
| 279 | 279 | if (is_object($v)) {
|
| 280 | - if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s');
|
|
| 281 | - else continue; |
|
| 280 | + if ($v instanceof \DateTime) {
|
|
| 281 | + $v = $v->format('Y-m-d H:i:s');
|
|
| 282 | + } else {
|
|
| 283 | + continue; |
|
| 284 | + } |
|
| 285 | + } elseif (is_string($v)) {
|
|
| 286 | + $v="'$v'"; |
|
| 287 | + } elseif ($v === null) {
|
|
| 288 | + $v='NULL'; |
|
| 289 | + } elseif (is_array($v)) {
|
|
| 290 | + $v = implode(',', $v);
|
|
| 282 | 291 | } |
| 283 | - elseif (is_string($v)) $v="'$v'"; |
|
| 284 | - elseif ($v === null) $v='NULL'; |
|
| 285 | - elseif (is_array($v)) $v = implode(',', $v);
|
|
| 286 | 292 | |
| 287 | 293 | if ($indexed) {
|
| 288 | 294 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1);
|
| 289 | - } |
|
| 290 | - else {
|
|
| 291 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
| 295 | + } else {
|
|
| 296 | + if ($k[0] != ':') {
|
|
| 297 | + $k = ':'.$k; |
|
| 298 | + } |
|
| 299 | + //add leading colon if it was left out |
|
| 292 | 300 | $sql_string = str_replace($k,$v,$sql_string); |
| 293 | 301 | } |
| 294 | 302 | } |