拡張子:txtvbswsfjsphpjavahtmlutf8sjis MVC は、MODEL、VIEW、CONTROL を意味する WEB アプリケーションを作成する 時の基本的な考え方です。 global は、ブロック内で最も上位で定義された変数を参照する方法です。 他の言語では、何もしなければグローバルを参照しますが、 PHP では、ローカルを参照するので注意が必要です control.php 拡張子:txtvbswsfjsphpjavahtmlutf8sjis <? # ********************************************************** # 初期処理 # ********************************************************** header( "Content-Type: text/html; Charset=EUC-JP" ); header( "Expires: Wed, 31 May 2000 14:59:58 GMT" ); require_once( "model.php"); require_once( "http://lightbox.in.coocan.jp/gen/db.txt"); $conf_db_type = 1; $SQL = new DB( "サーバー","DB","ユーザー","パスワード" ); $SQL->Debug = true; # ********************************************************** # 主処理 # ********************************************************** counter_action(); if ( $_GET['send'] == "送信" ) { counter_update(); } # ********************************************************** # 画面定義 # ********************************************************** require_once( "view.php"); $SQL->Close(); ?> model.php 拡張子:txtvbswsfjsphpjavahtmlutf8sjis <? # ********************************************************** # アクセスカウンタの表示データの取得処理 # ********************************************************** function counter_action() { global $SQL,$OUT_DATA; $Query = "update acounter set PAGE_COUNT = PAGE_COUNT + 1"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $SQL->Execute( $Query ); $ret = mysql_affected_rows( $SQL->Connect ); if ( $ret == 0 ) { $Query = "insert into acounter (PAGE_NAME,PAGE_COUNT)"; $Query .= " values('NEW_PAGE',1)"; $SQL->Execute( $Query ); } $Query = "select * from acounter"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $Column = $SQL->QueryEx( $Query ); $OUT_DATA = $Column["PAGE_COUNT"]; } # ********************************************************** # アクセスカウンタの表示データの更新処理 # ********************************************************** function counter_update() { global $SQL; $Query = "update acounter set PAGE_COUNT = {$_GET["counter"]}"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $SQL->Execute( $Query ); } ?> view.php
MVC は、MODEL、VIEW、CONTROL を意味する WEB アプリケーションを作成する 時の基本的な考え方です。 global は、ブロック内で最も上位で定義された変数を参照する方法です。 他の言語では、何もしなければグローバルを参照しますが、 PHP では、ローカルを参照するので注意が必要です
<? # ********************************************************** # 初期処理 # ********************************************************** header( "Content-Type: text/html; Charset=EUC-JP" ); header( "Expires: Wed, 31 May 2000 14:59:58 GMT" ); require_once( "model.php"); require_once( "http://lightbox.in.coocan.jp/gen/db.txt"); $conf_db_type = 1; $SQL = new DB( "サーバー","DB","ユーザー","パスワード" ); $SQL->Debug = true; # ********************************************************** # 主処理 # ********************************************************** counter_action(); if ( $_GET['send'] == "送信" ) { counter_update(); } # ********************************************************** # 画面定義 # ********************************************************** require_once( "view.php"); $SQL->Close(); ?>
<? # ********************************************************** # アクセスカウンタの表示データの取得処理 # ********************************************************** function counter_action() { global $SQL,$OUT_DATA; $Query = "update acounter set PAGE_COUNT = PAGE_COUNT + 1"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $SQL->Execute( $Query ); $ret = mysql_affected_rows( $SQL->Connect ); if ( $ret == 0 ) { $Query = "insert into acounter (PAGE_NAME,PAGE_COUNT)"; $Query .= " values('NEW_PAGE',1)"; $SQL->Execute( $Query ); } $Query = "select * from acounter"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $Column = $SQL->QueryEx( $Query ); $OUT_DATA = $Column["PAGE_COUNT"]; } # ********************************************************** # アクセスカウンタの表示データの更新処理 # ********************************************************** function counter_update() { global $SQL; $Query = "update acounter set PAGE_COUNT = {$_GET["counter"]}"; $Query .= " where PAGE_NAME = 'NEW_PAGE'"; $SQL->Execute( $Query ); } ?>