2014-05-21 112 views
0

我已經在我的本地主機上成功安裝了PEAR和MDB2。 但是,當我試圖運行由MDB2給出的示例代碼時,我得到錯誤(在附圖中)安裝PHP PEAR和MDB2後警告/致命錯誤要求(MDB2.php)

也安裝後多次重新啓動Wamp服務器。

錯誤和警告

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

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

php.ini中是默認期間PEAR安裝通過去梨修改。

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

enter image description here

<?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);  
?> 
+0

對不起,剛刪除不必要的。重啓你的網絡服務器。您的文件正在查找:。; C:\ php \ pear爲您的MDB2.php文件,但位於。; E:\ wamp \ bin \ php \ php5.4.12 \ pear –

回答

0

我已經解決了這個問題。 卸載舊的WAMP並刪除剩下的wamp文件夾。 然後新鮮安裝WAMP和PEAR。 使用PHP文件夾路徑修改環境變量。

有一個在Ë另外的php.ini:\ WAMP \ BIN \ apache的\ Apache2.4.4 \ BIN

修改php.ini與同包括路徑

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

安裝數據庫軟件包MDB2 ,

並重新啓動服務器。

0

您應該重新啓動您的Web服務器時更改爲php.ini做,否則將不能生效。

您當前的配置在尋找:include_path='.;C:\php\pear' 然而,系統中安裝了此目錄中:E:\wamp\bin\php\php5.4.12\pear

重新啓動wampp安裝完畢後,應該開始工作。

+0

已經嘗試過。 –

+0

你確定你修改了正確的php.ini文件嗎?使用phpinfo()來找出php.ini文件的位置,並檢查包含路徑的php.ini文件。它似乎使用:。; C:\ php \ pear作爲默認包含路徑。無論如何,在E Drive上明確安裝wamp時,爲什麼會在C:\ php \ pear中查找? –