ethnaでDB接続

ethna使い方メモ

データベースの作成

以下のコマンドを実行

create database `sample` default character set utf8;
ユーザの作成

以下のコマンドを実行

grant all privileges on sample.* to test@localhost identified by 'test';
dsnの設定

/etc/sample-ini.phpの以下を修正

'dsn' => 'mysql://admin:admin@localhost/sample',

actionファイルの修正

接続するactionファイルに以下を修正

<?php
    function perform()
    {
        $db =& $this->backend->getDB();

        $sql = "SELECT now()";
        $res =& $db->query($sql);
        $row =& $res->fetchRow();

        $this->af->setApp('now', $row[0]);

        return 'login';
    }
?>
templateファイルの修正

接続するtemplateファイルに以下の記述を追加

        <p>{$app.now}</p>