<html><head><title>Library Books</title></head>
<body>
<table border=1>
<tr><th>Book</th><th>Year Published</th><th>Author</th></tr>
<?php
// connect
require_once('DB.php');
$db = DB::connect("mysql://librarian:[email protected]/library");
if (DB::iserror($db)) {
die($db->getMessage());
}
// issue the query
$sql = "SELECT books.title,books.pub_year,authors.name
FROM books, authors
WHERE books.authorid=authors.authorid
ORDER BY books.pub_year ASC";
$q = $db->query($sql);
if (DB::iserror($q)) {
die($q->getMessage());
}
// generate the table
while ($q->fetchInto($row)) {
?>
<tr><td><?= $row[0] ?></td>
<td><?= $row[1] ?></td>
<td><?= $row[2] ?></td>
</tr>
<?php
}
?>
スクリプトを実行するにはどのようにDB.phpが必要ですか?データベースに接続 - スクリプトの提案ですか?
それは動作しません:あなたはDBクラスとスクリプトを呼び出しているすべてのメソッドを実装する必要があります事前
どのようなエラーが発生しますか? –
致命的なエラー:8行目のxxx.phpにクラス 'DB'が見つかりません – easyrider