Databases Reference
In-Depth Information
$view = Zend::registry('view');
if ($movie_name)
$db → addMovie($movie_name);
if ($votevalue)
$db → updateVote($votevalue);
$view → sum = $db → showVote();
$view → result = $db → showData();
echo $view → render('vote.php');
}
}
?>
Note: indexAction() in the controllers other than indexController should never
be called. Because you do not have any control over the user being creative
and modifying the URL to access anything, you should always redirect the
URL appropriately. Also, in order to support dynamic actions, such as
add/123, you must implement __call() functions.
3.4.1 Integrating with databases: Zend_Db_Adapter
Zend_Db_Adapter is the database API abstraction layer for the Zend
Framework. You can use same Zend_Db_Adapter to connect to and work with
many databases, including MySQL, DB2, Sybase, SQL Server, and others. You
first need to create an instance of your database server. The code shown in
Example 3-10 shows how to create the instance of DB2 database.
Example 3-10 Creating instance of DB2 database using Zend_Db_Adapter
$params = array('host' => '9.30.76.201',
'port' => '50000',
'username' => 'db2admin',
'password' => '********',
'dbname' => 'movie');
$conn = Zend_Db::factory('Db2', $params);
You can ignore the host and port parameters if the DB2 server is local to the
framework. Once a DB2 instance is created, it can be passed to the database
class being initialized. For our sample application, we create a Database class
database.php. The code shown in Example 3-11 on page 112 creates an
instance of the database class and makes our database object available through
the registry variable. A registry is a Zend framework object that can save
Search WWH ::




Custom Search