首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装PEAR和/Fatal后警告MDB2错误要求(MDB2.php)

安装PEAR和/Fatal后警告MDB2错误要求(MDB2.php)
EN

Stack Overflow用户
提问于 2014-05-21 19:54:08
回答 2查看 1.7K关注 0票数 0

我已经成功地在我的本地主机上安装了PEAR和。但是当我试图运行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.ini默认由go-pear在安装过程中修改.

代码语言:javascript
复制
;***** Added by go-pear
include_path=".;E:\wamp\bin\php\php5.4.12\pear"
;*****

代码语言:javascript
复制
<?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);    
?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-23 17:32:25

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

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

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

代码语言:javascript
复制
;***** Added by go-pear
include_path=".;E:\wamp\bin\php\php5.4.12\pear"
;***** 

安装数据库包MDB2,

重新启动服务器。

票数 0
EN

Stack Overflow用户

发布于 2014-05-21 20:30:52

无论何时对php.ini进行更改,您都应该重新启动web服务器,否则这些更改将不会生效。

您的当前配置正在查看:include_path='.;C:\php\pear',但是您的安装在:E:\wamp\bin\php\php5.4.12\pear中有以下目录

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23792590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档