谁只使用PERA的DB类?

时间:2011-11-15 20:26:02

标签: database pear connect

我想只使用PEAR DB类,我尝试按照:

$pearPfad ="PEAR_DB-1.7.14/DB-1.7.14/DB.php";

error_reporting(E_ALL);
require_once($pearPfad);

$DB_dbType ="mysql";
$DB_user = "myuser";
$DB_pass = "mypassword";
$DB_host = "localhost";
$DB_dbName ="mydatabase";

$dsn = $DB_dbType . "://"       // Build a DSN string (Data Source Name)
        . $DB_user . ":"        // Required by DB::connect()
        . $DB_pass . "@"
        . $DB_host . "/"
        . $DB_dbName;

$db = DB::connect($dsn, TRUE);

if (DB::isError($db)) {
    die("FEHLER: ".$db->getMessage() );
}  
$sql = "SELECT id, title , created FROM h1z4e_content";
$res = $db->query($sql);

if (DB::isError($res)) {
    die($res->getMessage());
}

while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
    if (DB::isError($row)) {
    die($row->getMessage());
    }

    print ("<p>Hey, it s:<br />" . $row->id . " " . $row->title . " ... and their freaky et: " . $row->created. "</p>\n");
}

    $res->free();
    // Similar to: mysql_free_resul

$db->disconnect();

但是我收到了这个错误:

  

警告:require_once(PEAR.php):无法打开流:第30行/var/www/PEAR/PEAR_DB-1.7.14/DB-1.7.14/DB.php中没有此类文件或目录致命错误:require_once():在/var/www/PEAR/PEAR_DB-1.7.14/DB-中打开所需的'PEAR.php'(include_path ='。:/ usr / share / php:/ usr / share / pear')失败第14行1.7.14 / DB.php

我在Stack Overflow中找到了这个链接:PHP-PEAR require_once('DB.php');

我不想在我的电脑上安装PEAR 我只想要用户PEAR DB类,这可能没有安装PEAR吗?

1 个答案:

答案 0 :(得分:0)

是的,但您需要正确设置包含路径 - 在您的情况下,设置为/full/path/to/PEAR_DB-1.7.14/DB-1.7.14/