phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Database: Inputing Data to Database

Tag: framework, zend, zend framework, database, input   Category: PHP Framework
post: 12 Apr 2008 read: 2,259


Zend Framework Database Step By Step Tutorial - Part 3: After create form, now, we create action to input data to database. For this job, open "UserController.php" within application/controllers. Add a method named "processAction", with following code:

  public function processAction()
  {
  
    $params = array('host'		=>'localhost',
	                'username'	=>'root',
					'password'  =>'admin',
					'dbname'	=>'zend'
	               );
	$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
	
    $request = $this->getRequest();

	$sql = "INSERT INTO `user` 
			(`first_name` , `last_name` ,`user_name` ,`password`)
			VALUES 
			('".$request->getParam('first_name')."', '".$request->getParam('last_name')."', '".$request->getParam('user_name')."', MD5('".$request->getParam('password')."'))";
	$DB->query($sql);
	
    $this->view->assign('title','Registration Process');
	$this->view->assign('description','Registration succes');  	
	
  }

It is simple to understand it, isn't it?

Next, create view for this processAction. create a file named "process.phtml" within application/views/scripts/user

. Enter following code:

<? include "header.phtml"; ?>
  <h1><?=$this->escape($this->title);?></h1>
  <h2><?=$this->escape($this->description);?></h2>
  <a href="list">Member List</a>
<? include "footer.phtml"; ?>

Now, point your browser to http://localhost:8050/test/zend/helloworld/web_root/user/register. Then, enter a user information such as:

Click registration button. You will get like this:



Series this article:
Zend Framework Database: Intro
Zend Framework Database: Creating Input Form
Zend Framework Database: Inputing Data to Database
Zend Framework Database: Inserting Expressions to a table
Zend Framework Database: Creating List of Data
Zend Framework Database: Creating Editing Form
Zend Framework Database: Updating Data
Zend Framework Database: Updating Data Use Update Query From Zend Framework
Zend Framework Database: Deleting Data
Zend Framework Database: Delete Query Style
Zend Framework Database: Summarizing Action Controller

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

1 Responses to Zend Framework Database: Inputing Data to Database:

Hi,

I'm copying the information from your tutorials.

I'm on Zend Framework Database: Inputing Data to Database.

But I get this error:

Fatal error: Class 'Zend_Db_Adapter_Pdo_Mysql' not found in /home/lukechaf/public_html/application/controllers/UserController.php on line 29

Any ideas?

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting