@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @param array $data |
260 | 260 | */ |
261 | - function __construct($data=null) |
|
261 | + function __construct($data = null) |
|
262 | 262 | { |
263 | 263 | if (!$this->source) { |
264 | 264 | $this->_model_name(); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | |
279 | 279 | if ($data) { |
280 | 280 | if (!is_array($data)) $data = Util::getParams(func_get_args()); |
281 | - foreach($this->fields as $field) { |
|
281 | + foreach ($this->fields as $field) { |
|
282 | 282 | if (isset($data[$field])) { |
283 | 283 | $this->$field = $data[$field]; |
284 | 284 | } |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | } elseif (array_key_exists($mmodel, $this->_has_and_belongs_to_many)) { |
383 | 383 | $relation = $this->_has_and_belongs_to_many[$mmodel]; |
384 | 384 | $relation_model = self::get($relation->model); |
385 | - $source = ($this->schema ? "{$this->schema}." : NULL ) . $this->source; |
|
386 | - $relation_source = ($relation_model->schema ? "{$relation_model->schema}." : NULL ) . $relation_model->source; |
|
385 | + $source = ($this->schema ? "{$this->schema}." : NULL) . $this->source; |
|
386 | + $relation_source = ($relation_model->schema ? "{$relation_model->schema}." : NULL) . $relation_model->source; |
|
387 | 387 | /** |
388 | 388 | * Cargo atraves de que tabla se efectuara la relacion |
389 | 389 | * |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | } else { |
395 | 395 | $relation->through = "{$relation_source}_{$this->source}"; |
396 | 396 | } |
397 | - }else{ |
|
397 | + } else { |
|
398 | 398 | $through = explode('/', $relation->through); |
399 | 399 | $relation->through = end($through); |
400 | 400 | } |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * @param $key |
635 | 635 | * @return array |
636 | 636 | */ |
637 | - public function get_alias($key=null) |
|
637 | + public function get_alias($key = null) |
|
638 | 638 | { |
639 | 639 | if ($key && array_key_exists($key, $this->alias)) { |
640 | 640 | return $this->alias[$key]; |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | * @param string $key |
650 | 650 | * @param string $value |
651 | 651 | */ |
652 | - public function set_alias($key=null, $value=null) |
|
652 | + public function set_alias($key = null, $value = null) |
|
653 | 653 | { |
654 | 654 | if ($key && array_key_exists($key, $this->alias)) { |
655 | 655 | $this->alias[$key] = $value; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | */ |
686 | 686 | public function begin() |
687 | 687 | { |
688 | - $this->_connect();//(true); |
|
688 | + $this->_connect(); //(true); |
|
689 | 689 | return $this->db->begin(); |
690 | 690 | } |
691 | 691 | |
@@ -745,20 +745,20 @@ discard block |
||
745 | 745 | $what = Util::getParams(func_get_args()); |
746 | 746 | $select = "SELECT "; |
747 | 747 | if (isset($what['columns'])) { |
748 | - $select.= self::sql_sanitize($what['columns']); |
|
748 | + $select .= self::sql_sanitize($what['columns']); |
|
749 | 749 | } elseif (isset($what['distinct'])) { |
750 | - $select.= 'DISTINCT '; |
|
751 | - $select.= $what['distinct'] ? self::sql_sanitize($what['distinct']) : join(",", $this->fields); |
|
750 | + $select .= 'DISTINCT '; |
|
751 | + $select .= $what['distinct'] ? self::sql_sanitize($what['distinct']) : join(",", $this->fields); |
|
752 | 752 | } else { |
753 | - $select.= join(",", $this->fields); |
|
753 | + $select .= join(",", $this->fields); |
|
754 | 754 | } |
755 | 755 | if ($this->schema) { |
756 | - $select.= " FROM {$this->schema}.{$this->source}"; |
|
756 | + $select .= " FROM {$this->schema}.{$this->source}"; |
|
757 | 757 | } else { |
758 | - $select.= " FROM {$this->source}"; |
|
758 | + $select .= " FROM {$this->source}"; |
|
759 | 759 | } |
760 | 760 | $what['limit'] = 1; |
761 | - $select.= $this->convert_params_to_sql($what); |
|
761 | + $select .= $this->convert_params_to_sql($what); |
|
762 | 762 | $resp = false; |
763 | 763 | |
764 | 764 | $result = $this->db->fetch_one($select); |
@@ -789,19 +789,19 @@ discard block |
||
789 | 789 | $what = Util::getParams(func_get_args()); |
790 | 790 | $select = "SELECT "; |
791 | 791 | if (isset($what['columns'])) { |
792 | - $select.= $what['columns'] ? self::sql_sanitize($what['columns']) : join(",", $this->fields); |
|
792 | + $select .= $what['columns'] ? self::sql_sanitize($what['columns']) : join(",", $this->fields); |
|
793 | 793 | } elseif (isset($what['distinct'])) { |
794 | - $select.= 'DISTINCT '; |
|
795 | - $select.= $what['distinct'] ? self::sql_sanitize($what['distinct']) : join(",", $this->fields); |
|
794 | + $select .= 'DISTINCT '; |
|
795 | + $select .= $what['distinct'] ? self::sql_sanitize($what['distinct']) : join(",", $this->fields); |
|
796 | 796 | } else { |
797 | - $select.= join(",", $this->fields); |
|
797 | + $select .= join(",", $this->fields); |
|
798 | 798 | } |
799 | 799 | if ($this->schema) { |
800 | - $select.= " FROM {$this->schema}.{$this->source}"; |
|
800 | + $select .= " FROM {$this->schema}.{$this->source}"; |
|
801 | 801 | } else { |
802 | - $select.= " FROM {$this->source}"; |
|
802 | + $select .= " FROM {$this->source}"; |
|
803 | 803 | } |
804 | - $select.= $this->convert_params_to_sql($what); |
|
804 | + $select .= $this->convert_params_to_sql($what); |
|
805 | 805 | $results = array(); |
806 | 806 | $all_results = $this->db->in_query($select); |
807 | 807 | foreach ($all_results AS $result) { |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | self::sql_item_sanitize($this->primary_key[0]); |
846 | 846 | if (isset($what[0])) { |
847 | 847 | if (is_numeric($what[0])) { |
848 | - $what['conditions'] = "{$this->primary_key[0]} = ".(int)$what[0] ; |
|
848 | + $what['conditions'] = "{$this->primary_key[0]} = " . (int) $what[0]; |
|
849 | 849 | } else { |
850 | 850 | if ($what[0] == '') { |
851 | 851 | $what['conditions'] = "{$this->primary_key[0]} = ''"; |
@@ -856,27 +856,27 @@ discard block |
||
856 | 856 | } |
857 | 857 | } |
858 | 858 | if (isset($what['join'])) { |
859 | - $select.= " {$what['join']}"; |
|
859 | + $select .= " {$what['join']}"; |
|
860 | 860 | } |
861 | 861 | if (isset($what['conditions'])) { |
862 | - $select.= " WHERE {$what['conditions']}"; |
|
862 | + $select .= " WHERE {$what['conditions']}"; |
|
863 | 863 | } |
864 | 864 | if (isset($what['group'])) { |
865 | - $select.= " GROUP BY {$what['group']}"; |
|
865 | + $select .= " GROUP BY {$what['group']}"; |
|
866 | 866 | } |
867 | 867 | if (isset($what['having'])) { |
868 | - $select.= " HAVING {$what['having']}"; |
|
868 | + $select .= " HAVING {$what['having']}"; |
|
869 | 869 | } |
870 | 870 | if (isset($what['order'])) { |
871 | 871 | self::sql_sanitize($what['order']); |
872 | - $select.= " ORDER BY {$what['order']}"; |
|
872 | + $select .= " ORDER BY {$what['order']}"; |
|
873 | 873 | } |
874 | 874 | $limit_args = array($select); |
875 | 875 | if (isset($what['limit'])) { |
876 | - array_push($limit_args, "limit: ".(int)$what['limit']); |
|
876 | + array_push($limit_args, "limit: " . (int) $what['limit']); |
|
877 | 877 | } |
878 | 878 | if (isset($what['offset'])) { |
879 | - array_push($limit_args, "offset: ".(int)$what['offset']); |
|
879 | + array_push($limit_args, "offset: " . (int) $what['offset']); |
|
880 | 880 | } |
881 | 881 | if (count($limit_args) > 1) { |
882 | 882 | $select = call_user_func_array(array($this, 'limit'), $limit_args); |
@@ -884,9 +884,9 @@ discard block |
||
884 | 884 | } else { |
885 | 885 | if (strlen($what)) { |
886 | 886 | if (is_numeric($what)) { |
887 | - $select.= "WHERE {$this->primary_key[0]} = ".(int)$what[0] ; |
|
887 | + $select .= "WHERE {$this->primary_key[0]} = " . (int) $what[0]; |
|
888 | 888 | } else { |
889 | - $select.= "WHERE $what"; |
|
889 | + $select .= "WHERE $what"; |
|
890 | 890 | } |
891 | 891 | } |
892 | 892 | } |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | * Se elimina el de indice cero ya que por defecto convert_params_to_sql lo considera como una condicion en WHERE |
939 | 939 | */ |
940 | 940 | unset($what[0]); |
941 | - $select.= $this->convert_params_to_sql($what); |
|
941 | + $select .= $this->convert_params_to_sql($what); |
|
942 | 942 | $results = array(); |
943 | 943 | foreach ($this->db->fetch_all($select) as $result) { |
944 | 944 | $results[] = $result[0]; |
@@ -980,15 +980,15 @@ discard block |
||
980 | 980 | if (isset($what['distinct']) && $what['distinct']) { |
981 | 981 | if (isset($what['group'])) { |
982 | 982 | $select = "SELECT COUNT(*) FROM (SELECT DISTINCT {$what['distinct']} FROM $table "; |
983 | - $select.= $this->convert_params_to_sql($what); |
|
984 | - $select.= ') AS t '; |
|
983 | + $select .= $this->convert_params_to_sql($what); |
|
984 | + $select .= ') AS t '; |
|
985 | 985 | } else { |
986 | 986 | $select = "SELECT COUNT(DISTINCT {$what['distinct']}) FROM $table "; |
987 | - $select.= $this->convert_params_to_sql($what); |
|
987 | + $select .= $this->convert_params_to_sql($what); |
|
988 | 988 | } |
989 | 989 | } else { |
990 | 990 | $select = "SELECT COUNT(*) FROM $table "; |
991 | - $select.= $this->convert_params_to_sql($what); |
|
991 | + $select .= $this->convert_params_to_sql($what); |
|
992 | 992 | } |
993 | 993 | $num = $this->db->fetch_one($select); |
994 | 994 | return $num[0]; |
@@ -1018,7 +1018,7 @@ discard block |
||
1018 | 1018 | $table = $this->source; |
1019 | 1019 | } |
1020 | 1020 | $select = "SELECT AVG({$what['column']}) FROM $table "; |
1021 | - $select.= $this->convert_params_to_sql($what); |
|
1021 | + $select .= $this->convert_params_to_sql($what); |
|
1022 | 1022 | $num = $this->db->fetch_one($select); |
1023 | 1023 | return $num[0]; |
1024 | 1024 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | $table = $this->source; |
1042 | 1042 | } |
1043 | 1043 | $select = "SELECT SUM({$what['column']}) FROM $table "; |
1044 | - $select.= $this->convert_params_to_sql($what); |
|
1044 | + $select .= $this->convert_params_to_sql($what); |
|
1045 | 1045 | $num = $this->db->fetch_one($select); |
1046 | 1046 | return $num[0]; |
1047 | 1047 | } |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | $table = $this->source; |
1071 | 1071 | } |
1072 | 1072 | $select = "SELECT MAX({$what['column']}) FROM $table "; |
1073 | - $select.= $this->convert_params_to_sql($what); |
|
1073 | + $select .= $this->convert_params_to_sql($what); |
|
1074 | 1074 | $num = $this->db->fetch_one($select); |
1075 | 1075 | return $num[0]; |
1076 | 1076 | } |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $table = $this->source; |
1100 | 1100 | } |
1101 | 1101 | $select = "SELECT MIN({$what['column']}) FROM $table "; |
1102 | - $select.= $this->convert_params_to_sql($what); |
|
1102 | + $select .= $this->convert_params_to_sql($what); |
|
1103 | 1103 | $num = $this->db->fetch_one($select); |
1104 | 1104 | return $num[0]; |
1105 | 1105 | } |
@@ -1279,7 +1279,7 @@ discard block |
||
1279 | 1279 | * @param array $values array de valores a cargar |
1280 | 1280 | * @return boolean success |
1281 | 1281 | */ |
1282 | - public function save($values=null) |
|
1282 | + public function save($values = null) |
|
1283 | 1283 | { |
1284 | 1284 | if ($values) { |
1285 | 1285 | if (!is_array($values)) |
@@ -1644,7 +1644,7 @@ discard block |
||
1644 | 1644 | } |
1645 | 1645 | if (isset($this->$np)) { |
1646 | 1646 | $fields[] = $np; |
1647 | - if (is_null($this->$np) || $this->$np == '' && $this->$np!='0') { |
|
1647 | + if (is_null($this->$np) || $this->$np == '' && $this->$np != '0') { |
|
1648 | 1648 | $values[] = 'NULL'; |
1649 | 1649 | } else { |
1650 | 1650 | /** |
@@ -2006,7 +2006,7 @@ discard block |
||
2006 | 2006 | * message: mensaje a mostrar |
2007 | 2007 | * field: nombre de campo a mostrar en el mensaje |
2008 | 2008 | */ |
2009 | - protected function validates_presence_of($field, $params=array()) |
|
2009 | + protected function validates_presence_of($field, $params = array()) |
|
2010 | 2010 | { |
2011 | 2011 | if (is_string($params)) |
2012 | 2012 | $params = Util::getParams(func_get_args()); |
@@ -2027,7 +2027,7 @@ discard block |
||
2027 | 2027 | * too_long: mensaje a mostrar cuando sea muy largo |
2028 | 2028 | * field: nombre de campo a mostrar en el mensaje |
2029 | 2029 | */ |
2030 | - protected function validates_length_of($field, $max, $min=0, $params=array()) |
|
2030 | + protected function validates_length_of($field, $max, $min = 0, $params = array()) |
|
2031 | 2031 | { |
2032 | 2032 | if (is_string($params)) |
2033 | 2033 | $params = Util::getParams(func_get_args()); |
@@ -2047,7 +2047,7 @@ discard block |
||
2047 | 2047 | * message: mensaje a mostrar |
2048 | 2048 | * field: nombre del campo a mostrar en el mensaje |
2049 | 2049 | */ |
2050 | - protected function validates_inclusion_in($field, $list, $params=array()) |
|
2050 | + protected function validates_inclusion_in($field, $list, $params = array()) |
|
2051 | 2051 | { |
2052 | 2052 | if (is_string($params)) |
2053 | 2053 | $params = Util::getParams(func_get_args()); |
@@ -2066,7 +2066,7 @@ discard block |
||
2066 | 2066 | * message: mensaje a mostrar |
2067 | 2067 | * field: nombre del campo a mostrar en el mensaje |
2068 | 2068 | */ |
2069 | - protected function validates_exclusion_of($field, $list, $params=array()) |
|
2069 | + protected function validates_exclusion_of($field, $list, $params = array()) |
|
2070 | 2070 | { |
2071 | 2071 | if (is_string($params)) |
2072 | 2072 | $params = Util::getParams(func_get_args()); |
@@ -2085,7 +2085,7 @@ discard block |
||
2085 | 2085 | * message: mensaje a mostrar |
2086 | 2086 | * field: nombre del campo a mostrar en el mensaje |
2087 | 2087 | */ |
2088 | - protected function validates_format_of($field, $pattern, $params=array()) |
|
2088 | + protected function validates_format_of($field, $pattern, $params = array()) |
|
2089 | 2089 | { |
2090 | 2090 | if (is_string($params)) |
2091 | 2091 | $params = Util::getParams(func_get_args()); |
@@ -2103,7 +2103,7 @@ discard block |
||
2103 | 2103 | * message: mensaje a mostrar |
2104 | 2104 | * field: nombre del campo a mostrar en el mensaje |
2105 | 2105 | */ |
2106 | - protected function validates_numericality_of($field, $params=array()) |
|
2106 | + protected function validates_numericality_of($field, $params = array()) |
|
2107 | 2107 | { |
2108 | 2108 | if (is_string($params)) |
2109 | 2109 | $params = Util::getParams(func_get_args()); |
@@ -2120,7 +2120,7 @@ discard block |
||
2120 | 2120 | * message: mensaje a mostrar |
2121 | 2121 | * field: nombre del campo a mostrar en el mensaje |
2122 | 2122 | */ |
2123 | - protected function validates_email_in($field, $params=array()) |
|
2123 | + protected function validates_email_in($field, $params = array()) |
|
2124 | 2124 | { |
2125 | 2125 | if (is_string($params)) |
2126 | 2126 | $params = Util::getParams(func_get_args()); |
@@ -2137,7 +2137,7 @@ discard block |
||
2137 | 2137 | * message: mensaje a mostrar |
2138 | 2138 | * field: nombre del campo a mostrar en el mensaje |
2139 | 2139 | */ |
2140 | - protected function validates_uniqueness_of($field, $params=array()) |
|
2140 | + protected function validates_uniqueness_of($field, $params = array()) |
|
2141 | 2141 | { |
2142 | 2142 | if (is_string($params)) |
2143 | 2143 | $params = Util::getParams(func_get_args()); |
@@ -2154,7 +2154,7 @@ discard block |
||
2154 | 2154 | * message: mensaje a mostrar |
2155 | 2155 | * field: nombre del campo a mostrar en el mensaje |
2156 | 2156 | */ |
2157 | - protected function validates_date_in($field, $params=array()) |
|
2157 | + protected function validates_date_in($field, $params = array()) |
|
2158 | 2158 | { |
2159 | 2159 | if (is_string($params)) |
2160 | 2160 | $params = Util::getParams(func_get_args()); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | if ($page_number < 1 && $per_page < 1) { |
80 | 80 | throw new KumbiaException("La página $page_number no existe en el páginador"); |
81 | 81 | } |
82 | - $start = $per_page * ($page_number - 1); |
|
82 | + $start = $per_page*($page_number - 1); |
|
83 | 83 | //Instancia del objeto contenedor de página |
84 | 84 | $page = new stdClass(); |
85 | 85 | //Si es un array, se hace páginacion de array |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $page->next = ($start + $per_page) < $n ? ($page_number + 1) : false; |
141 | 141 | $page->prev = ($page_number > 1) ? ($page_number - 1) : false; |
142 | 142 | $page->current = $page_number; |
143 | - $page->total = ceil($n / $per_page); |
|
143 | + $page->total = ceil($n/$per_page); |
|
144 | 144 | $page->count = $n; |
145 | 145 | $page->per_page = $per_page; |
146 | 146 | return $page; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | if ($page_number < 1 || $per_page < 1) { |
179 | 179 | throw new KumbiaException("La página $page_number no existe en el páginador"); |
180 | 180 | } |
181 | - $start = $per_page * ($page_number - 1); |
|
181 | + $start = $per_page*($page_number - 1); |
|
182 | 182 | //Instancia del objeto contenedor de página |
183 | 183 | $page = new stdClass(); |
184 | 184 | //Cuento las apariciones atraves de una tabla derivada |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $page->next = ($start + $per_page) < $n ? ($page_number + 1) : false; |
194 | 194 | $page->prev = ($page_number > 1) ? ($page_number - 1) : false; |
195 | 195 | $page->current = $page_number; |
196 | - $page->total = ceil($n / $per_page); |
|
196 | + $page->total = ceil($n/$per_page); |
|
197 | 197 | $page->count = $n; |
198 | 198 | $page->per_page = $per_page; |
199 | 199 | return $page; |
@@ -85,7 +85,7 @@ |
||
85 | 85 | $dbclass = "DbPdo{$config['type']}"; |
86 | 86 | $db_file = "$path/adapters/pdo/{$config['type']}.php"; |
87 | 87 | } else { |
88 | - if($config['type'] == 'mysql') $config['type'] = 'mysqli'; |
|
88 | + if ($config['type'] == 'mysql') $config['type'] = 'mysqli'; |
|
89 | 89 | $dbclass = "Db{$config['type']}"; |
90 | 90 | $db_file = "$path/adapters/{$config['type']}.php"; |
91 | 91 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | $this->id_connection = new mysqli($config['host'], $config['username'], $config['password'], $config['name'], $config['port']); |
123 | 123 | //no se usa $object->error() ya que solo funciona a partir de 5.2.9 y 5.3 |
124 | - if (mysqli_connect_error ()) throw new KumbiaException(mysqli_connect_error()); |
|
124 | + if (mysqli_connect_error()) throw new KumbiaException(mysqli_connect_error()); |
|
125 | 125 | //Selecciona charset |
126 | 126 | if (isset($config['charset'])) $this->id_connection->set_charset($config['charset']); |
127 | 127 | return TRUE; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param int $opt |
169 | 169 | * @return array |
170 | 170 | */ |
171 | - public function fetch_array($result_query='', $opt=MYSQLI_BOTH) |
|
171 | + public function fetch_array($result_query = '', $opt = MYSQLI_BOTH) |
|
172 | 172 | { |
173 | 173 | if (!$result_query) { |
174 | 174 | $result_query = $this->last_result_query; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * Devuelve el numero de filas de un select |
194 | 194 | */ |
195 | - public function num_rows($result_query='') |
|
195 | + public function num_rows($result_query = '') |
|
196 | 196 | { |
197 | 197 | if (!$result_query) { |
198 | 198 | $result_query = $this->last_result_query; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param resource $result_query |
215 | 215 | * @return string |
216 | 216 | */ |
217 | - public function field_name($number, $result_query='') |
|
217 | + public function field_name($number, $result_query = '') |
|
218 | 218 | { |
219 | 219 | |
220 | 220 | if (!$result_query) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param resource $result_query |
239 | 239 | * @return boolean |
240 | 240 | */ |
241 | - public function data_seek($number, $result_query='') |
|
241 | + public function data_seek($number, $result_query = '') |
|
242 | 242 | { |
243 | 243 | if (!$result_query) { |
244 | 244 | $result_query = $this->last_result_query; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param resource $result_query |
260 | 260 | * @return int |
261 | 261 | */ |
262 | - public function affected_rows($result_query='') |
|
262 | + public function affected_rows($result_query = '') |
|
263 | 263 | { |
264 | 264 | if (($numberRows = mysqli_affected_rows($this->id_connection)) !== false) { |
265 | 265 | return $numberRows; |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public function error($err='') |
|
276 | + public function error($err = '') |
|
277 | 277 | { |
278 | 278 | $this->last_error = mysqli_error($this->id_connection) ? mysqli_error($this->id_connection) : "[Error Desconocido en MySQL: $err]"; |
279 | - $this->last_error.= $err; |
|
279 | + $this->last_error .= $err; |
|
280 | 280 | if ($this->logger) { |
281 | 281 | Logger::error($this->last_error); |
282 | 282 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return int |
300 | 300 | */ |
301 | - public function last_insert_id($table='', $primary_key='') |
|
301 | + public function last_insert_id($table = '', $primary_key = '') |
|
302 | 302 | { |
303 | 303 | return mysqli_insert_id($this->id_connection); |
304 | 304 | } |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @param string $table |
310 | 310 | * @return boolean |
311 | 311 | */ |
312 | - public function table_exists($table, $schema='') |
|
312 | + public function table_exists($table, $schema = '') |
|
313 | 313 | { |
314 | 314 | $table = addslashes("$table"); |
315 | 315 | if ($schema == '') { |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | $sql_new = $sql; |
334 | 334 | |
335 | 335 | if (isset($params['limit']) && is_numeric($params['limit'])) { |
336 | - $sql_new.=" LIMIT $params[limit]"; |
|
336 | + $sql_new .= " LIMIT $params[limit]"; |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | if (isset($params['offset']) && is_numeric($params['offset'])) { |
340 | - $sql_new.=" OFFSET $params[offset]"; |
|
340 | + $sql_new .= " OFFSET $params[offset]"; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return $sql_new; |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @param string $table |
350 | 350 | * @return resource |
351 | 351 | */ |
352 | - public function drop_table($table, $if_exists=true) |
|
352 | + public function drop_table($table, $if_exists = true) |
|
353 | 353 | { |
354 | 354 | if ($if_exists) { |
355 | 355 | return $this->query("DROP TABLE IF EXISTS $table"); |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param array $definition |
372 | 372 | * @return resource |
373 | 373 | */ |
374 | - public function create_table($table, $definition, $index=array()) |
|
374 | + public function create_table($table, $definition, $index = array()) |
|
375 | 375 | { |
376 | 376 | $create_sql = "CREATE TABLE $table ("; |
377 | 377 | if (!is_array($definition)) { |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | } |
422 | 422 | $create_lines[] = "`$field` " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra; |
423 | 423 | } |
424 | - $create_sql.= join(',', $create_lines); |
|
424 | + $create_sql .= join(',', $create_lines); |
|
425 | 425 | $last_lines = array(); |
426 | 426 | if (count($primary)) { |
427 | 427 | $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')'; |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | $last_lines[] = join(',', $unique_index); |
434 | 434 | } |
435 | 435 | if (count($last_lines)) { |
436 | - $create_sql.= ',' . join(',', $last_lines) . ')'; |
|
436 | + $create_sql .= ',' . join(',', $last_lines) . ')'; |
|
437 | 437 | } |
438 | 438 | return $this->query($create_sql); |
439 | 439 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param string $table |
455 | 455 | * @return array |
456 | 456 | */ |
457 | - public function describe_table($table, $schema='') |
|
457 | + public function describe_table($table, $schema = '') |
|
458 | 458 | { |
459 | 459 | if ($schema == '') { |
460 | 460 | return $this->fetch_all("DESCRIBE `$table`"); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param int $opt |
197 | 197 | * @return array |
198 | 198 | */ |
199 | - public function fetch_array($pdo_statement=NULL, $opt='') |
|
199 | + public function fetch_array($pdo_statement = NULL, $opt = '') |
|
200 | 200 | { |
201 | 201 | if ($opt === '') { |
202 | 202 | $opt = self::DB_BOTH; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @deprecated |
236 | 236 | * @return int |
237 | 237 | */ |
238 | - public function num_rows($pdo_statement='') |
|
238 | + public function num_rows($pdo_statement = '') |
|
239 | 239 | { |
240 | 240 | if ($pdo_statement) { |
241 | 241 | $pdo = clone $pdo_statement; |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param resource $pdo_statement |
253 | 253 | * @return string |
254 | 254 | */ |
255 | - public function field_name($number, $pdo_statement=NULL) |
|
255 | + public function field_name($number, $pdo_statement = NULL) |
|
256 | 256 | { |
257 | 257 | if (!$this->pdo) { |
258 | 258 | throw new KumbiaException('No hay conexión para realizar esta acción'); |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param PDOStatement $pdo_statement |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public function data_seek($number, $pdo_statement=NULL) |
|
281 | + public function data_seek($number, $pdo_statement = NULL) |
|
282 | 282 | { |
283 | 283 | return false; |
284 | 284 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @deprecated |
291 | 291 | * @return int |
292 | 292 | */ |
293 | - public function affected_rows($pdo_statement=NULL) |
|
293 | + public function affected_rows($pdo_statement = NULL) |
|
294 | 294 | { |
295 | 295 | if (!$this->pdo) { |
296 | 296 | throw new KumbiaException('No hay conexión para realizar esta acción'); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * |
316 | 316 | * @return string |
317 | 317 | */ |
318 | - public function error($err='') |
|
318 | + public function error($err = '') |
|
319 | 319 | { |
320 | 320 | if ($this->pdo) { |
321 | 321 | $error = $this->pdo->errorInfo(); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | } else { |
324 | 324 | $error = ""; |
325 | 325 | } |
326 | - $this->last_error.= $error . " [" . $err . "]"; |
|
326 | + $this->last_error .= $error . " [" . $err . "]"; |
|
327 | 327 | if ($this->logger) { |
328 | 328 | Logger::error($this->last_error); |
329 | 329 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return int |
337 | 337 | */ |
338 | - public function no_error($number=0) |
|
338 | + public function no_error($number = 0) |
|
339 | 339 | { |
340 | 340 | if ($this->pdo) { |
341 | 341 | $error = $this->pdo->errorInfo(); |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - public function last_insert_id($table='', $primary_key='') |
|
352 | + public function last_insert_id($table = '', $primary_key = '') |
|
353 | 353 | { |
354 | 354 | return $this->pdo->lastInsertId(); |
355 | 355 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @param array $fields |
400 | 400 | * @return integer |
401 | 401 | */ |
402 | - public function insert($table, $values, $fields=null) |
|
402 | + public function insert($table, $values, $fields = null) |
|
403 | 403 | { |
404 | 404 | //$insert_sql = ""; |
405 | 405 | if (is_array($values)) { |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param string $where_condition |
427 | 427 | * @return integer |
428 | 428 | */ |
429 | - public function update($table, $fields, $values, $where_condition=null) |
|
429 | + public function update($table, $fields, $values, $where_condition = null) |
|
430 | 430 | { |
431 | 431 | $update_sql = "UPDATE $table SET "; |
432 | 432 | if (count($fields) != count($values)) { |
@@ -438,9 +438,9 @@ discard block |
||
438 | 438 | $update_values[] = $field . ' = ' . $values[$i]; |
439 | 439 | $i++; |
440 | 440 | } |
441 | - $update_sql.= join(',', $update_values); |
|
441 | + $update_sql .= join(',', $update_values); |
|
442 | 442 | if ($where_condition != null) { |
443 | - $update_sql.= " WHERE $where_condition"; |
|
443 | + $update_sql .= " WHERE $where_condition"; |
|
444 | 444 | } |
445 | 445 | return $this->exec($update_sql); |
446 | 446 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param int $opt |
196 | 196 | * @return array |
197 | 197 | */ |
198 | - function fetch_array($resultQuery=NULL, $opt=OCI_BOTH) |
|
198 | + function fetch_array($resultQuery = NULL, $opt = OCI_BOTH) |
|
199 | 199 | { |
200 | 200 | |
201 | 201 | if (!$resultQuery) { |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | /** |
229 | 229 | * Devuelve el numero de filas de un select |
230 | 230 | */ |
231 | - function num_rows($resultQuery=NULL) |
|
231 | + function num_rows($resultQuery = NULL) |
|
232 | 232 | { |
233 | 233 | |
234 | 234 | if (!$resultQuery) { |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param resource $resultQuery |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - function field_name($number, $resultQuery=NULL) |
|
270 | + function field_name($number, $resultQuery = NULL) |
|
271 | 271 | { |
272 | 272 | |
273 | 273 | if (!$resultQuery) { |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param resource $resultQuery |
292 | 292 | * @return boolean |
293 | 293 | */ |
294 | - function data_seek($number, $resultQuery=NULL) |
|
294 | + function data_seek($number, $resultQuery = NULL) |
|
295 | 295 | { |
296 | 296 | if (!$resultQuery) { |
297 | 297 | $resultQuery = $this->last_result_query; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param resource $resultQuery |
326 | 326 | * @return int |
327 | 327 | */ |
328 | - function affected_rows($resultQuery=NULL) |
|
328 | + function affected_rows($resultQuery = NULL) |
|
329 | 329 | { |
330 | 330 | |
331 | 331 | if (!$resultQuery) { |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - function error($err='') |
|
349 | + function error($err = '') |
|
350 | 350 | { |
351 | 351 | if (!$this->id_connection) { |
352 | 352 | $error = oci_error() ? oci_error() : "[Error Desconocido en Oracle]"; |
353 | 353 | if (is_array($error)) { |
354 | - $error['message'].=" > $err "; |
|
354 | + $error['message'] .= " > $err "; |
|
355 | 355 | return $error['message']; |
356 | 356 | } else { |
357 | 357 | //$error.=" $php_errormsg "; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | } |
361 | 361 | $error = oci_error($this->id_connection); |
362 | 362 | if ($error) { |
363 | - $error['message'].=" > $err "; |
|
363 | + $error['message'] .= " > $err "; |
|
364 | 364 | } else { |
365 | 365 | $error['message'] = $err; |
366 | 366 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @param string $table |
419 | 419 | * @return boolean |
420 | 420 | */ |
421 | - public function drop_table($table, $if_exists=true) |
|
421 | + public function drop_table($table, $if_exists = true) |
|
422 | 422 | { |
423 | 423 | if ($if_exists) { |
424 | 424 | if ($this->table_exists($table)) { |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * @param array $definition |
445 | 445 | * @return resource |
446 | 446 | */ |
447 | - public function create_table($table, $definition, $index=array()) |
|
447 | + public function create_table($table, $definition, $index = array()) |
|
448 | 448 | { |
449 | 449 | $create_sql = "CREATE TABLE $table ("; |
450 | 450 | if (!is_array($definition)) { |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | } |
495 | 495 | $create_lines[] = "$field " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra; |
496 | 496 | } |
497 | - $create_sql.= join(',', $create_lines); |
|
497 | + $create_sql .= join(',', $create_lines); |
|
498 | 498 | $last_lines = array(); |
499 | 499 | if (count($primary)) { |
500 | 500 | $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')'; |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $last_lines[] = join(',', $unique_index); |
507 | 507 | } |
508 | 508 | if (count($last_lines)) { |
509 | - $create_sql.= ',' . join(',', $last_lines) . ')'; |
|
509 | + $create_sql .= ',' . join(',', $last_lines) . ')'; |
|
510 | 510 | } |
511 | 511 | return $this->query($create_sql); |
512 | 512 | } |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * |
527 | 527 | * @return int |
528 | 528 | */ |
529 | - public function last_insert_id($table='', $primary_key='') |
|
529 | + public function last_insert_id($table = '', $primary_key = '') |
|
530 | 530 | { |
531 | 531 | if (!$this->id_connection) { |
532 | 532 | return false; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | * @param string $table |
549 | 549 | * @return boolean |
550 | 550 | */ |
551 | - function table_exists($table, $schema='') |
|
551 | + function table_exists($table, $schema = '') |
|
552 | 552 | { |
553 | 553 | $num = $this->fetch_one("SELECT COUNT(*) FROM ALL_TABLES WHERE TABLE_NAME = '" . strtoupper($table) . "'"); |
554 | 554 | return $num[0]; |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @param string $table |
561 | 561 | * @return array |
562 | 562 | */ |
563 | - public function describe_table($table, $schema='') |
|
563 | + public function describe_table($table, $schema = '') |
|
564 | 564 | { |
565 | 565 | /** |
566 | 566 | * Soporta schemas? |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @package Db |
27 | 27 | * @subpackage Adapters |
28 | 28 | */ |
29 | -class DbMsSQL extends DbBase implements DbBaseInterface { |
|
29 | +class DbMsSQL extends DbBase implements DbBaseInterface { |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Resource de la Conexión a MsSQL |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | * @param array $config |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public function connect($config){ |
|
120 | - if(!extension_loaded('mssql')){ |
|
119 | + public function connect($config) { |
|
120 | + if (!extension_loaded('mssql')) { |
|
121 | 121 | throw new KumbiaException('Debe cargar la extensión de PHP llamada php_mssql'); |
122 | 122 | } |
123 | - if(!isset($config['port']) || !$config['port']) { |
|
123 | + if (!isset($config['port']) || !$config['port']) { |
|
124 | 124 | $config['port'] = 1433; |
125 | 125 | } |
126 | 126 | //if($this->id_connection = mssql_connect("{$config['host']},{$config['port']}", $config['username'], $config['password'], true)){ |
127 | - if($this->id_connection = mssql_connect($config['host'], $config['username'], $config['password'], true)){ |
|
128 | - if($config['name']!=='') { |
|
129 | - if(!mssql_select_db($config['name'], $this->id_connection)){ |
|
127 | + if ($this->id_connection = mssql_connect($config['host'], $config['username'], $config['password'], true)) { |
|
128 | + if ($config['name'] !== '') { |
|
129 | + if (!mssql_select_db($config['name'], $this->id_connection)) { |
|
130 | 130 | throw new KumbiaException($this->error()); |
131 | 131 | } |
132 | 132 | } |
@@ -141,25 +141,25 @@ discard block |
||
141 | 141 | * @param string $sql_query |
142 | 142 | * @return resource or false |
143 | 143 | */ |
144 | - public function query($sql_query){ |
|
144 | + public function query($sql_query) { |
|
145 | 145 | $this->debug($sql_query); |
146 | - if($this->logger){ |
|
146 | + if ($this->logger) { |
|
147 | 147 | Logger::debug($sql_query); |
148 | 148 | } |
149 | 149 | |
150 | 150 | $this->last_query = $sql_query; |
151 | - if($result_query = mssql_query($sql_query, $this->id_connection)){ |
|
151 | + if ($result_query = mssql_query($sql_query, $this->id_connection)) { |
|
152 | 152 | $this->last_result_query = $result_query; |
153 | 153 | return $result_query; |
154 | - }else{ |
|
154 | + } else { |
|
155 | 155 | throw new KumbiaException($this->error(" al ejecutar <em>\"$sql_query\"</em>")); |
156 | 156 | } |
157 | 157 | } |
158 | 158 | /** |
159 | 159 | * Cierra la Conexión al Motor de Base de datos |
160 | 160 | */ |
161 | - public function close(){ |
|
162 | - if($this->id_connection) { |
|
161 | + public function close() { |
|
162 | + if ($this->id_connection) { |
|
163 | 163 | return mssql_close(); |
164 | 164 | } |
165 | 165 | return false; |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param int $opt |
172 | 172 | * @return array |
173 | 173 | */ |
174 | - public function fetch_array($result_query='', $opt=MSSQL_BOTH){ |
|
174 | + public function fetch_array($result_query = '', $opt = MSSQL_BOTH) { |
|
175 | 175 | |
176 | - if(!$result_query){ |
|
176 | + if (!$result_query) { |
|
177 | 177 | $result_query = $this->last_result_query; |
178 | - if(!$result_query){ |
|
178 | + if (!$result_query) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | } |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @param array $config |
188 | 188 | */ |
189 | - public function __construct($config){ |
|
189 | + public function __construct($config) { |
|
190 | 190 | $this->connect($config); |
191 | 191 | } |
192 | 192 | /** |
193 | 193 | * Devuelve el número de filas de un select |
194 | 194 | */ |
195 | - public function num_rows($result_query=''){ |
|
195 | + public function num_rows($result_query = '') { |
|
196 | 196 | |
197 | - if(!$result_query){ |
|
197 | + if (!$result_query) { |
|
198 | 198 | $result_query = $this->last_result_query; |
199 | - if(!$result_query){ |
|
199 | + if (!$result_query) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | } |
203 | - if(($number_rows = mssql_num_rows($result_query))!==false){ |
|
203 | + if (($number_rows = mssql_num_rows($result_query)) !== false) { |
|
204 | 204 | return $number_rows; |
205 | 205 | } else { |
206 | 206 | throw new KumbiaException($this->error()); |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | * @param resource $result_query |
215 | 215 | * @return string |
216 | 216 | */ |
217 | - public function field_name($number, $result_query=''){ |
|
217 | + public function field_name($number, $result_query = '') { |
|
218 | 218 | |
219 | - if(!$result_query){ |
|
219 | + if (!$result_query) { |
|
220 | 220 | $result_query = $this->last_result_query; |
221 | - if(!$result_query){ |
|
221 | + if (!$result_query) { |
|
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | } |
225 | - if(($fieldName = mssql_field_name($result_query, $number))!==false){ |
|
225 | + if (($fieldName = mssql_field_name($result_query, $number)) !== false) { |
|
226 | 226 | return $fieldName; |
227 | 227 | } else { |
228 | 228 | throw new KumbiaException($this->error()); |
@@ -235,14 +235,14 @@ discard block |
||
235 | 235 | * @param resource $result_query |
236 | 236 | * @return boolean |
237 | 237 | */ |
238 | - public function data_seek($number, $result_query=''){ |
|
239 | - if(!$result_query){ |
|
238 | + public function data_seek($number, $result_query = '') { |
|
239 | + if (!$result_query) { |
|
240 | 240 | $result_query = $this->last_result_query; |
241 | - if(!$result_query){ |
|
241 | + if (!$result_query) { |
|
242 | 242 | return false; |
243 | 243 | } |
244 | 244 | } |
245 | - if(($success = mssql_data_seek($result_query, $number))!==false){ |
|
245 | + if (($success = mssql_data_seek($result_query, $number)) !== false) { |
|
246 | 246 | return $success; |
247 | 247 | } else { |
248 | 248 | throw new KumbiaException($this->error()); |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param resource $result_query |
256 | 256 | * @return int |
257 | 257 | */ |
258 | - public function affected_rows($result_query=''){ |
|
259 | - if(($numberRows = mssql_affected_rows())!==false){ |
|
258 | + public function affected_rows($result_query = '') { |
|
259 | + if (($numberRows = mssql_affected_rows()) !== false) { |
|
260 | 260 | return $numberRows; |
261 | 261 | } else { |
262 | 262 | throw new KumbiaException($this->error()); |
@@ -268,17 +268,17 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return string |
270 | 270 | */ |
271 | - public function error($err=''){ |
|
272 | - if(!$this->id_connection){ |
|
271 | + public function error($err = '') { |
|
272 | + if (!$this->id_connection) { |
|
273 | 273 | $this->last_error = mssql_get_last_message() ? mssql_get_last_message() : "[Error Desconocido en MsSQL: $err]"; |
274 | - if($this->logger){ |
|
274 | + if ($this->logger) { |
|
275 | 275 | Logger::error($this->last_error); |
276 | 276 | } |
277 | 277 | return $this->last_error; |
278 | 278 | } |
279 | 279 | $this->last_error = mssql_get_last_message() ? mssql_get_last_message() : "[Error Desconocido en MsSQL: $err]"; |
280 | - $this->last_error.= $err; |
|
281 | - if($this->logger){ |
|
280 | + $this->last_error .= $err; |
|
281 | + if ($this->logger) { |
|
282 | 282 | Logger::error($this->last_error); |
283 | 283 | } |
284 | 284 | return $this->last_error; |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return int |
290 | 290 | */ |
291 | - public function no_error(){ |
|
291 | + public function no_error() { |
|
292 | 292 | return mssql_errno(); |
293 | 293 | } |
294 | 294 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return int |
298 | 298 | */ |
299 | - public function last_insert_id($table='', $primary_key=''){ |
|
299 | + public function last_insert_id($table = '', $primary_key = '') { |
|
300 | 300 | |
301 | 301 | //$id = false; |
302 | 302 | $result = mssql_query("select max({$primary_key}) from $table"); |
@@ -312,9 +312,9 @@ discard block |
||
312 | 312 | * @param string $table |
313 | 313 | * @return boolean |
314 | 314 | */ |
315 | - public function table_exists($table, $schema=''){ |
|
315 | + public function table_exists($table, $schema = '') { |
|
316 | 316 | $table = addslashes("$table"); |
317 | - if($schema==''){ |
|
317 | + if ($schema == '') { |
|
318 | 318 | $num = $this->fetch_one("SELECT COUNT(*) FROM |
319 | 319 | INFORMATION_SCHEMA.TABLES |
320 | 320 | WHERE TABLE_NAME = '$table'"); |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | * @param string $sql consulta sql |
334 | 334 | * @return string |
335 | 335 | */ |
336 | - public function limit($sql){ |
|
336 | + public function limit($sql) { |
|
337 | 337 | $params = Util::getParams(func_get_args()); |
338 | 338 | |
339 | 339 | //TODO: añadirle el offset |
340 | - if(isset($params['limit'])){ |
|
340 | + if (isset($params['limit'])) { |
|
341 | 341 | $sql = str_ireplace("SELECT ", "SELECT TOP $params[limit] ", $sql); |
342 | 342 | } |
343 | 343 | return $sql; |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | * @param string $table |
350 | 350 | * @return resource |
351 | 351 | */ |
352 | - public function drop_table($table, $if_exists=true){ |
|
353 | - if($if_exists){ |
|
352 | + public function drop_table($table, $if_exists = true) { |
|
353 | + if ($if_exists) { |
|
354 | 354 | $sql = "IF EXISTS(SELECT TABLE_NAME FROM |
355 | 355 | INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '$table') |
356 | 356 | DROP TABLE $table;"; |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * |
365 | 365 | * @return array |
366 | 366 | */ |
367 | - public function list_tables(){ |
|
367 | + public function list_tables() { |
|
368 | 368 | return $this->fetch_all("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"); |
369 | 369 | } |
370 | 370 | |
@@ -388,20 +388,20 @@ discard block |
||
388 | 388 | return $this->fetch_all($sql); |
389 | 389 | } |
390 | 390 | */ |
391 | - public function describe_table($table, $schema=''){ |
|
391 | + public function describe_table($table, $schema = '') { |
|
392 | 392 | $describeTable = $this->fetch_all("exec sp_columns @table_name = '$table'"); |
393 | 393 | $finalDescribe = array(); |
394 | - foreach($describeTable as $field){ |
|
394 | + foreach ($describeTable as $field) { |
|
395 | 395 | $finalDescribe[] = array( |
396 | 396 | 'Field' => $field['COLUMN_NAME'], |
397 | - 'Type' => $field['LENGTH'] ? $field['TYPE_NAME'] : $field['TYPE_NAME'].'('.$field['LENGTH'].')', |
|
397 | + 'Type' => $field['LENGTH'] ? $field['TYPE_NAME'] : $field['TYPE_NAME'] . '(' . $field['LENGTH'] . ')', |
|
398 | 398 | 'Null' => $field['NULLABLE'] == 1 ? 'YES' : 'NO' |
399 | 399 | ); |
400 | 400 | } |
401 | 401 | $describeKeys = $this->fetch_all("exec sp_pkeys @table_name = '$table'"); |
402 | - foreach($describeKeys as $field){ |
|
403 | - for($i=0;$i<=count($finalDescribe)-1;++$i){ |
|
404 | - if($finalDescribe[$i]['Field']==$field['COLUMN_NAME']){ |
|
402 | + foreach ($describeKeys as $field) { |
|
403 | + for ($i = 0; $i <= count($finalDescribe) - 1; ++$i) { |
|
404 | + if ($finalDescribe[$i]['Field'] == $field['COLUMN_NAME']) { |
|
405 | 405 | $finalDescribe[$i]['Key'] = 'PRI'; |
406 | 406 | } else { |
407 | 407 | $finalDescribe[$i]['Key'] = ""; |
@@ -418,14 +418,14 @@ discard block |
||
418 | 418 | * @param resource $result_query |
419 | 419 | * @return object |
420 | 420 | */ |
421 | - public function fetch_object($result_query = NULL){ |
|
422 | - if(!$result_query){ |
|
421 | + public function fetch_object($result_query = NULL) { |
|
422 | + if (!$result_query) { |
|
423 | 423 | $result_query = $this->last_result_query; |
424 | 424 | } |
425 | 425 | return mssql_fetch_object($result_query); |
426 | 426 | } |
427 | 427 | |
428 | - public function create_table ($table, $definition, $index = array()){ |
|
428 | + public function create_table($table, $definition, $index = array()) { |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param int $opt |
175 | 175 | * @return array |
176 | 176 | */ |
177 | - function fetch_array($resultQuery=NULL, $opt=PGSQL_BOTH) |
|
177 | + function fetch_array($resultQuery = NULL, $opt = PGSQL_BOTH) |
|
178 | 178 | { |
179 | 179 | |
180 | 180 | if (!$resultQuery) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | /** |
200 | 200 | * Devuelve el numero de filas de un select |
201 | 201 | */ |
202 | - function num_rows($resultQuery=NULL) |
|
202 | + function num_rows($resultQuery = NULL) |
|
203 | 203 | { |
204 | 204 | |
205 | 205 | if (!$resultQuery) { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @param resource $resultQuery |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - function field_name($number, $resultQuery=NULL) |
|
225 | + function field_name($number, $resultQuery = NULL) |
|
226 | 226 | { |
227 | 227 | |
228 | 228 | if (!$resultQuery) { |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param resource $resultQuery |
246 | 246 | * @return boolean |
247 | 247 | */ |
248 | - function data_seek($number, $resultQuery=NULL) |
|
248 | + function data_seek($number, $resultQuery = NULL) |
|
249 | 249 | { |
250 | 250 | if (!$resultQuery) { |
251 | 251 | $resultQuery = $this->last_result_query; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param resource $resultQuery |
267 | 267 | * @return int |
268 | 268 | */ |
269 | - function affected_rows($resultQuery=NULL) |
|
269 | + function affected_rows($resultQuery = NULL) |
|
270 | 270 | { |
271 | 271 | |
272 | 272 | if (!$resultQuery) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return string |
289 | 289 | */ |
290 | - function error($err='') |
|
290 | + function error($err = '') |
|
291 | 291 | { |
292 | 292 | if (!$this->id_connection) { |
293 | 293 | $this->last_error = @pg_last_error() ? @pg_last_error() . $err : "[Error Desconocido en PostgreSQL \"$err\"]"; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | return $this->last_error; |
298 | 298 | } |
299 | 299 | $this->last_error = @pg_last_error() ? @pg_last_error() . $err : "[Error Desconocido en PostgreSQL: $err]"; |
300 | - $this->last_error.= $err; |
|
300 | + $this->last_error .= $err; |
|
301 | 301 | if ($this->logger) { |
302 | 302 | Logger::error($this->last_error); |
303 | 303 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return int |
322 | 322 | */ |
323 | - public function last_insert_id($table='', $primary_key='') |
|
323 | + public function last_insert_id($table = '', $primary_key = '') |
|
324 | 324 | { |
325 | 325 | |
326 | 326 | $last_id = $this->fetch_one("SELECT CURRVAL('{$table}_{$primary_key}_seq')"); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @param string $table |
334 | 334 | * @return boolean |
335 | 335 | */ |
336 | - function table_exists($table, $schema='') |
|
336 | + function table_exists($table, $schema = '') |
|
337 | 337 | { |
338 | 338 | $table = addslashes(strtolower($table)); |
339 | 339 | if (strpos($table, ".")) { |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | $sql_new = $sql; |
361 | 361 | |
362 | 362 | if (isset($params['limit']) && is_numeric($params['limit'])) { |
363 | - $sql_new.=" LIMIT $params[limit]"; |
|
363 | + $sql_new .= " LIMIT $params[limit]"; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | if (isset($params['offset']) && is_numeric($params['offset'])) { |
367 | - $sql_new.=" OFFSET $params[offset]"; |
|
367 | + $sql_new .= " OFFSET $params[offset]"; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | return $sql_new; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | * @param string $table |
377 | 377 | * @return boolean |
378 | 378 | */ |
379 | - public function drop_table($table, $if_exists=true) |
|
379 | + public function drop_table($table, $if_exists = true) |
|
380 | 380 | { |
381 | 381 | if ($if_exists) { |
382 | 382 | if ($this->table_exists($table)) { |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @param array $definition |
403 | 403 | * @return resource |
404 | 404 | */ |
405 | - public function create_table($table, $definition, $index=array()) |
|
405 | + public function create_table($table, $definition, $index = array()) |
|
406 | 406 | { |
407 | 407 | $create_sql = "CREATE TABLE $table ("; |
408 | 408 | if (!is_array($definition)) { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | } |
453 | 453 | $create_lines[] = "$field " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra; |
454 | 454 | } |
455 | - $create_sql.= join(',', $create_lines); |
|
455 | + $create_sql .= join(',', $create_lines); |
|
456 | 456 | $last_lines = array(); |
457 | 457 | if (count($primary)) { |
458 | 458 | $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')'; |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $last_lines[] = join(',', $unique_index); |
465 | 465 | } |
466 | 466 | if (count($last_lines)) { |
467 | - $create_sql.= ',' . join(',', $last_lines) . ')'; |
|
467 | + $create_sql .= ',' . join(',', $last_lines) . ')'; |
|
468 | 468 | } |
469 | 469 | return $this->query($create_sql); |
470 | 470 | } |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @param string $table |
494 | 494 | * @return array |
495 | 495 | */ |
496 | - public function describe_table($table, $schema='') |
|
496 | + public function describe_table($table, $schema = '') |
|
497 | 497 | { |
498 | 498 | $describe = $this->fetch_all("SELECT a.attname AS Field, t.typname AS Type, |
499 | 499 | CASE WHEN attnotnull=false THEN 'YES' ELSE 'NO' END AS Null, |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @param string $class clase de objeto |
524 | 524 | * @return object |
525 | 525 | */ |
526 | - public function fetch_object($query_result=null, $class='stdClass') |
|
526 | + public function fetch_object($query_result = null, $class = 'stdClass') |
|
527 | 527 | { |
528 | 528 | if (!$query_result) { |
529 | 529 | $query_result = $this->last_result_query; |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @param int $opt |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public function fetch_array($result_query=NULL, $opt=MYSQL_BOTH) |
|
178 | + public function fetch_array($result_query = NULL, $opt = MYSQL_BOTH) |
|
179 | 179 | { |
180 | - $result=array(); |
|
180 | + $result = array(); |
|
181 | 181 | if (!$result_query) { |
182 | 182 | $result_query = $this->last_result_query; |
183 | 183 | if (!$result_query) { |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | /** |
217 | 217 | * Devuelve el numero de filas de un select |
218 | 218 | */ |
219 | - public function num_rows($result_query='') |
|
219 | + public function num_rows($result_query = '') |
|
220 | 220 | { |
221 | 221 | // GDS Interbase no soporta esta funcion (No debe ser usada) |
222 | 222 | return false; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param resource $result_query |
230 | 230 | * @return string |
231 | 231 | */ |
232 | - public function field_name($number, $result_query='') |
|
232 | + public function field_name($number, $result_query = '') |
|
233 | 233 | { |
234 | 234 | |
235 | 235 | if (!$result_query) { |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param resource $result_query |
253 | 253 | * @return boolean |
254 | 254 | */ |
255 | - public function data_seek($number, $result_query=NULL) |
|
255 | + public function data_seek($number, $result_query = NULL) |
|
256 | 256 | { |
257 | 257 | if (!$result_query) { |
258 | 258 | $result_query = $this->last_result_query; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param resource $result_query |
274 | 274 | * @return int |
275 | 275 | */ |
276 | - public function affected_rows($result_query=NULL) |
|
276 | + public function affected_rows($result_query = NULL) |
|
277 | 277 | { |
278 | 278 | if (($numberRows = ibase_affected_rows()) !== false) { |
279 | 279 | return $numberRows; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return string |
289 | 289 | */ |
290 | - public function error($err='') |
|
290 | + public function error($err = '') |
|
291 | 291 | { |
292 | 292 | if (!$this->id_connection) { |
293 | 293 | $this->last_error = ibase_errmsg() ? ibase_errmsg() : "[Error Desconocido en Firebird: $err]"; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | return $this->last_error; |
298 | 298 | } |
299 | 299 | $this->last_error = ibase_errmsg() ? ibase_errmsg() : "[Error Desconocido en Firebird: $err]"; |
300 | - $this->last_error.= $err; |
|
300 | + $this->last_error .= $err; |
|
301 | 301 | if ($this->logger) { |
302 | 302 | Logger::error($this->last_error); |
303 | 303 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @return int |
338 | 338 | */ |
339 | - public function last_insert_id($table='', $primary_key='') |
|
339 | + public function last_insert_id($table = '', $primary_key = '') |
|
340 | 340 | { |
341 | 341 | return ibase_insert_id($this->id_connection); |
342 | 342 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @param string $table |
348 | 348 | * @return boolean |
349 | 349 | */ |
350 | - public function table_exists($table, $schema='') |
|
350 | + public function table_exists($table, $schema = '') |
|
351 | 351 | { |
352 | 352 | $table = strtoupper(addslashes("$table")); |
353 | 353 | // NOT LIKE 'RDB\$%' |
@@ -367,11 +367,11 @@ discard block |
||
367 | 367 | $sql_new = $sql; |
368 | 368 | |
369 | 369 | if (isset($params['limit']) && is_numeric($params['limit'])) { |
370 | - $sql_new.=" FIRST $params[limit]"; |
|
370 | + $sql_new .= " FIRST $params[limit]"; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | if (isset($params['offset']) && is_numeric($params['offset'])) { |
374 | - $sql_new.=" SKIP $params[offset]"; |
|
374 | + $sql_new .= " SKIP $params[offset]"; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | return $sql_new; |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param string $table |
384 | 384 | * @return boolean |
385 | 385 | */ |
386 | - public function drop_table($table, $if_exists=true) |
|
386 | + public function drop_table($table, $if_exists = true) |
|
387 | 387 | { |
388 | 388 | if ($if_exists) { |
389 | 389 | if ($this->table_exists($table)) { |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @param array $definition |
410 | 410 | * @return resource |
411 | 411 | */ |
412 | - public function create_table($table, $definition, $index=array()) |
|
412 | + public function create_table($table, $definition, $index = array()) |
|
413 | 413 | { |
414 | 414 | $create_sql = "CREATE TABLE $table ("; |
415 | 415 | if (!is_array($definition)) { |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | } |
464 | 464 | $create_lines[] = "$field " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra; |
465 | 465 | } |
466 | - $create_sql.= join(',', $create_lines); |
|
466 | + $create_sql .= join(',', $create_lines); |
|
467 | 467 | $last_lines = array(); |
468 | 468 | if (count($primary)) { |
469 | 469 | $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')'; |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | $last_lines[] = join(',', $unique_index); |
476 | 476 | } |
477 | 477 | if (count($last_lines)) { |
478 | - $create_sql.= ',' . join(',', $last_lines) . ')'; |
|
478 | + $create_sql .= ',' . join(',', $last_lines) . ')'; |
|
479 | 479 | } |
480 | 480 | return $this->query($create_sql); |
481 | 481 | } |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @param string $table |
497 | 497 | * @return array |
498 | 498 | */ |
499 | - public function describe_table($table, $schema='') |
|
499 | + public function describe_table($table, $schema = '') |
|
500 | 500 | { |
501 | 501 | if ($schema == '') { |
502 | 502 | return $this->fetch_all("DESCRIBE $table"); |