© 2013 All rights reserved.
0

PHP: Zend framework and Oracle cursors

Working with Oracle cursors is in Zend very limited. There is only a simple class Zend_Db_Cursor_Oracle that can handle SQL query and return the whole result.

cursorsoracle

In more complicated situations, we need to bind multiple variables, returning only part of the result, etc..

We will customize class Zend_Db_Adapter_Oracle and prepare to the processing cursors

In first step we will prepare functions which execute query:

This function will prepare and execute sql query with cursors. Function execCursor have three parameters:

  • $sql – sql query with cursor
  • $cursor_name – cursor name
  • $bind = array() – variables to binding

In next step we can write functions to return result from sql query. We will prepare four functions for this time:

  • fetchCursorWithLimit – Execute the query and returns data in the limit
  • fetchCursorPairs – Execute the query and returns the data pairs in the limit
  • fetchCursorSingle – Returns the first record of the result
  • fetchCursor – Return the first record

example of the use

Execute the sql query and returns the first record of the result:

Execute the sql query and returns the data pairs in the limit (from 20, limit 10)

The solution again

Comments are closed for this page

About
Hi, i am programmer from the Czech Republic. I love web development (Ruby, Ruby on Rails, PHP, Nette) and iOS development (Objective-C, Cocoa).
To cooperate, here is my phone:
+420 608 836