@@ -18,7 +18,7 @@ |
||
18 | 18 | |
19 | 19 | private function setTabla(string $tabla): string |
20 | 20 | { |
21 | - if(strlen($tabla) < 1) |
|
21 | + if (strlen($tabla) < 1) |
|
22 | 22 | { |
23 | 23 | throw new Exception("La tabla no puede estar vacia"); |
24 | 24 | } |
@@ -8,8 +8,7 @@ discard block |
||
8 | 8 | private $_tabla; |
9 | 9 | private $_valoresAInsertar; |
10 | 10 | |
11 | - public function __construct |
|
12 | - ( |
|
11 | + public function __construct( |
|
13 | 12 | Tabla $Tabla, |
14 | 13 | ValoresAInsertar $ValoresAInsertar |
15 | 14 | ) |
@@ -23,19 +22,19 @@ discard block |
||
23 | 22 | $keys = array_keys($this->_valoresAInsertar->valoresAInsertar()); |
24 | 23 | $values = ''; |
25 | 24 | |
26 | - $x=1; |
|
27 | - foreach($this->_valoresAInsertar->valoresAInsertar() as $field) |
|
25 | + $x = 1; |
|
26 | + foreach ($this->_valoresAInsertar->valoresAInsertar() as $field) |
|
28 | 27 | { |
29 | - $values.= "?"; |
|
28 | + $values .= "?"; |
|
30 | 29 | |
31 | - if($x < count($this->_valoresAInsertar->valoresAInsertar())) |
|
30 | + if ($x < count($this->_valoresAInsertar->valoresAInsertar())) |
|
32 | 31 | { |
33 | - $values.= ', '; |
|
32 | + $values .= ', '; |
|
34 | 33 | } |
35 | 34 | |
36 | 35 | $x++; |
37 | 36 | } |
38 | 37 | |
39 | - return "INSERT INTO ". $this->_tabla->tabla()." (`". implode('`, `', $keys) ."`) VALUES ({$values})"; |
|
38 | + return "INSERT INTO ".$this->_tabla->tabla()." (`".implode('`, `', $keys)."`) VALUES ({$values})"; |
|
40 | 39 | } |
41 | 40 | } |
42 | 41 | \ No newline at end of file |
@@ -19,7 +19,7 @@ |
||
19 | 19 | |
20 | 20 | private function setValoresAInsertar(array $array): array |
21 | 21 | { |
22 | - if(count($array) < 1) |
|
22 | + if (count($array) < 1) |
|
23 | 23 | { |
24 | 24 | throw new Exception("Error, no hay valores para insertar"); |
25 | 25 | } |
@@ -13,8 +13,7 @@ discard block |
||
13 | 13 | private $_query; |
14 | 14 | public $_ultimaIdInsertada = null; |
15 | 15 | |
16 | - public function __construct |
|
17 | - ( |
|
16 | + public function __construct( |
|
18 | 17 | ConexionBaseDeDatos $ConexionBaseDeDatos, |
19 | 18 | Query $Query |
20 | 19 | ) |
@@ -27,12 +26,12 @@ discard block |
||
27 | 26 | { |
28 | 27 | $consulta = $this->_conexionBaseDeDatos->prepare($this->_query->query()); |
29 | 28 | |
30 | - if(!empty($this->_query->valores())) |
|
29 | + if (!empty($this->_query->valores())) |
|
31 | 30 | { |
32 | - $x=1; |
|
31 | + $x = 1; |
|
33 | 32 | foreach ($this->_query->valores() as $value) |
34 | 33 | { |
35 | - $consulta->bindValue($x,$value); |
|
34 | + $consulta->bindValue($x, $value); |
|
36 | 35 | $x++; |
37 | 36 | } |
38 | 37 | } |
@@ -43,7 +42,7 @@ discard block |
||
43 | 42 | $this->_ultimaIdInsertada = $this->_conexionBaseDeDatos->lastInsertId(); |
44 | 43 | |
45 | 44 | } |
46 | - catch(PDOException $e) |
|
45 | + catch (PDOException $e) |
|
47 | 46 | { |
48 | 47 | throw new ConsultaException("Error al procesar la consulta"); |
49 | 48 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | return $consulta->crear(array( |
44 | 44 | 'conexion' => $conexion->crear(array()), |
45 | 45 | 'sql' => $update->update(), |
46 | - 'valores' => $this->juntarValores($array['valores'],$donde->datos()) |
|
46 | + 'valores' => $this->juntarValores($array['valores'], $donde->datos()) |
|
47 | 47 | )); |
48 | 48 | } |
49 | 49 |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | private $_donde; |
15 | 15 | private $_valoresAInsertar; |
16 | 16 | |
17 | - public function __construct |
|
18 | - ( |
|
17 | + public function __construct( |
|
19 | 18 | Tabla $Tabla, |
20 | 19 | Donde $Donde, |
21 | 20 | ValoresAInsertar $ValoresAInsertar |
@@ -33,12 +32,12 @@ discard block |
||
33 | 32 | |
34 | 33 | foreach ($this->_valoresAInsertar->valoresAInsertar() as $key => $value) |
35 | 34 | { |
36 | - $set = $set. ' ' .$key. ' = ?,'; |
|
35 | + $set = $set.' '.$key.' = ?,'; |
|
37 | 36 | array_push($values, $value); |
38 | 37 | } |
39 | 38 | |
40 | 39 | $valores = trim($set, ','); |
41 | 40 | |
42 | - return "UPDATE " . $this->_tabla->tabla(). " SET ".$valores.$this->_donde->donde(); |
|
41 | + return "UPDATE ".$this->_tabla->tabla()." SET ".$valores.$this->_donde->donde(); |
|
43 | 42 | } |
44 | 43 | } |
45 | 44 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | declare(strict_types=1); |
8 | 8 | |
9 | -require_once __DIR__ . '/vendor/autoload.php'; |
|
9 | +require_once __DIR__.'/vendor/autoload.php'; |
|
10 | 10 | |
11 | 11 | use src\pdoDataBase\conexion\{ |
12 | 12 | BaseDeDatos, |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $prueba = new Consulta( |
98 | 98 | $conexion, |
99 | - new Query($sql->select(),$donde->datos()) |
|
99 | + new Query($sql->select(), $donde->datos()) |
|
100 | 100 | ); |
101 | 101 | echo '<h1>Obteniendo la consulta de un select</h1>'; |
102 | 102 | var_dump( |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | new Donde( |
166 | 166 | new MasDonde(array()), |
167 | 167 | array( |
168 | - 'id','=',1 |
|
168 | + 'id', '=', 1 |
|
169 | 169 | ) |
170 | 170 | ), |
171 | 171 | new ValoresAInsertar( |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | 'dos' => 102331 |
189 | 189 | ), |
190 | 190 | 'donde' => array( |
191 | - 'id','=',1 |
|
191 | + 'id', '=', 1 |
|
192 | 192 | ) |
193 | 193 | ) |
194 | 194 | ); |