本文整理汇总了PHP中ActiveRecord::connectPdo方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::connectPdo方法的具体用法?PHP ActiveRecord::connectPdo怎么用?PHP ActiveRecord::connectPdo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::connectPdo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPages
public function getPages($category)
{
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly');
$data = $blog->findFromKey('category', $category);
$ids = array();
foreach ($data as $row) {
$ids[] = $row->postid;
}
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$result = array();
foreach ($ids as $pagenum) {
$result[] = $blog->find($pagenum);
}
return $result;
}
示例2: getCategory
public function getCategory()
{
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly');
$categories = $blog->getValueList('category');
$result = array();
foreach (array_reverse($categories) as $category) {
$result[] = array('title' => $category, 'url' => sprintf("/?category=%s", urlencode($category)));
}
return $result;
}
示例3: getPages
public function getPages($archive)
{
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$result = $blog->findLike('date', sprintf("%s/%s", explode('-', $archive)[0], explode('-', $archive)[1]) . '%');
$pagenum_arr = array();
foreach ($result as $page) {
$pagenum_arr[] = $page->pagenum;
}
array_multisort($pagenum_arr, SORT_ASC, $result);
return $result;
}
示例4: getAllMonths
private function getAllMonths()
{
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$dates = $blog->getValueList('date');
foreach ($dates as $date) {
$ym[] = explode('/', $date)[0] . "-" . explode('/', $date)[1];
}
$ym = array_unique($ym);
asort($ym);
foreach ($ym as $date) {
$result[] = ["year" => explode('-', $date)[0], "month" => explode('-', $date)[1]];
}
return $result;
}
示例5: ActiveRecord
<?php
require_once 'activerecord.php';
$ar = new ActiveRecord();
$ar->connectPdo('blogdb', 'blog', $_POST['username'], $_POST['password']);
$postid = $ar->size() + 1;
$ar->pagenum = $postid;
$ar->author = $_POST['username'];
$ar->date = date('Y/m/d');
$ar->title = $_POST['title'];
$ar->text = nl2br($_POST['text']);
try {
$ar->save();
} catch (Exception $e) {
echo $e->getMessage();
return;
}
$ar->connectPdo('blogdb', 'categorytable', $_POST['username'], $_POST['password']);
$categories = explode(',', $_POST["category"]);
foreach ($categories as $category) {
$ar->postid = $postid;
$ar->category = $category;
try {
$ar->save();
} catch (Exception $e) {
echo $e->getMessage();
$ar->connectPdo('blogdb', 'blog', $_POST['username'], $_POST['password']);
$postid = $ar->size();
$ar->delete($postid);
return;
}
示例6: Smarty
<?php
define('SMARTY_DIR', '/usr/share/php/smarty3/');
require_once 'activerecord.php';
require_once SMARTY_DIR . 'Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir = '/srv/smarty/templates';
$smarty->compile_dir = '/srv/smarty/templates_c';
$smarty->config_dir = '/srv/smarty/configs';
$smarty->cache_dir = '/srv/smarty/cache';
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$num = $blog->size();
$pages = $blog->pickout($num - 10, 10);
$items = array();
$category = new ActiveRecord();
$category->connectPdo('blogdb', 'categorytable', 'readonly', 'readonly');
$categories = $category->find($num - 2)->category;
for ($i = 0; $i < 10; $i++) {
$categorystr = $category->find($num - (9 - $i))->category;
$datetime = new DateTime($pages[9 - $i]->date);
$items[$i] = array('title' => $pages[9 - $i]->title, 'link' => "http://pakutoma.pw/?page={$pages[9 - $i]->pagenum}", 'category' => $categorystr, 'description' => mb_substr(str_replace("\n", " ", strip_tags($pages[9 - $i]->text)), 0, 40) . '...', 'pubDate' => $datetime->format(DATE_RSS));
}
$smarty->assign('items', $items);
$smarty->display('rss.tpl');
示例7: ArchiveView
$archiveview = new ArchiveView();
$data = $archiveview->getPages($archive);
if (!isset($data[0]->pagenum)) {
echo "データが存在しません。";
return;
}
$latest = new LatestPages();
$category = new Category();
$archive = new Archive();
foreach (array_reverse($data) as $page) {
$main[] = array('title' => $page->title, 'date' => $page->date, 'text' => mb_substr($page->text, 0, mb_strpos($page->text, "<br />")), 'pagenum' => $page->pagenum);
}
$smarty->assign('title', 'アーカイブ:' . $_GET['archive']);
} else {
$blog = new ActiveRecord();
$blog->connectPdo('blogdb', 'blog', 'readonly', 'readonly');
$data = $blog->find($blog->size());
if (!isset($data->pagenum)) {
echo "データが存在しません。";
return;
}
$latest = new LatestPages();
$category = new Category();
$archive = new Archive();
$main[] = array('title' => $data->title, 'date' => $data->date, 'text' => $data->text);
$smarty->assign('prev', $blog->find($blog->size() - 1));
}
}
}
$smarty->assign('main', $main);
$smarty->assign('latest', $latest->getPages());