02-03.phpのファイルの先頭でrequire_once(’02_01_b.php’);と、02-01_b.phpファイルを読み込んでいますが、この02-01_b.phpにも、
(ここまで)
が正しい内容です。
[問い合わせ] 4章でエラー多発する
185ページ、Chapter4のMySQLに関してうまく行きません。CDのデータをそのまま使用しても動きません。
【回答】
おそらくxamppバージョンの違いによるものだと思います。執筆中はxampp-1.6.7で確認しましたが、2011-11現在のxamppは1.7.7です。
下記xamppバージョンを試しました。
xampp-1.6.7 (xampp-win32-1.6.7-installer.exe)
xampp-1.6.8 (xampp-win32-1.6.8-installer.exe)
xampp-1.7.4 (xampp-win32-1.7.4-VC6.zip)
xampp-1.7.7 (xampp-win32-1.7.7-VC9-installer.exe)
添付CD-ROMのファイルをそのまま使い、修正していません。
————————————————————
xampp | DB作成~インポート | chapter4_6/index.php表示
————————————————————
1.6.7 OK OK
1.6.8 OK OK
1.7.4 OK ページ上部にエラー(※1)
1.7.7 OK ページ上部にエラー(※1)
————————————————————
※1 エラー表示の後、ページ下に本来のテーブルが表示された
(ファイルパスは読者様の環境に読み替えてください))
Deprecated: Assigning the return value of new by reference is deprecated in C:webxampp177ihtdocssmartybookchapter4_6index.php on line 30
Strict Standards: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in C:webxampp177ihtdocssmartybookchapter4_6CMS.class.php on line 16
(省略、最後にエラー全文を記載します)
■エラーを抑えるためにはphp設定を変更してしまうのが簡単です。
c:xamppphpphp.ini の 516行目を下記のように修正してください。
修正前
error_reporting = E_ALL | E_STRICT
修正後
error_reporting = E_ALL & ~E_DEPRECATED
修正したら apacheを再起動してください。
タスクトレイのXAMPPアイコンをダブルクリックしてください。
Apache 右側の[Stop]ボタンをクリックしてください。
約10秒待ってから、
Apache 右側の[Start]ボタンをクリックしてください。
■このエラーについて
以前のコードが最新phpでは推奨されないとして警告・エラーになる場合があります。
今回の例では、
chapter4_6/index.php : 30行目
$cms =& new CMS($CONFIG[‘dsn’]);
↓
$cms = new CMS($CONFIG[‘dsn’]);
PEAR::DB
PEAR::DBは非推奨、代わりにPEAR::MDBを推奨。
の箇所で警告・エラーが表示されました。
(エラー全文、ここから。ファイルパスは読者様の環境に読み替えてください。学習中にこれが表示されたら...どうしたらいいか困ってしまいますよね)
Deprecated: Assigning the return value of new by reference is deprecated in C:webxampp177ihtdocssmartybookchapter4_6index.php on line 30
Strict Standards: Non-static method DB::connect() should not be called statically, assuming $this from incompatible context in C:webxampp177ihtdocssmartybookchapter4_6CMS.class.php on line 16
Strict Standards: Non-static method DB::parseDSN() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 520
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 551
Strict Standards: Non-static method DB::errorMessage() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1899
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 688
Strict Standards: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARPEAR.php on line 871
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 557
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177ihtdocssmartybookchapter4_6CMS.class.php on line 17
Strict Standards: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 2195
Strict Standards: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 2195
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1217
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1292
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 1387
Strict Standards: Non-static method Pager::factory() should not be called statically in C:webxampp177ihtdocssmartybookchapter4_6index.php on line 34
Strict Standards: Non-static method DB::isManip() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 2195
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1217
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1666
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDB.php on line 1387
Strict Standards: Non-static method DB::isError() should not be called statically, assuming $this from incompatible context in C:webxampp177iphpPEARDBcommon.php on line 1683
(エラー全文、ここまで)
[問合せ] 2章、46ページで画像が表示されない
問合せ
2章、46ページの02_03.phpを表示すると、Studyでは、0001のデータしか表示されず、画像も表示されません。data.csvの行の最後に、「,(カンマ)」を入れると、画像が表示されました。Eating、Workでは、data.csvの内容は何も表示されません。
回答
data.csvの改行コードを CR にしたところ、問合せの状況を再現しました。テキストエディタでdata.csvを保存するとき、改行コードを CR+LF または LF で保存してください。
[問合せ] Pager.php や DB.php はどこにありますか
問合せ
4章6の chapter4_6/index.php のrequire_once(‘Pager.php’) の Pager.phpや、CMS.class.phpのrequire_once(‘DB.php’) のDB.phpがCD-ROMにありませんが、どこにありますか
回答
Pager.php、DB.phpともに、xamppについてきます。xamppをインストールすると、次の場所にあります。
c:xamppphpPEARPager.php
c:xamppphpPEARPager*.php
c:xamppphpDBDB.php
c:xamppphpDBDB*.php
[問合せ] PHP4で、4章6を正しく表示できない
問合せ
PHP4で、4章6の193ページを正しく表示できません。
回答
原因
chapter4_6/SortNavigator.class.phpで、http_build_query関数を呼んでいます。しかし、この関数はPHP5以降のため、PHP4ではエラーになります。
対策
php5func.zip をダウンロード、解凍して、chapter4_6/php5func.php にコピーしてください。
次に、chapter4_6/index.php を修正します。
(修正前)
require_once( './config.php' ); $smarty = new Smarty();
を、次のように赤太字の部分を挿入してください。
(修正後)
require_once( './config.php' );
if ( PHP_VERSION < "5" ) {
require_once( './php5func.php' );
}
$smarty = new Smarty();
PEAR::Net_UserAgent_Mobile用のi-mode機種情報xml
Smarty動的Webサイト構築入門の5.3 Smartyとケータイで、PEAR::Net_UserAgent_Mobileパッケージを使っています。このパッケージは外部ファイルからi-mode機種情報を読み込むことができます。本の付録CDROMに、筆者作成のdocomo_netuamobile.xmlを収録しました。
ところが、このdocomo_netuamobile.xmlには不具合があり、下から5~6行目の「SO902WP+」以降を正しく読み込みません。次の2点の修正が必要です。
1点目は、docomo_netuamobile.xmlです。「SO902WP+」ではなく、「SO902WPplus」とします。
2点目は、keitai_ini.phpを修正して、「SO902WP+」自体を認識できるようにします。SO902WP+の場合は、Net_UserAgent_Mobile内部の機種情報を使い、そうでない場合は、docomo_netuamobile.xmlを使うようにします。
修正前
7: $_SERVER[‘DOCOMO_MAP’] = dirname(__FILE__) . “/docomo_netuamobile.xml”;
8: $agent = &Net_UserAgent_Mobile::factory();
9: $display = $agent->getDisplay();
修正後
7: if ( ! preg_match(‘/SO902iWP[+]/’, $_SERVER[‘HTTP_USER_AGENT’]) ) {
8: $_SERVER[‘DOCOMO_MAP’] = dirname(__FILE__) . “/docomo_netuamobile.xml”;
9: }
10: $agent = &Net_UserAgent_Mobile::factory();
11: $display = $agent->getDisplay();
Smarty動的Webサイト構築入門
「Smarty動的Webサイト構築入門」が技術評論社から発売されました。原、青木、川野辺、鵜飼の共著で、私も執筆者の一人として参加しました。
本書はPHP上で動くテンプレートエンジン「Smarty」の解説書です。
Smartyを使った動的なサイトの構築方法から、応用テクニックまで幅広く説明します。
・テンプレートとは
・PHPの基礎
・Smartyの基礎
・CMSやブログの作成
・MySQLとphpMyAdmin
・Flashとの連携
・XMLの出力
・JavaScriptでフォトギャラリー
・ケータイ向けWebページ
・APIとの連携