66 public function find($table, $where=
"1=1", $fields=
"*", $orderBy=
"1")
71 $q = $this->
query(
"SELECT $fields FROM $table WHERE $where ORDER BY $orderBy");
88 $q = $this->
query($sql);
119 $q = $this->
query($sql);
122 while ($row = $this->
fetch_array($q, db::DB_ASSOC)) {
138 $q = $this->
query($sql);
141 while ($row = $this->
fetch_array($q, db::DB_NUM)) {
156 $q = $this->
query($sql);
158 if ($this->num_rows($q) > 1) {
159 Flash::warning(
"Una sentencia SQL: \"$sql\" retorno mas de una fila cuando se esperaba una sola");
175 public function insert($table, $values, $fields=null)
178 if (is_array($values)) {
179 if (!count($values)) {
180 new KumbiaException(
"Imposible realizar inserción en $table sin datos");
182 if (is_array($fields)) {
183 $insert_sql =
"INSERT INTO $table (" . join(
",", $fields) .
") VALUES (" . join(
",", $values) .
")";
185 $insert_sql =
"INSERT INTO $table VALUES (" . join(
",", $values) .
")";
187 return $this->
query($insert_sql);
189 throw new KumbiaException(
'El segundo parametro para insert no es un Array');
202 public function update($table, $fields, $values, $where_condition=null)
204 $update_sql =
"UPDATE $table SET ";
205 if (count($fields) != count($values)) {
206 throw new KumbiaException(
'Los número de valores a actualizar no es el mismo de los campos');
209 $update_values = array();
210 foreach ($fields as $field) {
211 $update_values[] = $field .
' = ' . $values[$i];
214 $update_sql.= join(
',', $update_values);
215 if ($where_condition != null) {
216 $update_sql.=
" WHERE $where_condition";
218 return $this->
query($update_sql);
227 public function delete($table, $where_condition)
229 if (trim($where_condition)) {
230 return $this->
query(
"DELETE FROM $table WHERE $where_condition");
232 return $this->
query(
"DELETE FROM $table");
242 return $this->
query(
'BEGIN');
251 return $this->
query(
'ROLLBACK');
260 return $this->
query(
'COMMIT');
270 return "'" . addslashes($value) .
"'";
279 protected function log($msg, $type)