public function __construct() { $this->connection = Connection::instance()->open(); if (is_null($this->model)) { $this->model = strtolower(get_class($this)); } }
public function __construct($condition) { //the connection with the data base $this->connection = Connection::instance()->open(); if (empty($this->table)) { $this->table = strtolower(get_class($this)); } if (!is_null($condition)) { if (is_int($condition)) { $this->pkVal = $condition; $this->findByPk($condition); $this->setCondition($condition); } elseif (is_array($condition)) { $this->find($condition); $this->setCondition($condition); } } else { return $this; } }
private function auth($authDBData) { $tblData = explode('.', $authDBData); list($table, $field) = $tblData; $connection = Connection::instance()->open(); $and = ''; foreach ($this->data as $field => $value) { //if exists a crypt in the rules array, encryption will be performed if (in_array('crypt', $this->rules[$field])) { $value = crypt($value, Config::get('salt')); } $and .= is_int($value) ? "`{$field}` = {$value}" : "`{$field}` = '{$value}' AND "; } $and = substr($and, 0, strlen($and) - 4); $execute = $connection->query("SELECT * FROM `{$table}` WHERE {$and}"); //if the query result is null, return false if ($execute->num_rows == 0) { return false; } return true; unset($authDBData); }