Zendframework project Environment, after looking at the next Zend Framework configuration operation database, PHP tutorial is as follows:
Create a Config.ini file under the Application/configs file
configuration information is as follows:
[General]
Db.adapter=pdo_mysql
Db.config.host=localhost/iparess
Db.config.username=username
Db.config.password=password
Db.config.dbname=databasename
2,
In the index.php page of the PULIBC directory
/** zend_application * *
Require_once ' zend/application.php ';
Insert Below
Set the Datase config
Require_once ' zend/config/ini.php ';
Require_once ' zend/registry.php ';
Require_once ' zend/db.php ';
Require_once ' zend/db/table.php ';
$config =new Zend_config_ini ('./.. /application/configs/config.ini ', NULL, true);
Zend_registry::set (' config ', $config);
$dbAdapter =zend_db::factory ($config->general->db->adapter, $config->general->db->config-> ToArray ());
$dbAdapter->query (' SET NAMES UTF8 ');
Zend_db_table::setdefaultadapter ($dbAdapter);
Zend_registry::set (' Dbadapter ', $dbAdapter);
In this regard, I use my local wordpress database to test, use the Wp_posts table to test it:
First, model models establish wp_posts.php
Copy Code code as follows:
<?php
Class Wp_posts extends zend_db_table{
protected $_name = ' wp_posts ';
protected $_primary = ' ID ';
}
?>
Controller controller The following set up indexcontroller.php
Copy Code code as follows:
<?php
Require_once Application_path. ' /models/wp_posts.php ';
Class Indexcontroller extends Zend_controller_action
{
Public Function init ()
{
/* Initialize Action Controller Here * *
}
Public Function indexaction ()
{
$con = new Wp_posts ();
$res = $con->fetchall ()->toarray ();
$this->view->res = $res;
$this->render ("index");
}
}
To create a view in views/scripts/index/: index.phtml
Copy Code code as follows:
<title>this is for test</title>
<body>
<table>
<?php foreach ($this->res as $news) {?>
<tr>
<td><?php echo $news [' ID ']?></td>
<td><?php echo $news [' Post_title ']?></td>
<td><?php echo $news [' Post_date ']?> </td>
</tr>
<?php}?>
</table>
</body>
OK, the browser shows: