[Maple-user: 330] Re: データベース接続の簡単なサンプル

Back to archive index

h-tag****@secom***** h-tag****@secom*****
2006年 8月 4日 (金) 17:13:01 JST


田口です、有り難う御座いました。
無事、できました。

> <?php
> class Index
> {

は、

<?php
require_once 'DB.php';

が必要でした。入れる場所、ここでいいのでしょうか?

h-taguchi @ secom
 

> 対象Actionクラス webapp/modules/index/Index.class.php
> 
> <?php
> class Index
> {
> 
> var $names;
> 
> function execute()
> {
> $this->names = array();
> 
> // 接続
> $db = DB::connect('mysql://ユーザー名@パスワード@DBのホスト/データベース
> 名');
> if (PEAR::isError($db)) { die($db->getMessage();) }
> 
> // 検索
> $res =& $db->query('SELECT name FROM mytable');
> 
> // 各行のデータの取得を、
> // 最後の行に到達するまで続けます
> while ($res->fetchInto($row)) {
> // DB のデフォルトのフェッチモードが DB_FETCHMODE_ORDERED であると仮定します
> $this->names[] = $row[0];
> }
> 
> // 切断
> $db->disconnect();
> 
> return 'success';
> }
> }
> ?>
> 



Maple-user メーリングリストの案内
Back to archive index