dqp10099 2010-12-19 15:11
浏览 29
已采纳

未找到梨类DB类

I have create a class called Database.php for interacting with MySql database using Pear Db class.

Database.php

<?php 
require_once('DB.php');
require_once('cException.php');

class DataBase
{

    private $dsn = 'mysql://root:xxxxxx@localhost/avatar';
    private $conn;


    //Constructor
    function __construct() 
    {
        global $conn;
        $this->conn = DB::connect($dsn);
        if(DB::isError($conn))
        {
            throw new DatabaseConnectionException();
        }
    }

    //destructor
    function __destruct() 
    {
       $this->conn->disconnect();
    }

    public function select($query)
    {
        $conn->setFetchMode(DB_FETCHMODE_ASSOC);
        $result = & $conn->query($query);

        if(DB::isError($result))
        {
            return new SelectCommandException($result->getMessage());
        }

        return $result;
    }

    static public function instance()
    {
        static $objDB;

        if(! isset($objDB))
        {
            $objDB = new DataBase();
        }

        return $objDB;
    }
?>

And I am calling this class from a sample file test.php

test.php

<?php

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);


    require_once 'Database.php';

    try 
    {
        $db = DataBase::instance();
    }
    catch (DatabaseConnectionException $ex1)
    {
        echo $ex1->toString();
    }

    try 
    {
        $sql = "Select * from register";
        $result = $db->select($sql);
        var_dump($result);
    }
    catch (SelectCommandException $ex2)
    {
        echo $ex2->toString();
    }
?>

When I run test.php I get the following error

Warning: require_once(/usr/share/pear/DB.php): failed to open stream: No such file or directory in /var/www/Avatar/Database.php on line 2 Fatal error: require_once(): Failed opening required '/usr/share/pear/DB.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/Avatar/Database.php on line 2

I don't know why I am getting this error. In phpinfo() it shows include_path .:/usr/share/php:/usr/share/pear .:/usr/share/php:/usr/share/pear

I am using php5 and I even tried installing php-pear package, still I get the same error. I don't understand what's wrong here. Can someone please point me in a right direction.

Note : I have not installed php5 using sudo apt-get install php5. I have downloaded php5 packages using Keryx application.

  • 写回答

1条回答 默认 最新

  • dragon4587 2010-12-19 15:19
    关注

    Looks you did not install DB package, try in command prompt, do

    pear list
    

    If no package of DB is installed, you can installed it with

    pear install DB
    

    example from documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏