[問い合わせ] 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
(エラー全文、ここまで)

タイトルとURLをコピーしました