简体   繁体   English

安装PHP PEAR和MDB2后出现警告/致命错误require(MDB2.php)

[英]Warning /Fatal error require(MDB2.php) after install PHP PEAR and MDB2

I have successfully installed PEAR and MDB2 on my localhost . 我已经在本地主机上成功安装了PEAR和MDB2。 But when i am trying to run example code given by MDB2, i am getting error (In attached image) 但是,当我试图运行由MDB2给出的示例代码中,我得到错误(附图片)

Also Restarted Wamp server many times after installation. 安装后还会多次重启Wamp服务器。

Error and Warning 错误和警告

Warning: require(MDB2.php) : failed to open stream: No such file or directory in E:\\wamp\\www\\pear_project\\examples\\example_php5.php on line 8 警告: require(MDB2.php)未能打开流:在没有这样的文件或目录E:\\wamp\\www\\pear_project\\examples\\example_php5.php第8行

Fatal error: require() : Failed opening required 'MDB2.php' ( include_path='.;C:\\php\\pear' ) in E:\\wamp\\www\\pear_project\\examples\\example_php5.php on line 8 致命错误: require()无法所需'MDB2.php'开口( include_path='.;C:\\php\\pear' )在E:\\wamp\\www\\pear_project\\examples\\example_php5.php第8行

php.ini is default modified by go-pear during PEAR installation. PEAR安装过程中, go-pear默认修改了php.ini

;***** 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);    
?>

You should restart your web server whenever changes are made to php.ini, or they will not take effect. 只要对php.ini进行了更改,就应该重新启动Web服务器,否则它们将不会生效。

Your current configuration is looking in: include_path='.;C:\\php\\pear' however, your installation has this directory in: E:\\wamp\\bin\\php\\php5.4.12\\pear 您当前的配置正在查找: include_path='.;C:\\php\\pear'但是,您的安装目录位于: E:\\wamp\\bin\\php\\php5.4.12\\pear

After restarting your wampp installation, it should begin working. 重新启动wampp安装后,它应该开始工作。

I have solved this problem. 我已经解决了这个问题。 uninstall old WAMP and delete the rest wamp folder. 卸载旧的WAMP并删除其余的WAMP文件夹。 Then Fresh Install WAMP and PEAR. 然后重新安装WAMP和PEAR。 Modify environment variable with the PHP folder path. 使用PHP文件夹路径修改环境变量。

There is another php.ini in E:\\wamp\\bin\\apache\\Apache2.4.4\\bin E:\\ wamp \\ bin \\ apache \\ Apache2.4.4 \\ bin中还有另一个php.ini

Modify php.ini with the same include path 使用相同的包含路径修改php.ini

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

Install the Database Package MDB2, 安装数据库软件包MDB2,

and restart server. 并重新启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM