We were wondering if anyone can help us with a query regarding Symfony2/Doctrine2.
We use Oracle as our database for applications and we have started to experiment with using Symfony 2 and Doctrine for new projects with the view to moving away from Zend Framework 1 – however we have hit a small problem. Most of the database interaction involves calling procedures which return cursors; unfortunately we currently haven’t found a way in Doctrine to utilize cursors as we would with using Zend DB (custom written statement, cursor and execution classes to wrap standard oci8 features).
Has anyone successfully used cursors with Doctrine and if so would they mind posting some pointers? This is how we implement them in oci8; however with no native access to the connection resource property we cannot use this method without extending / creating a new class to allow this.
Code has been omitted for readability!
$oc = oci_connect($user,$pw,$tns);
$var = null;
$cur = null;
$stmt = "BEGIN schema.package.procedure(:var_in, :cur_out); END;";
$stid = oci_parse($oc, $stmt);
$cur = oci_new_cursor($oc);
oci_bind_by_name($stid, ':VAR_IN', $var);
oci_bind_by_name($stid, ': CUR_OUT', $cur, -1, OCI_B_CURSOR);
oci_execute($stid);
// Now treat the cursor as a statement resource
oci_execute($cur, OCI_DEFAULT);
oci_fetch_all($cur, $result, null, null, OCI_FETCHSTATEMENT_BY_ROW);
oci_free_statement($stid);
oci_close($oc);
//use $result for processing….
var_dump($result);
Many Thanks
I have found zero information about Doctrine2 supporting cursors in OUT parameters.
You can get connection resource from the container, but it's not recommended to use it directly.
// assuming you're in a controller
$this->get('database_connection')->getWrappedConnection();
For Oracle connections you could use ZendDB. There's a nice wrapper for Symfony2: