public function save(\Models\PageModel $page) { $query = "INSERT INTO page (label, title, body, slug) VALUES (?, ?, ?, ?)"; $param = [$page->getLabel(), $page->getTitle(), $page->getBody(), $page->getSlug()]; $this->db->query($query, $param); return $this->db->row(); }
public function selectByConferenceId($id) { $query = "SELECT v.name, v.address, v.id\r\n FROM venues v\r\n JOIN conferences c ON c.venue_id = v.id\r\n WHERE c.id = ?"; $this->db->query($query, [$id]); $result = $this->db->row(); return new \Models\VenueModel($result['name'], $result['address'], $result['id']); }
/** * * @param \Repository\User $user * @return type */ public function save(\Models\UserModels $user) { $query = "INSERT INTO users (username, password) VALUES (?, ?)"; $param = [$user->getUsername(), $user->getPasword()]; $this->db->query($query, $param); return $this->db->row(); }
public function save(User_infoModel $user) { $query = 'INSERT INTO user_info(user_id, gender, first_name, last_name, email) VALUE (?, ?, ?, ?, ?)'; $param = [$user->getUserId(), $user->getGender(), $user->getFirstName(), $user->getLastName(), $user->getEmail()]; $this->db->query($query, $param); return $this->db->row(); }
public function save(\Models\ConferenceModel $conf) { $query = 'INSERT INTO conferences (confName, startDate, endDate, venue_id, user_id) VALUES (?, ?, ?, ?, ?)'; $param = [$conf->getConfName(), $conf->getStartDate(), $conf->getEndDate(), $conf->getVenueId(), $conf->getUserId()]; $this->db->query($query, $param); return $this->db->row(); }
public function getHallIdByConference($confId, $hallName) { $query = 'SELECT h.id, h.seating, h.hallName, h.venue_id FROM `halls` AS h JOIN `venues` AS v ON v.id = h.venue_id JOIN `conferences` AS c ON c.venue_id = v.id WHERE c.id = ? and h.hallName = ?'; $this->db->query($query, [$confId, $hallName]); return $this->db->row(); }
public function getLecturesById($id) { $query = 'SELECT name, startTime, endTime, break, hall_id, conference_Id, day, l.id FROM lectures as l WHERE c.id = ?'; $this->db->query($query, [$id]); $result = $this->db->fetchAll(); $lecture = []; foreach ($result as $key => $value) { $lecture[] = new LectureModel($value['name'], $value['startTime'], $value['endTime'], $value['break'], $value['hall_id'], $value['conference_Id'], $value['day'], $value['id']); } return $lecture; }
public function run() { $this->prepareTables(); $repeats = $this->getRepeats(); $sql = 'SELECT txt FROM test'; $bar = new CliProgressBar($repeats); for ($i = 1; $i <= $repeats; ++$i) { Timer::start(); $result = ODb::rows($sql); foreach ($result as $value) { } Timer::stop(); $bar->update($i); } $this->addResult('non-generator', Timer::get()); Timer::reset(); $bar = new CliProgressBar($repeats); // Db class initialization $pool = new ConnectionPool(); $conn = new PdoConnection('master'); $conn->setDsn("mysql:host=localhost;dbname={$this->database};charset=utf8")->setUserName('root')->setPassword('')->setOptions([PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false]); $pool->addConnection($conn, true); PdoAdapter::setPool($pool); Db::setAdapter(PdoAdapter::instance()); for ($i = 1; $i <= $repeats; ++$i) { Timer::start(); $result = Db::rows($sql); foreach ($result as $value) { } Timer::stop(); $bar->update($i); } $this->addResult('generator', Timer::get()); $this->cleanup(); }
public function __construct($db_connection = null) { if ($db_connection == null) { $this->db = Db::get(); } else { $this->db = $db_connection; } }
function __construct($id, $title, $text, $author, $type, $views, $date, $img) { parent::__construct($id, $title, $text); $this->author = $author; $db = \database\Db::getInstance(); $pdo = $db->getDb(); $category = new CategoryMapper($pdo); $this->type = $category->find($type); $this->views = $views; $this->date = $date; $this->img = $img; }
public function createTable($class, $properties = []) { $constrain = ["CONSTRAINT fk_user_info_users FOREIGN KEY (user_id)\r\n REFERENCES conf.users (id))", "CONSTRAINT fk_users_roles FOREIGN KEY (role_id)\r\n REFERENCES conf.role (id))"]; $query = "CREATE TABLE IF NOT EXISTS `conf`.`{$class}` ( "; foreach ($properties as $value) { foreach ($value as $valueKey => $valueName) { $query .= "{$valueKey} "; foreach ($value[$valueKey] as $v) { $query .= "{$v} "; } $query .= ', '; } } if ($class == "Users") { $query .= $constrain[1]; } if ($class == "User_info") { $query .= $constrain[0]; } $query .= " DEFAULT CHARACTER SET = utf8"; $this->db->query($query); return $this->db->row(); }
<?php require_once 'AutoLoad.php'; new AutoLoad(); const CONTROLLER = 'home'; const ACTION = 'index'; \Database\Db::setInstance(\Database\DBConfig::DB_NAME, \Database\DBConfig::DB_PASS, \Database\DBConfig::DB_HOST, \Database\DBConfig::DB_HOST); $uri = $_GET['uri']; $uri = trim($uri, '/'); $requestUri = explode('/', $uri); $controller = array_shift($requestUri); $controller = ucfirst(strtolower($controller)); if ($controller == 'Admin') { $controller = array_shift($requestUri); $controller = 'Admin\\' . ucfirst(strtolower($controller)); } $action = array_shift($requestUri); $params = $requestUri; $app = new \App($controller, $action, $params); $app->run();
/** * Registry constructor. * @param $db */ public function __construct($db) { // Exemplo de injeção de dependência $this->db = Db::getInstance(); }
/** * 设置服务对应队列存放数据库并进行实例化数据库实例 */ public function setDb() { $type = array_key_exists("type", $this->db_conf) ? $this->db_conf["type"] : DATA_TYPE_REDIS; $this->db = Db::getInstance($type, $this->db_conf); }
private function loadConfig() { \Database\Db::attachDriver('mysql', new \Database\Adapter\Mysql('localhost', 'root', '123abcxyz', 'ltvn')); }
/** * Pages quantity calculation */ public function calcMaxPages() { $this->page_nums = (int) ceil(Db::getFoundRows() / $this->getLimit()); }