【问题标题】:Warning /Fatal error require(MDB2.php) after install PHP PEAR and MDB2安装 PHP PEAR 和 MDB2 后需要警告/致命错误(MDB2.php)
【发布时间】:2014-05-21 19:54:08
【问题描述】:

我已经在我的 localhost 上成功安装了 PEAR 和 MDB2。 但是当我尝试运行 MDB2 给出的示例代码时,我得到了错误(在附图中)

安装后还多次重启 Wamp 服务器。

错误和警告

警告:require(MDB2.php):无法打开流:第 8 行的E:\wamp\www\pear_project\examples\example_php5.php 中没有此类文件或目录

致命错误:require():在第 8 行的E:\wamp\www\pear_project\examples\example_php5.php 中打开所需的“MDB2.php”(include_path='.;C:\php\pear')失败

php.iniPEAR 安装过程中默认由 go-pear 修改。

;***** Added by go-pear
include_path=".;E:\wamp\bin\php\php5.4.12\pear"
;*****

<?php

/**************************************/
/* a nice php5 only show case of MDB2 */
/**************************************/

require 'MDB2.php';

// the database needs to be created manually beforehand
$dsn = array(
    'phptype'  => 'mysql',
    'username' => 'root',
#    'phptype'  => 'mysql',
#    'username' => 'root',
    'password' => '',
    'hostspec' => 'localhost',
    'database' => 'driver_test',
);
#$dsn = 'sqlite:///:memory:';

// create MDB2 instance
$mdb2 = MDB2::factory($dsn);
if (MDB2::isError($mdb2)) {
    die($mdb2->getMessage());
}

// set the default fetchmode
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);

$fields = array(
    'id' => array(
        'type'     => 'integer',
        'unsigned' => true,
        'autoincrement'  => true,
    ),
    'somename' => array(
        'type'     => 'text',
        'length'   => 12,
    ),
    'somedate'  => array(
        'type'     => 'date',
    ),
);
$table = 'sometable';

// create a table
// since we are on php5 we can use the magic __call() method to:
// - load the manager module: $mdb2->loadModule('Manager', null, true);
// - redirect the method call to the manager module: $mdb2->manager->createTable('sometable', $fields);
$mdb2->mgCreateTable($table, $fields);

$query = "INSERT INTO $table (somename, somedate) VALUES (:name, :date)";
// parameters:
// 1) the query (notice we are using named parameters, but we could also use ? instead
// 2) types of the placeholders (either keyed numerically in order or by name)
// 3) MDB2_PREPARE_MANIP denotes a DML statement
$stmt = $mdb2->prepare($query, array('text', 'date'), MDB2_PREPARE_MANIP);
if (MDB2::isError($stmt)) {
    die($stmt->getMessage());
}

// load Date helper class
MDB2::loadFile('Date');

$stmt->execute(array('name' => 'hello', 'date' => MDB2_Date::mdbToday()));
// get the last inserted id
echo 'last insert id: ';
var_dump($mdb2->lastInsertId($table, 'id'));
$stmt->execute(array('name' => 'world', 'date' => '2005-11-11'));
// get the last inserted id
echo 'last insert id: ';
var_dump($mdb2->lastInsertId($table, 'id'));

// load Iterator implementations
MDB2::loadFile('Iterator');

$query = 'SELECT * FROM '.$table;
// parameters:
// 1) the query
// 2) true means MDB2 tries to determine the result set type automatically
// 3) true is the default and means that internally a MDB2_Result instance should be created
// 4) 'MDB2_BufferedIterator' means the MDB2_Result should be wrapped inside an SeekableIterator
$result = $mdb2->query($query, true, true, 'MDB2_BufferedIterator');

// iterate over the result set
foreach ($result as $row) {
    echo 'output row:<br>';
    var_dump($row);
}

// call drop table, since dropTable is not implemented in our instance
// but inside the loaded Manager module __call() will find it there and
// will redirect the call accordingly
// we could also have done:
//  $mdb2->manager->dropTable($table); or
//  $mdb2->mgDropTable($table);
$mdb2->dropTable($table);    
?>

【问题讨论】:

  • 对不起,只是不必要地删除了那个。重新启动您的网络服务器。您的文件正在:.;C:\php\pear 中查找您的 MDB2.php 文件,但它位于 .;E:\wamp\bin\php\php5.4.12\pear

标签: php pear


【解决方案1】:

每当对 php.ini 进行更改时,您都应该重新启动您的网络服务器,否则它们将不会生效。

您当前的配置正在查找:include_path='.;C:\php\pear' 但是,您的安装目录位于:E:\wamp\bin\php\php5.4.12\pear

重新启动 wampp 安装后,它应该开始工作了。

【讨论】:

  • 您确定您修改了正确的 php.ini 文件吗?使用 phpinfo() 找出 php.ini 文件的位置,并检查 php.ini 文件的包含路径。它似乎仍在使用: .;C:\php\pear 作为默认包含路径。当 wamp 清楚地安装在 E 驱动器上时,为什么会在 C:\php\pear 中查找?
【解决方案2】:

我已经解决了这个问题。 卸载旧的 WAMP 并删除其余的 wamp 文件夹。 然后全新安装 WAMP 和 PEAR。 使用 PHP 文件夹路径修改环境变量。

E:\wamp\bin\apache\Apache2.4.4\bin中还有一个php.ini

php.ini修改成相同的包含路径

;***** Added by go-pear
include_path=".;E:\wamp\bin\php\php5.4.12\pear"
;***** 

安装数据库包MDB2,

然后重启服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多