如何在核心php项目中使用Zend数据库类 -
我下载了ZendFramework-2.3.1 将Zend文件夹从其库文件夹中提取到我的项目库文件夹 -
PROJECTDIR / 图书馆 - Zend 的index.php
在index.php中我正在使用此代码 -
use library\Zend\Db\Adapter\Adapter ;
// use Zend\Db\Adapter\Adapter ; also tried this line
$adapter = new Adapter(array(
'driver' => 'Pdo_Sqlite',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
)
);
我也试过这个 -
$adapter = new Zend\Db\Adapter\Adapter(array(
'driver' => 'Pdo_Sqlite',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
));
$adapter = new \Zend\Db\Adapter\Adapter(array(
'driver' => 'Pdo_Sqlite',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
));
$adapter = new library\Zend\Db\Adapter\Adapter(array(
'driver' => 'Pdo_Sqlite',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
));
$adapter = new Adapter(array(
'driver' => 'Pdo_Sqlite',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
)
);
print_r($adapter) ;
致命错误:第25行的/var/www/pubcrawl/index.php中找不到类' Zend \ Db \ Adapter \ Adapter
任何帮助都将不胜感激。
谢谢, 阿布舍克巴克
答案 0 :(得分:0)
我解决了我的问题。通过ThiagoFrança在评论中提供的参考文献的帮助做到这一点 -
并且能够使用Pdo_Mysql作为驱动程序和表中的数据来连接数据库。
在项目目录的根目录下放置Zend文件夹 -
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister' => true));
$loader->setFallbackAutoloader(true);
// Register with spl_autoload:
$loader->register();
use Zend\Db\Adapter\Adapter ;
$adapter = new Zend\Db\Adapter\Adapter(array(
'driver' => 'Pdo_Mysql',
'hostname'=>'localhost',
'database' => 'pub_crawl',
'username' => 'root',
'password' => 'Micro123#'
));
$optionalParameters = array();
$sql = 'SELECT * FROM pubs' ;
$statement = $adapter->createStatement($sql, $optionalParameters);
$result = $statement->execute();
$row = $result->current() ; // for getting first record
希望它可以帮助别人。