public function generatePrimaryKey() { $dao = new DAO(get_called_class()); // TODO HAX $connection = DB::getConnection(); $q = $connection->prepare("SELECT COUNT(*) FROM " . self::$tableName . " WHERE fight_id = " . $this->fight_id); $q->execute(); $r = $q->get_result(); $actionCount = $r->fetch_row()[0]; $this->action_id = $actionCount + 1; }
public static function query($query) { $connection = DB::getConnection(); $q = $connection->prepare($query); if (!$q) { return null; } if (func_num_args() > 1) { $refs = []; $values = array_slice(func_get_args(), 1); if (is_array($values[0]) && func_num_args() === 2) { $values = $values[0]; } $types = []; foreach ($values as $arg) { if (is_numeric($arg)) { $types[] = "i"; } else { $types[] = "s"; } $refs[] =& $values; } call_user_func_array([$q, "bind_param"], array_merge([implode($types)], $refs)); } $result = $q->execute(); if ($result) { return $q->get_result(); } else { return NULL; } }