本文整理汇总了PHP中Nette\Database\Context::query方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::query方法的具体用法?PHP Context::query怎么用?PHP Context::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Context
的用法示例。
在下文中一共展示了Context::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->database->query($this->getFile(self::FILE_EMAILS_TABLE));
$this->database->query($this->getFile(self::FILE_GROUPS_TABLE));
$this->database->query($this->getFile(self::FILE_SENDER_LIST_TABLE));
$this->database->query($this->getFile(self::FILE_GROUP_EMAIL_TABLE));
}
示例2: renderDefault
public function renderDefault()
{
// 1. Vlozeni noveho zaznamu do tabulky se zavody
// 2. Vyber zavodu (identifikatoru), vetsinou toho, ktery byl vytvoren v predchozim bode
$id_event = "VCHOD2015";
// 3. Kontrola identifikatoru zavodu - nesmi byt pouzit v tabulce casu
$data = $this->database->query('select id from sm_time where id_event = ?', $id_event);
if ($data->getRowCount() > 0) {
// Chyba! Vyzadovat novou volbu zavodu
// Pozor! VCHOD2015 jiz v tabulce casu je!
}
// 4. Zadani textoveho souboru s vysledky s predepsanym DR
// $input_file = "/home/vencs88/php/import_time/data/cp_praha2015.txt";
// $input_file = "/home/vencs88/php/import_time/data/vysledky_blbec.txt";
$input_file = "/home/vencs88/php/import_time/data/mem2015.txt";
// 5. Vizualni kontrola chyb po nacteni vysledku do pomocne tabulky
$this->template->status = $this->importTimeManager->getImportData($input_file, $id_event);
$this->template->data = $this->database->table('sm_import');
// 6. Nejsou-li chyby, umoznit import vysledku do tabulky casu
// INSERT INTO sm_time
// (
// id_stroke,
// id_swimmer,
// time,
// rank,
// point
// )
// SELECT * FROM sm_import;
//
// // Zvazit vymaz pomocne tabulky
// DELETE FROM sm_import;
}
示例3: setRole
public function setRole($id, $roles)
{
$this->database->query("DELETE FROM uzivatele_role WHERE uzivatel_id=?;", $id);
foreach ($roles as $k => $v) {
if ($v == 1) {
$this->database->query("INSERT INTO uzivatele_role ", array("role_id" => $k, "uzivatel_id" => $id));
}
}
}
示例4: save
public function save($vals)
{
$arr = array('alt' => $vals['alt'], 'title' => $vals['title']);
if (!empty($vals['id'])) {
$this->database->query("UPDATE upload SET ", $arr, " WHERE id=?;", $vals['id']);
return $this->get($vals['id']);
} else {
$arr['extension'] = $vals['extension'];
$this->database->query("INSERT INTO upload ", $arr);
return $this->get($this->database->getInsertId());
}
}
示例5: startup
protected function startup()
{
parent::startup();
$this->database->query("SET search_path TO dba");
// TODO temporary schema search path fix
if ($this->presenter->name != 'Sign' && !$this->user->isLoggedIn()) {
$this->redirect('Sign:in');
}
if ($this->user->getLogoutReason() == Nette\Security\IUserStorage::INACTIVITY) {
$this->flashMessage('You have been logged out (20 minutes).', 'info');
}
}
示例6: getKey
/**
* @param $application
* @param $key
* @return false|Apikey
*/
public function getKey($application, $key)
{
$row = $this->database->query("SELECT * FROM " . self::TABLE . " WHERE application = ? AND `key` = ? AND expiration >= NOW()", $application, $key)->fetch();
if ($row) {
$entity = new Apikey();
$entity->setId($row['id']);
$entity->setApplication($row['application']);
$entity->setKey($row['key']);
$entity->setExpiration($row['expiration']);
return $entity;
}
return FALSE;
}
示例7: ensureUser
private function ensureUser()
{
if (!$this->getUser()->isLoggedIn()) {
$this->database->query("INSERT INTO `users`", array("id" => null));
$us = $this->database->table('users')->where('id = ?', $this->database->getInsertId())->fetch();
$this->user->setExpiration('365 days', FALSE);
$this->user->login(new \Nette\Security\Identity($us->id, null, $us));
} else {
$us = $this->database->table('users')->where('id = ?', $this->user->getId())->fetch();
if ($us == null) {
$this->user->logout(true);
}
}
}
示例8: purge
function purge(\Nette\Database\Context $context)
{
/* For mysql */
$tables = $context->query("SELECT TABLE_NAME AS t FROM `INFORMATION_SCHEMA`.`TABLES` WHERE TABLE_SCHEMA = 'test' ")->fetchAll();
if ($tables) {
$arr = [];
foreach ($tables as $table) {
$arr[] = $table['t'];
}
$context->query("SET foreign_key_checks = 0");
$context->query("DROP TABLE " . implode(", ", $arr));
$context->query("SET foreign_key_checks = 1");
}
}
示例9: processViews
private function processViews()
{
$tables = $this->db->getConnection()->getSupplementalDriver()->getTables();
foreach ($tables as $table) {
if ($table['view'] == TRUE) {
$viewName = $table['name'];
// Fetch SHOW CREATE VIEW string
$row = $this->db->query("SHOW CREATE VIEW `{$viewName}`")->fetch();
$createView = $row["Create View"];
// Remove Auto increment value
$createView = Strings::replace($createView, '#SQL SECURITY DEFINER\\s?#i');
$createView = Strings::replace($createView, '#ALGORITHM=UNDEFINED\\s?#i');
$createView = Strings::replace($createView, '/DEFINER=`.+?`\\@`.+?`\\s?/');
// Add ;
$createView .= ";";
$dropTable = "DROP VIEW IF EXISTS `{$viewName}`;\n";
$data = Data::header() . $dropTable . $createView . "\n" . Data::footer();
$dump = new Dump($viewName, Dump::TYPE_VIEW, $this->dumpDir);
$dump->saveIfChanged($data, function ($fromFile) use($createView) {
$createViewFromFile = Strings::match($fromFile, "/CREATE.*;/s")[0];
return Strings::normalize($createViewFromFile) == Strings::normalize($createView);
});
}
}
}
示例10: add
public function add(IEntity $parent, array $add)
{
$this->mapperOne->beginTransaction();
$list = $this->buildList($parent, $add);
$builder = new SqlBuilder($this->joinTable, $this->context);
$this->context->query($builder->buildInsertQuery(), $list);
}
示例11: getImportData
/**
* Ze zvoleneho txt souboru vybere vysledky domacich plavcu
* @param string $file_name Vstupni txt soubor
* @param string $event_id Identifikator zavodu
* @param string $delimiter Oddelovac poli
* @param int $length Maximalni delka radku
* @return array Informace o poctu chyb a nactenych zaznamu
*/
public function getImportData($file_name, $id_event, $delimiter = ";", $length = 1000)
{
setlocale(LC_CTYPE, 'cs_CZ.UTF-8');
// V pripade chyby fopen vrati FALSE
if (!($this->fp = @fopen($file_name, "r"))) {
$this->status["fileok"] = FALSE;
return $this->status;
}
$this->id_event = $id_event;
$this->delimiter = $delimiter;
$this->length = $length;
// Prochazi se vsechny radky vstupniho souboru
while (($row = fgetcsv($this->fp, $this->length, $this->delimiter)) !== FALSE) {
// Z radku se nactou pouze pozadovane polozky
$this->selectRow($row);
}
// Ulozi se pocet nactenych zaznamu
$this->status["recnum"] = count($this->data);
// Vymaz pomocne tabulky
$this->database->query('TRUNCATE TABLE sm_import');
// Naplneni pomocne tabulky
$this->database->query('INSERT INTO sm_import', $this->data);
// Vraceni informace o poctu chyb a nactenych zaznamu
return $this->status;
}
示例12: executeQueries
/**
* @param Selection|ActiveRow[]
* @return array
*/
public function executeQueries(Selection $queries)
{
$errors = [];
foreach ($queries as $query) {
try {
$this->database->query($query->query);
// update query as executed
$query->update(['executed' => 1]);
} catch (\Exception $e) {
// save information about error in query
$query->update(['error' => $e->getMessage()]);
$errors[$query->getPrimary()] = $e->getMessage();
}
}
return $errors;
}
示例13: executeQueries
public function executeQueries(\Nette\Database\Table\Selection $queries)
{
$errors = array();
foreach ($queries as $query) {
try {
$test = $this->connection->query($query->query);
// update query as executed
$query->update(array('executed' => 1));
} catch (\Exception $e) {
// save information about error in query
$query->update(array('error' => $e->getMessage()));
$errors[$query->id] = $e->getMessage();
}
}
return $errors;
}
示例14: invoke
public function invoke(Container $container, Context $db)
{
$driver = new PostgreSqlNetteDbDriver($db, 'migrations');
$printer = new Console();
$runner = new Runner($driver, $printer);
if ($this->in->getOption('init')) {
ob_start();
$runner->run($runner::MODE_INIT);
$sql = ob_get_clean();
$db->query($sql);
$this->out->writeln('<info>Migrations table created</info>');
return;
}
$g = new Group();
$g->directory = __DIR__ . '/../../../migrations/struct';
$g->dependencies = [];
$g->enabled = TRUE;
$g->name = 'struct';
$runner->addGroup($g);
$runner->addExtensionHandler('sql', new Extensions\NetteDbSql($db));
$runner->addExtensionHandler('php', new PhpClass(['db' => $db], $container));
try {
$runner->run();
return;
} catch (\PDOException $e) {
if ($e->getCode() !== '42S02') {
throw $e;
}
// lets hope locale is english
if (!preg_match("~Table '.*?\\.migrations' doesn't exist~", $e->getMessage())) {
throw $e;
}
$this->out->writeln('<error>Migrations table does not exist, init migrations first</error>');
}
}
示例15: setCategory
/**
* Create new category
*/
function setCategory($title, $parent, $slug = null)
{
if (is_numeric($parent) == false) {
$parent = null;
}
$this->database->table("categories")->insert(array("title" => $title, "parent_id" => $parent));
$this->database->query("UPDATE categories SET sorted = id WHERE sorted = 0");
}