本文整理汇总了PHP中dibi类的典型用法代码示例。如果您正苦于以下问题:PHP dibi类的具体用法?PHP dibi怎么用?PHP dibi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dibi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepare
private function _prepare()
{
db::connect();
dibi::addSubst('table', 'students');
dibi::addSubst('courses_students', 'courses_students');
dibi::addSubst('courses', 'courses');
}
示例2: renderDefault
public function renderDefault($url)
{
$res = dibi::query('
SELECT
workId,
url as file,
title,
text,', Model::sqlCategory() . ' as category,
authorUrl,
CONCAT_WS(" ", name, surname) as authorName,
year,', Model::sqlWorkClassName() . 'as workClass,', 'award,
type,
pages,
words,
characters,
[read],
added,
edited
FROM [works]
join [authors] on author = authorId
WHERE `url`=%s', $url)->fetchAll();
//$res[0]['award'] = ($res[0]['award'] != 99) ? $res[0]['award'] . ". místo" : "nominaci";
//2010-08-19 22:43:25
$res[0]['added'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['added']);
$res[0]['edited'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['edited']);
$this->template->data = $res[0];
$this->template->files = FileModel::getFiles($res[0]['workId']);
Model::increaseRead($res[0]['workId']);
}
示例3: load
/**
* Nacte data.
*
* @return Bobr_Page_Page
* @throws Bobr_Page_PageIAException Pokud neni vyplnena vlastnosti id.
* @throws Bobr_Page_PageException Pokud nenajde zadne data.
*/
public function load()
{
if (0 > $this->id) {
throw new Bobr_Page_PageIAException('Neni zadano pageId ktere se ma nacist.');
}
if (!$this->loadFromCache()) {
$query = 'SELECT `container_id`, `block_id`, `weight`
FROM `' . Config::DB_PREFIX . 'pageid_container_block`
WHERE `pageid_id` = ' . $this->id . ' ORDER BY `container_id`, `weight`';
$data = dibi::query($query)->fetchAssoc('container_id,block_id');
if (empty($data)) {
throw new Bobr_Page_PageException('Zadana stranka nema zadne data.');
}
// Naimportujem data.
$this->importRecord($data);
try {
$this->setPageId(new Bobr_Page_PageId($this->id));
} catch (Bobr_Page_PageIdException $e) {
// Nelze nacist PageId nelze sestavit Page.
throw new Bobr_Page_PageException($e->getMessage());
}
// Ulozime Page do cache.
$this->saveToCache();
}
return $this;
}
示例4: indexAction
/**
*
*/
public function indexAction()
{
die('todo');
$overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false;
foreach (dibi::getDatabaseInfo()->getTables() as $table_data) {
if ($table_data->getName() == Migration_MigrationModel::getTableName()) {
continue;
}
$ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray();
$ddl_query = $ddl_data['Create Table'];
$migration_time = time();
$migration_name = 'Create' . ucfirst($table_data->getName());
$migration_name = str_replace(' ', '', $migration_name);
$migration_name = str_replace('-', '', $migration_name);
$migration_name = str_replace('_', '', $migration_name);
$filename = cfg()->migration_path . $migration_name . '.php';
if (Core_Files::fileSize($filename) && !$overwrite) {
echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL;
continue;
}
$template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME);
$template_data = str_replace('Template', $migration_name, $template_data);
$template_data = str_replace('__NAME__', $migration_name, $template_data);
$template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
$template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
$template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data);
$down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`';
$template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data);
Core_Files::putContent($filename, $template_data);
echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL;
}
}
示例5: connectToDatabase
/**
* Spoji se z databzi.
*
* @return Bobr_Bobr
* @throws DibiDriverException
*/
private function connectToDatabase()
{
// @todo odchytavat vyjimku pri nepovedenem spojeni.
$config = new Config();
$connect = dibi::connect(array('driver' => 'postgre', 'string' => ' host=' . $config->dbHost . ' port=' . $config->dbPort . ' dbname=' . $config->dbName . ' user=' . $config->dbUser . ' password=' . $config->dbPassword . '', 'persistent' => $config->dbPersistent), $config->dbConnectionName);
return $this;
}
示例6: __construct
function __construct()
{
//-----vytvorenie objektu menu
$menu = new MenuItem();
$menu->menuAction();
//-----vytvorenie objektu node
$node = new node();
$node->nodeAction();
MT::addContent($menu->render(), 'leftHolder');
try {
if (isset($_GET['id_menu_item']) or isset($_GET['addMenuItem']) or isset($_GET['changeMenuItem'])) {
MT::addTemplate(APP_DIR . '/templates/admin/modulHolder.phtml', 'modulHolder');
MT::addVar('modulHolder', 'type_modul', dibi::fetchAll("SELECT * FROM [type_modul] WHERE visible_for_user='1'"));
}
//zobrazenie zmeny polozky pre menu
if (isset($_GET['changeMenuItem'])) {
$menu->showChangeMenuItem($_GET['id_menu_item']);
}
if (isset($_GET['id_menu_item']) and !isset($_GET['changeMenuItem'])) {
$node->showModul();
}
//pridanie polozky do menu
if (isset($_GET['addMenuItem'])) {
$menu->showAddMenuItem();
}
//zachytenie vynimie
} catch (NodeException $e) {
echo '<div style="border: 2px solid red; padding: 5px;">' . $e->getMessage() . '</div>';
exit;
}
}
示例7: match
/**
* Maps HTTP request to a PresenterRequest object.
* @param Nette\Web\IHttpRequest
* @return PresenterRequest|NULL
*/
public function match(IHttpRequest $context)
{
\Nette\Diagnostics\FireLogger::log('-------------');
\Nette\Diagnostics\FireLogger::log($context);
return NULL;
if (!preg_match('#^/([a-zA-Z0-9-]+)/?$#', $context->getUri()->path, $matches)) {
return NULL;
}
$id = $matches[1];
if (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_produktu WHERE nameid=%s", $id)) {
$presenter = 'Front:Product';
} elseif (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_kategorie WHERE nameid=%s", $id)) {
$presenter = 'Front:Category';
} elseif (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_s_clanky WHERE nameid=%s", $id)) {
$presenter = 'Front:Article';
} else {
return NULL;
}
// alternativa: použít jednu tabulku s páry URL -> jméno Presenteru
// výhoda: jeden lookup místo (až) tří, neměřitelně vyšší rychlost ;)
// nevýhoda: nutnost ji udržovat :-(
// alternativa č.2: místo COUNT(*) načíst z DB celý záznam a předat v parametru presenteru
// výhoda: stejně jej bude potřebovat
// nevýhoda: nadstandardní závislost mezi routerem a presenterem
$params = $context->getQuery();
$params['id'] = $id;
return new PresenterRequest($presenter, $context->getMethod(), $params, $context->getPost(), $context->getFiles(), array('secured' => $context->isSecured()));
}
示例8: match
/**
* Maps HTTP request to a PresenterRequest object.
* @param Nette\Web\IHttpRequest
* @return PresenterRequest|NULL
*/
public function match(IHttpRequest $context)
{
if (!preg_match('#^/([a-z0-9]{1,3})/(.*?)/?$#', $context->getUri()->path, $matches)) {
return NULL;
}
$lang = $matches[1];
$categories = $matches[2];
$pom = explode("/", $categories);
$last = end($pom);
if (dibi::fetchSingle("\n\t\t\tSELECT\n\t\t\t COUNT(*)\n\t\t\tFROM\n\t\t\t category\n\t\t\t JOIN category_lang USING(id_category)\n\t\t\t JOIN [lang] USING(id_lang)\n\t\t\tWHERE iso=%s", $lang, "AND link_rewrite = %s", $last)) {
$presenter = 'Front:Eshop';
} elseif (dibi::fetchSingle("SELECT COUNT(*) FROM menu_item WHERE lang = %s", $lang, "AND url_identifier=%s", $last)) {
$presenter = 'Front:List';
} else {
return NULL;
}
// alternativa: použít jednu tabulku s páry URL -> jméno Presenteru
// výhoda: jeden lookup místo (až) tří, neměřitelně vyšší rychlost ;)
// nevýhoda: nutnost ji udržovat :-(
// alternativa č.2: místo COUNT(*) načíst z DB celý záznam a předat v parametru presenteru
// výhoda: stejně jej bude potřebovat
// nevýhoda: nadstandardní závislost mezi routerem a presenterem
$params = $context->getQuery();
// $params['link_rewrite'] = $last;
$params['lang'] = $lang;
return new NPresenterRequest($presenter, $context->getMethod(), $params, $context->getPost(), $context->getFiles(), array('secured' => $context->isSecured()));
}
示例9: renderDefault
public function renderDefault()
{
//uvod
$home = dibi::fetch("SELECT * FROM [menu_item] WHERE home = 1 AND lang = %s", $this->lang);
if (!$home) {
$home = dibi::fetch("SELECT * FROM [menu_item] WHERE lang = %s", $this->lang, "ORDER BY sequence LIMIT 1");
}
$this->template->id_menu_item = $home['id_menu_item'];
/*
* META INFO
*/
$this['header']->addTitle($home['meta_title']);
$this['header']->setDescription($home['meta_description']);
$node = $this->getService('Node');
$query = $node->getAll($this->template->id_menu_item);
$this->template->node_list = $query->fetchAll();
//produkty na uvode
$list = dibi::select('id_product')->from('product')->where('home = 1');
$count_list = clone $list;
$count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle();
$vp = new VisualPaginator($this, 'paginator');
$paginator = $vp->getPaginator();
$paginator->itemsPerPage = 12;
$paginator->itemCount = (int) $count;
$this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll();
$this->template->paginator = $paginator;
foreach ($this->template->products as $k => $p) {
$this->template->products[$k] = ProductModel::getProductWithParams($p['id_product'], $this->id_lang, $this->user);
}
/* widget */
$this['productNewsSaleAvaiableTable']->setIdLang($this->id_lang);
$this['productNewsSaleAvaiableTable']->setUser($this->user);
}
示例10: renderXml
public function renderXml()
{
$this->template->items = dibi::query('
SELECT
product.id_product AS id,
product_lang.name,
product_lang.description,
product_lang.link_rewrite AS product_link,
category_product.id_category AS id_category,
category_lang.name AS category_name,
category_lang.link_rewrite AS category_link
FROM `product`
LEFT JOIN product_lang USING (id_product)
LEFT JOIN category_product USING (id_product)
LEFT JOIN category_lang USING (id_category)
WHERE product_lang.id_lang = 1 AND
category_lang.id_lang = 1
GROUP BY (id_product)')->fetchAll();
$this->template->baseUri = 'http://www.matrace-rosty.sk';
$this->id_lang = 1;
for ($i = 0; $i < count($this->template->items); $i++) {
$productWithLowestPrice = dibi::query('SELECT * FROM product_param WHERE id_product = %i', $this->template->items[$i]['id'], ' ORDER BY price LIMIT 0,1')->fetch();
$this->template->items[$i]['url'] = $this->getPresenter()->link('Eshop:current', array('categories' => $this->template->items[$i]['category_link'], 'url_identifier' => NStrings::webalize($this->template->items[$i]['product_link'])));
$this->template->items[$i]['image'] = ProductModel::getImage($this->template->items[$i]['id']);
$this->template->items[$i]['price_vat'] = round($productWithLowestPrice['price'], 2);
$this->template->items[$i]['price'] = round($this->template->items[$i]['price_vat'] / 1.2, 2);
$this->template->items[$i]['vat'] = '0.20';
$this->template->items[$i]['size'] = $productWithLowestPrice['size'];
$this->template->items[$i]['material'] = $productWithLowestPrice['material'];
}
}
示例11: deleteMd
/**
* Metainformation catalogue
* --------------------------------------------------
*
* MICKA_LIB_INSERT.PHP for MicKa
*
* @link http://www.bnhelp.cz
* @package Micka
* @category Metadata
* @version 20101120
* @authors DZ
*/
function deleteMd($user, $type, $value, $mode, $par = NULL)
{
setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "user={$user}, {$type}={$value}, mode={$mode}, par={$par}");
$rs = FALSE;
// autorizace
if ($user == 'guest' || !canAction()) {
return $rs;
}
$record = getMdHeader($type, $value, $col = '', $fetch = array('all', '='));
if (isset($record[0]['RECNO']) && $record[0]['RECNO'] > -1) {
if (!getMdRight('edit', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) {
return $rs;
} else {
$sql = array();
if ($mode == 'all') {
array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i;', $record[0]['RECNO']);
array_push($sql, 'DELETE FROM [md] WHERE [recno]=%i;', $record[0]['RECNO']);
} elseif ($mode == 'value') {
array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i AND md_id<>38;', $record[0]['RECNO']);
}
dibi::begin();
try {
dibi::query($sql);
dibi::commit();
$rs = TRUE;
} catch (DibiException $e) {
setMickaLog($e, 'ERROR', 'micka_lib_insert.php (deleteMd)');
dibi::rollback();
}
}
}
//Debug::dump($rs);
setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "return={$rs}");
return $rs;
}
示例12: __construct
/**
* Constractor creates connection and checks/creates tables stucture
*/
public function __construct()
{
$dibiConfig = dibi::getConnection()->getConfig();
$dbname = isset($dibiConfig['dbname']) ? $dibiConfig['dbname'] : $dibiConfig['database'];
$config = array('driver' => 'sqlite', 'profiler' => Environment::getConfig('perform')->storage_profiler, 'database' => realpath(Environment::getConfig('perform')->modelCache) . '/' . $dbname . '-storage.sdb');
parent::__construct($config, 'storage');
if (!$this->getDatabaseInfo()->hasTable('fields')) {
$this->query('CREATE TABLE [fields] ([id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL,
[hash] VARCHAR(32) NOT NULL, [type] VARCHAR(50));
CREATE UNIQUE INDEX [fields_idx] on [fields] ( [name], [table]);');
}
if (!$this->getDatabaseInfo()->hasTable('tables')) {
$this->query('CREATE TABLE [tables] ( [id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);');
}
if (!$this->getDatabaseInfo()->hasTable('views')) {
$this->query('CREATE TABLE [views] ( [id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);');
}
if (!$this->getDatabaseInfo()->hasTable('indexes')) {
$this->query('CREATE TABLE [indexes] ([id] INTEGER NOT NULL PRIMARY KEY,
[name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL,
[hash] VARCHAR(32) NOT NULL, [unique] BOOLEAN);
CREATE UNIQUE INDEX [indexes_idx] on [indexes] ( [name], [table]);');
}
}
示例13: setUp
protected function setUp()
{
$this->db = dibi::getConnection("ormion");
$this->db->delete("comments")->execute();
$this->db->delete("pages")->execute();
$this->db->query("insert into [pages]", array("name" => "Clanek", "description" => "Popis", "text" => "Text", "visits" => 0, "allowed" => true), array("name" => "Article", "description" => "Description", "text" => "Text emericky.", "visits" => 5, "allowed" => false), array("name" => "Nepovolený článek", "description" => "Popis nepovoleného článku", "text" => "Dlouhý text. By byl delší než tento.", "visits" => 3, "allowed" => false), array("name" => "Jinačí článek", "description" => "Ryze alternativní popis", "text" => "Duchaplný text.", "visits" => 8, "allowed" => true));
}
示例14: renderXml_old
function renderXml_old()
{
//$this->id_lang
$this->template->items = dibi::query('
SELECT
product.id_product AS id,
product_lang.name,
product_lang.meta_description,
product_lang.link_rewrite AS product_link,
category_product.id_category AS id_category,
category_lang.name AS category_name,
category_lang.link_rewrite AS category_link
FROM `product`
LEFT JOIN product_lang USING (id_product)
LEFT JOIN category_product USING (id_product)
LEFT JOIN category_lang USING (id_category)
WHERE product_lang.id_lang = 1 AND
category_lang.id_lang = 1
GROUP BY (id_product)')->fetchAll();
$this->template->baseUri = 'http://' . $_SERVER['HTTP_HOST'];
$this->id_lang = 1;
for ($i = 0; $i < count($this->template->items); $i++) {
$this->template->items[$i]['url'] = $this->link(':Front:Product:default', array('id' => $this->template->items[$i]['id'], 'id_category' => $this->template->items[$i]['id_category']));
$this->template->items[$i]['image'] = ProductModel::getImage($this->template->items[$i]['id']);
$this->template->items[$i]['price_vat'] = round($productWithLowestPrice['price'], 2);
$this->template->items[$i]['price'] = round($this->template->items[$i]['price_vat'] / 1.2, 2);
$this->template->items[$i]['vat'] = '0.20';
$this->template->items[$i]['size'] = $productWithLowestPrice['size'];
$this->template->items[$i]['material'] = $productWithLowestPrice['material'];
}
dde($this->template->items);
}
示例15: getToken
public function getToken()
{
session_start();
$code = $_REQUEST["code"];
if (empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE));
//CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . APP_ID . "&redirect_uri=" . urlencode(REDIRECT_URI) . "&scope=" . PERMISSIONS . "&state=" . $_SESSION['state'];
echo "<script> top.location.href='" . $dialog_url . "'</script>";
}
if ($_SESSION['state'] && $_SESSION['state'] === $_REQUEST['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . APP_ID . "&redirect_uri=" . urlencode(REDIRECT_URI) . "&client_secret=" . APP_SECRET . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$date = new DateTime();
$date->add(new DateInterval('PT' . $params["expires"] . 'S'));
$arr = array('token' => $params['access_token'], 'expiration' => $date);
dibi::query('TRUNCATE tokens');
dibi::query('INSERT INTO tokens', $arr);
echo "Thanks for your token :)";
} else {
echo "The state does not match. You may be a victim of CSRF.";
}
}