I am new to Zend framework.I have tried database connection on each particular page in action method of controller its working fine.
I am using WAMP server, but now I want to learn database connection class on one page.and using that on different different action method. I want a connection made on index page and using at the all pages of project.
This is my action method in controller:
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();
}
and application.ini file is below in which i add only database adapter setting in this file
[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