Commit d08d9af8 authored by Alex Ne's avatar Alex Ne

Добавлена функция first

parent 95b8140a
...@@ -328,6 +328,19 @@ class X_DB_MySQLi { ...@@ -328,6 +328,19 @@ class X_DB_MySQLi {
} }
} }
/**
* @param $SQL
* @return mixed
*/
public function first($SQL) {
$data = $this->get($SQL);
if (is_array($data) && count($data) > 0) {
return $data[0];
} else {
return false;
}
}
/** /**
* @param $table * @param $table
* @param $column * @param $column
......
...@@ -89,6 +89,21 @@ class TableItem { ...@@ -89,6 +89,21 @@ class TableItem {
return $this; return $this;
} }
public function first() {
$columns = func_get_args();
if (count($columns) == 1 && is_array($columns[0])) {
$columns = "`" . implode("`,`", $columns[0]) . "`";
} else if (count($columns) > 1) {
$columns = "`" . implode("`,`", $columns) . "`";
} else {
$columns = "*";
}
$this->sql_type = "first";
$this->sql = "SELECT {$columns} FROM `{$this->table_name}`";
return $this;
}
public function select() { public function select() {
$columns = func_get_args(); $columns = func_get_args();
if (count($columns) == 1 && is_array($columns[0])) { if (count($columns) == 1 && is_array($columns[0])) {
...@@ -333,6 +348,9 @@ class TableItem { ...@@ -333,6 +348,9 @@ class TableItem {
if ($this->sql_type == "select" && $this->driver instanceof \X_DB_MySQLi) { if ($this->sql_type == "select" && $this->driver instanceof \X_DB_MySQLi) {
return $this->driver->get($this->sql . $this->sql_where . $this->sql_order . $this->sql_limit, $op1, $op2, $op3); return $this->driver->get($this->sql . $this->sql_where . $this->sql_order . $this->sql_limit, $op1, $op2, $op3);
} }
if ($this->sql_type == "first" && $this->driver instanceof \X_DB_MySQLi) {
return $this->driver->first($this->sql . $this->sql_where . $this->sql_order . $this->sql_limit, $op1, $op2, $op3);
}
if ($this->sql_type == "delete" && $this->driver instanceof \X_DB_MySQLi) { if ($this->sql_type == "delete" && $this->driver instanceof \X_DB_MySQLi) {
return $this->driver->rq($this->sql . $this->sql_where); return $this->driver->rq($this->sql . $this->sql_where);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment