61 private $return_rows =
true;
73 private $actual_limit = 0;
137 if (!extension_loaded(
'informix')) {
138 throw new KumbiaException(
'Debe cargar la extensión de PHP llamada php_ifx');
141 if ($this->id_connection = ifx_connect(
"{$config['name']}@{$config['host']}",
$config[
'username'],
$config[
'password'])) {
156 $this->
debug($sql_query);
161 $this->last_query = $sql_query;
164 if ($this->return_rows) {
165 $result_query = ifx_query($sql_query, $this->id_connection, IFX_HOLD);
167 $result_query = ifx_query($sql_query, $this->id_connection);
170 if ($result_query ===
false) {
173 $this->last_result_query = $result_query;
174 return $result_query;
184 if ($this->id_connection) {
185 return ifx_close($this->id_connection);
200 if (!$result_query) {
202 if (!$result_query) {
206 $fetch = ifx_fetch_row($result_query, $opt);
209 if ($this->
limit != -1) {
210 if ($this->actual_limit >= $this->
limit) {
212 $this->actual_limit = 0;
215 $this->actual_limit++;
216 if ($this->actual_limit == $this->
limit) {
218 $this->actual_limit = 0;
224 if (!is_array($fetch) || ($opt == self::DB_ASSOC)) {
227 if ($opt == self::DB_BOTH) {
230 foreach ($fetch as $key => $value) {
231 $result[$key] = $value;
232 $result[$i++] = $value;
236 if ($opt == self::DB_NUM) {
237 return array_values($fetch);
260 if (!$result_query) {
262 if (!$result_query) {
266 if (($number_rows = ifx_num_rows($result_query)) !==
false) {
269 if ($this->
limit == -1) {
272 return $this->
limit < $number_rows ? $this->
limit : $number_rows;
289 if (!$result_query) {
291 if (!$result_query) {
295 $fields = ifx_fieldproperties($result_query);
296 if (!is_array($fields)) {
300 $fields = array_keys($fields);
301 return $fields[$number];
314 if (!$result_query) {
316 if (!$result_query) {
320 if (($success = ifx_fetch_row($result_query, $number)) !==
false) {
335 if (!$result_query) {
337 if (!$result_query) {
341 if (($numberRows = ifx_affected_rows($result_query)) !==
false) {
355 if (!$this->id_connection) {
356 $this->last_error = ifx_errormsg() ? ifx_errormsg() :
"[Error Desconocido en Informix: $err]";
362 $this->last_error = ifx_errormsg($this->id_connection) ? ifx_errormsg($this->id_connection) :
"[Error Desconocido en Informix: $err]";
363 $this->last_error.= $err;
387 $sqlca = ifx_getsqlca($this->last_result_query);
388 return $sqlca[
"sqlerrd1"];
400 $table = addslashes(
"$table");
401 $num = $this->
fetch_one(
"SELECT COUNT(*) FROM systables WHERE tabname = '$table'");
402 return (
int) $num[0];
430 return $this->
query(
"DROP TABLE $table");
436 return $this->
query(
"DROP TABLE $table");
455 $create_sql =
"CREATE TABLE $table (";
456 if (!is_array($definition)) {
457 throw new KumbiaException(
"Definición invalida para crear la tabla '$table'");
459 $create_lines = array();
461 $unique_index = array();
465 foreach ($definition as $field => $field_def) {
466 if (isset($field_def[
'not_null'])) {
467 $not_null = $field_def[
'not_null'] ?
'NOT NULL' :
'';
471 if (isset($field_def[
'size'])) {
472 $size = $field_def[
'size'] ?
'(' . $field_def[
'size'] .
')' :
'';
476 if (isset($field_def[
'index'])) {
477 if ($field_def[
'index']) {
478 $index[] =
"INDEX($field)";
481 if (isset($field_def[
'unique_index'])) {
482 if ($field_def[
'unique_index']) {
483 $index[] =
"UNIQUE($field)";
486 if (isset($field_def[
'primary'])) {
487 if ($field_def[
'primary']) {
488 $primary[] =
"$field";
491 if (isset($field_def[
'auto'])) {
492 if ($field_def[
'auto']) {
493 $field_def[
'type'] =
"SERIAL";
496 if (isset($field_def[
'extra'])) {
497 $extra = $field_def[
'extra'];
501 $create_lines[] =
"$field " . $field_def[
'type'] . $size .
' ' . $not_null .
' ' . $extra;
503 $create_sql.= join(
',', $create_lines);
504 $last_lines = array();
505 if (count($primary)) {
506 $last_lines[] =
'PRIMARY KEY(' . join(
",", $primary) .
')';
509 $last_lines[] = join(
',', $index);
511 if (count($unique_index)) {
512 $last_lines[] = join(
',', $unique_index);
514 if (count($last_lines)) {
515 $create_sql.=
',' . join(
',', $last_lines) .
')';
518 return $this->
query($create_sql);
528 return $this->
fetch_all(
"SELECT tabname FROM systables WHERE tabtype = 'T' AND version <> 65537");
544 $describe = $this->
fetch_all(
"SELECT c.colname AS Field, c.coltype AS Type,
545 'YES' AS NULL FROM systables t, syscolumns c WHERE
546 c.tabid = t.tabid AND t.tabname = '$table' ORDER BY c.colno");
547 $final_describe = array();
548 foreach ($describe as $field) {
550 if ($field[
'field'] ==
'id') {
551 $field[
"key"] =
'PRI';
552 $field[
"null"] =
'NO';
556 if (substr($field[
'field'], -3) ==
'_id') {
557 $field[
"null"] =
'NO';
559 if ($field[
'type'] == 262) {
560 $field[
'type'] =
"serial";
562 if ($field[
'type'] == 13) {
563 $field[
'type'] =
"varchar";
565 if ($field[
'type'] == 7) {
566 $field[
'type'] =
"date";
568 $final_describe[] = array(
569 "Field" => $field[
"field"],
570 "Type" => $field[
"type"],
571 "Null" => $field[
"null"],
572 "Key" => $field[
"key"]
575 return $final_describe;
586 public function insert($table, $values, $fields=null)
589 return parent::insert($table, $values, $fields);
601 public function update($table, $fields, $values, $where_condition=null)
604 return parent::update($table, $fields, $values, $where_condition);
613 public function delete($table, $where_condition)
616 return parent::delete($table, $where_condition);
626 $this->return_rows = $value;
636 return $this->
query(
"BEGIN WORK");
646 return $this->
query(
"ROLLBACK");
656 return $this->
query(
"COMMIT");