我是 Zend 框架的新手。我在控制器的操作方法中尝试了每个特定页面上的数据库连接,它工作正常。
我正在使用 WAMP 服务器,但现在我想在一页上学习数据库连接类。并在不同的不同操作方法上使用它。我想在索引页面上建立连接并在项目的所有页面上使用。
这是我在控制器中的操作方法:
public function userAction()
{
$db = Zend_Db_Table::getDefaultAdapter();
$data = array(
'first_name' => 'xyz',
'last_name' => 'xyz',
'user_name' => 'xyz',
'password' => 'xyz'
);
$rows_affected = $db->insert('user', $data);
$last_insert_id = $db->lastInsertId();
}
和 application.ini 文件在下面,我在此文件中仅添加数据库适配器设置
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.db.adapter = "PDO_MYSQL"//adapter
resources.db.params.host ="localhost" //server name here or host
resources.db.params.username = "root"///username here
resources.db.params.password = "" //database password
resources.db.params.dbname = "zend"//database name
resources.db.isDefaultTableAdapter = true
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1