Php 连接到数据库-脚本建议? 图书馆图书 达索尔出版社
要使脚本运行,DB.php应该是什么样子 这是行不通的:Php 连接到数据库-脚本建议? 图书馆图书 达索尔出版社,php,mysql,oop,Php,Mysql,Oop,要使脚本运行,DB.php应该是什么样子 这是行不通的: <html><head><title>Library Books</title></head> <body> <table border=1> <tr><th>Book</th><th>Year Published</th><th>Author</th></tr>
<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:passw0rd@localhost/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类和脚本调用的所有方法。根据粘贴的内容,
connect
,isError
,getMessage
,query
,以及fetchInto
。您并不是真的想编写自己的DB包装器
实际上,代码似乎正在尝试使用旧的
看看这个包裹。非常好。您会遇到什么错误?致命错误:在第8行的xxx.php中找不到类'DB'。谢谢,我会看一看,它确实是PEAR DB。
<?php
define("DB_SERVER", "localhost");
define("DB_NAME", "***");
define ("DB_USER", "***");
define ("DB_PASSWORD", "***");
?>