Skip to content

Instantly share code, notes, and snippets.

@sugarHoge
Created June 11, 2013 14:31
Show Gist options
  • Save sugarHoge/5757297 to your computer and use it in GitHub Desktop.
Save sugarHoge/5757297 to your computer and use it in GitHub Desktop.
SELECT⇒結果(連想配列)⇒View
<?php
require_once 'Zend/Db.php';
class MainController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$param = $this->getRequest()->getParam('token');
if ($param !== "aaa") {
throw new Zend_Exeption("不正使用エラー");
}
// DB接続情報を連想配列に格納
$dbInit = array(
'host' => 'localhost',
'username' => 'root',
'password' => 'mysql123',
'dbname' => '_udkrent',
'charset' => 'utf8'
);
try {
// 接続
$db = Zend_Db::factory('Pdo_Mysql', $dbInit);
$dat = new Zend_Date();
$nowDate = $dat->toString("yyyy-MM-dd");
$this->view->nowDate = $nowDate;
$sql = 'SELECT * FROM dtb_order where create_date >= "' . "2010-06-09" .'"';
$result = $db->query($sql);
$row = $result->fetchAll();
$count = count($row);
} catch (Zend_Exception $e) {
// 例外発生時
die($e->getMessage());
}
// DBへの接続を切断
$db->closeConnection();
$this->view->newOrderKensu = "【" . $count . "件】";
$this->view->hoge = $row;
}
}
<?php foreach ($this->hoge as $val): ?>
<li><a><?php echo $val['order_name01'] . $val['order_name02'] ?></a></li>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment