@@ -34,8 +34,9 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | private function getInstance(): ?PDO |
| 36 | 36 | {
|
| 37 | - if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao") ) |
|
| 38 | - $this->database .= "Homologacao"; |
|
| 37 | + if (strpos($_SERVER['SERVER_NAME'], "homologacao") && !strpos($this->database, "Homologacao") ) {
|
|
| 38 | + $this->database .= "Homologacao"; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | if (!isset($this->instance)) {
|
| 41 | 42 | $this->instance = Connect::getInstance($this->database); |
@@ -340,18 +341,26 @@ discard block |
||
| 340 | 341 | $indexed = $params == array_values($params); |
| 341 | 342 | foreach($params as $k=>$v) {
|
| 342 | 343 | if (is_object($v)) {
|
| 343 | - if ($v instanceof \DateTime) $v = $v->format('Y-m-d H:i:s');
|
|
| 344 | - else continue; |
|
| 344 | + if ($v instanceof \DateTime) {
|
|
| 345 | + $v = $v->format('Y-m-d H:i:s');
|
|
| 346 | + } else {
|
|
| 347 | + continue; |
|
| 348 | + } |
|
| 349 | + } elseif (is_string($v)) {
|
|
| 350 | + $v="'$v'"; |
|
| 351 | + } elseif ($v === null) {
|
|
| 352 | + $v='NULL'; |
|
| 353 | + } elseif (is_array($v)) {
|
|
| 354 | + $v = implode(',', $v);
|
|
| 345 | 355 | } |
| 346 | - elseif (is_string($v)) $v="'$v'"; |
|
| 347 | - elseif ($v === null) $v='NULL'; |
|
| 348 | - elseif (is_array($v)) $v = implode(',', $v);
|
|
| 349 | 356 | |
| 350 | 357 | if ($indexed) {
|
| 351 | 358 | $sql_string = preg_replace('/\?/', $v, $sql_string, 1);
|
| 352 | - } |
|
| 353 | - else {
|
|
| 354 | - if ($k[0] != ':') $k = ':'.$k; //add leading colon if it was left out |
|
| 359 | + } else {
|
|
| 360 | + if ($k[0] != ':') {
|
|
| 361 | + $k = ':'.$k; |
|
| 362 | + } |
|
| 363 | + //add leading colon if it was left out |
|
| 355 | 364 | $sql_string = str_replace($k,$v,$sql_string); |
| 356 | 365 | } |
| 357 | 366 | } |
@@ -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>"; die(); }
|
| 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 | |
@@ -66,8 +67,9 @@ discard block |
||
| 66 | 67 | $query = "INSERT INTO $this->tableName"; |
| 67 | 68 | $values = []; |
| 68 | 69 | $dataColumns = array_keys($params); |
| 69 | - if (isset ($dataColumns[0])) |
|
| 70 | - $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 70 | + if (isset ($dataColumns[0])) {
|
|
| 71 | + $query .= ' (`' . implode('`, `', $dataColumns) . '`) ';
|
|
| 72 | + } |
|
| 71 | 73 | $query .= ' VALUES (';
|
| 72 | 74 | |
| 73 | 75 | foreach ($dataColumns as $index => $column) {
|
@@ -78,8 +80,9 @@ discard block |
||
| 78 | 80 | $query .= ')'; |
| 79 | 81 | |
| 80 | 82 | $result = $this->executeSQL($query, $values); |
| 81 | - if (empty($result)) |
|
| 82 | - return false; |
|
| 83 | + if (empty($result)) {
|
|
| 84 | + return false; |
|
| 85 | + } |
|
| 83 | 86 | return true; |
| 84 | 87 | } else {
|
| 85 | 88 | return false; |
@@ -104,8 +107,9 @@ discard block |
||
| 104 | 107 | if (isset($where)) { $sql .= " WHERE $where"; }
|
| 105 | 108 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; die(); }
|
| 106 | 109 | $result = $this->executeSQL($sql, $values); |
| 107 | - if (empty($result)) |
|
| 108 | - return false; |
|
| 110 | + if (empty($result)) {
|
|
| 111 | + return false; |
|
| 112 | + } |
|
| 109 | 113 | return true; |
| 110 | 114 | } |
| 111 | 115 | |
@@ -126,12 +130,14 @@ discard block |
||
| 126 | 130 | } |
| 127 | 131 | $query = rtrim($query, ", "); |
| 128 | 132 | |
| 129 | - if (!empty($where)) |
|
| 130 | - $query .= " WHERE {$where}";
|
|
| 133 | + if (!empty($where)) {
|
|
| 134 | + $query .= " WHERE {$where}";
|
|
| 135 | + } |
|
| 131 | 136 | |
| 132 | 137 | $result = $this->executeSQL($query, $values); |
| 133 | - if (empty($result)) |
|
| 134 | - return false; |
|
| 138 | + if (empty($result)) {
|
|
| 139 | + return false; |
|
| 140 | + } |
|
| 135 | 141 | return true; |
| 136 | 142 | } else {
|
| 137 | 143 | return false; |
@@ -150,8 +156,9 @@ discard block |
||
| 150 | 156 | if (!empty($where)) { $sql .= " WHERE $where"; }
|
| 151 | 157 | if ($debug) { echo $sql; echo "<pre>"; print_r($values); echo "</pre>"; die(); }
|
| 152 | 158 | $result = $this->executeSQL($sql, $values); |
| 153 | - if (empty($result)) |
|
| 154 | - return false; |
|
| 159 | + if (empty($result)) {
|
|
| 160 | + return false; |
|
| 161 | + } |
|
| 155 | 162 | return true; |
| 156 | 163 | } |
| 157 | 164 | |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | * @param array|null $params |
| 11 | 11 | */ |
| 12 | 12 | public function __construct(array $params = null){ |
| 13 | - if (!empty($params)) |
|
| 14 | - $this->fromMapToModel($params); |
|
| 13 | + if (!empty($params)) {
|
|
| 14 | + $this->fromMapToModel($params); |
|
| 15 | + } |
|
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | /** |
@@ -70,7 +71,9 @@ discard block |
||
| 70 | 71 | $data = (object) $this->toMap(); |
| 71 | 72 | $re_2 = new ReflectionObject($data); |
| 72 | 73 | $classname = get_class($this); |
| 73 | - if ($pos = strrpos($classname, '\\')) $classname = substr($classname, $pos + 1); |
|
| 74 | + if ($pos = strrpos($classname, '\\')) {
|
|
| 75 | + $classname = substr($classname, $pos + 1); |
|
| 76 | + } |
|
| 74 | 77 | return $classname .' {' . implode(', ', array_map( |
| 75 | 78 | function($p_0) use ($data) |
| 76 | 79 | { |