**目次 [#ba5d08a7]
 #contents
 
 ** カウンタプログラム作成(DB) [#o47ffa45]
 |カテゴリー|カウンタプログラム作成(DB)|
 |優先順位|A|
 |イテレーション|[[イテレーション1]]|
 |状態|完了|
 |完了予定日|2007/8/10|
 |工数||
 |対応者|清原|
 
 ----
 **要件 [#ef00bbe2]
 -ウェブアプリであること。
 -数字が表示される。
 -その数字は更新するたびに1ずつインクリメントされていくこと。
 http://carrot.ark-web.jp/~konuma/counter/counter.php
 ↑これと同じ仕様です(ソースは見ちゃダメです。文字化けもマネしちゃいけません。)
 
 かつソースはオブジェクト指向的に書いてください。
 DBを使用する事。
 
 **ソース [#i8c07762]
 -dbcounttest.php
  <html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
  <?php
  require_once('DataBaseCounter.php');
  $count = new DataBaseCounter('mysql://root@localhost/count','counter');
  $count->connect();
  print("合計:".$count->renewCount('scnt')."\n<br>");
  print("今日:".$count->renewCount('tcnt')."\n<br>");
  $count->disconnect();
  ?>
  </body>
  </html>
 
 -DataBaseCount.php
  <?php
  class DataBaseCounter{
      var $dns;
      var $tablename;
      var $db;
      function DataBaseCounter($dns,$tablename)
      {
          require_once('DB.php');
          $this->dns = $dns;
          $this->tablename = $tablename;
      }
      function connect()
      {
          $this->db = DB::connect($this->dns);
          if (PEAR::isError($this->db)){
              die($this->db->getMessage());
          }
      }
      function renewCount($day)
      {
          $res = $this->db->getOne('select '.$day .' from '.$this->tablename);
          $this->db->query('update '.$this->tablename.' set '.$day.' = '.($res+1));
           return $res;
      }
      function disconnect()
      {
          $this->db->disconnect();
      }
  }
  ?>

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

アークウェブのサービスやソリューションはこちら