/** * Creates model in table * * @return \Model */ public function create() { if ($this->beforeSave()) { $sql = Mysql::prepareInsert(static::getTable(), $this->fields()); if (Mysql::exec($sql)) { $this->id = Mysql::insertID(); $this->_created = true; return $this->afterSave(); } else { throw new \Exception(Mysql::error()); } } return false; }
static function connect($server, $username, $password) { $hash = md5(serialize(array($server, $username, $password))); if (!isset(self::$linkCache[$hash])) { $link = mysql_connect($server, $username, $password); if (!$link) { $n = Mysql::errno(); $e = Mysql::error(); Mysql::logError("connect", "{$n}: {$e}"); } else { Mysql::query("set character_set_client='utf8'", $link); Mysql::query("set character_set_connection='utf8'", $link); Mysql::query("set character_set_results='utf8'", $link); } self::$linkCache[$hash] = $link; } return self::$linkCache[$hash]; }