Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 连接到数据库-脚本建议? 图书馆图书 达索尔出版社_Php_Mysql_Oop - Fatal编程技术网

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>

要使脚本运行,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>
<?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", "***");
?>