Doctrine 2 - Stored procedures MySql #5733

Closed
opened 2026-01-22 15:15:55 +01:00 by admin · 3 comments
Owner

Originally created by @zbyyna on GitHub (Oct 10, 2017).

Originally assigned to: @lcobucci on GitHub.

Hello,
I apologize for new issue, but I don't know where to ask. I want to write to google group, but it is not possible add to new comment..

I am trying to work with stored procedures in Doctrine 2 in Symfony 3 and I have i problem with fetching data. This is my code in repository:

public function getParentCategoryByTypeId($type_id, LoggerInterface $logger){

 $rsm = new ResultSetMapping;
 $rsm->addEntityResult('AppBundle\Entity\Category', 'c');

 $logger->info('CALL get_category_by_type (type_id) IN()',array('i_type_id' => $type_id));

 $qb = $this->getEntityManager()->createNativeQuery(
 'CALL get_category_by_type ('.':type_id'.')', $rsm
 );
 $qb->setParameters(
 array(
 'type_id' => $type_id
 ));

 $res = $qb->getResult();

 $logger->info('CALL get_category_by_type () OUT()', array('result' => $res));

 return $qb;

}

Here is my procedure:

{
CREATE PROCEDURE get_category_by_type(IN type_id INT)
  BEGIN
    SELECT * FROM category As c WHERE c.parent IN (SELECT ct.category_id FROM category ct WHERE ct.type = type_id);
END;
}

Problem is, that $res returns null data. Can I ask for help with work with stored procedure? I would like to call the mysql procedures and fetching data in repository, than transmit whole SQL statement through
network. This solution is best for performance and organizability SQL code..It is possible working with stored procedures in Doctrine 2?

Thank you for any answer,
Zbyyna

Originally created by @zbyyna on GitHub (Oct 10, 2017). Originally assigned to: @lcobucci on GitHub. Hello, I apologize for new issue, but I don't know where to ask. I want to write to google group, but it is not possible add to new comment.. I am trying to work with stored procedures in Doctrine 2 in Symfony 3 and I have i problem with fetching data. This is my code in repository: ```php public function getParentCategoryByTypeId($type_id, LoggerInterface $logger){ $rsm = new ResultSetMapping; $rsm->addEntityResult('AppBundle\Entity\Category', 'c'); $logger->info('CALL get_category_by_type (type_id) IN()',array('i_type_id' => $type_id)); $qb = $this->getEntityManager()->createNativeQuery( 'CALL get_category_by_type ('.':type_id'.')', $rsm ); $qb->setParameters( array( 'type_id' => $type_id )); $res = $qb->getResult(); $logger->info('CALL get_category_by_type () OUT()', array('result' => $res)); return $qb; } ``` Here is my procedure: ```sql { CREATE PROCEDURE get_category_by_type(IN type_id INT) BEGIN SELECT * FROM category As c WHERE c.parent IN (SELECT ct.category_id FROM category ct WHERE ct.type = type_id); END; } ``` Problem is, that $res returns null data. Can I ask for help with work with stored procedure? I would like to call the mysql procedures and fetching data in repository, than transmit whole SQL statement through network. This solution is best for performance and organizability SQL code..It is possible working with stored procedures in Doctrine 2? Thank you for any answer, Zbyyna
admin added the Question label 2026-01-22 15:15:55 +01:00
admin closed this issue 2026-01-22 15:15:55 +01:00
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2017):

@zbyyna there are differences between a FUNCTION and a PROCEDURE, procedures can't return values.

@lcobucci commented on GitHub (Nov 26, 2017): @zbyyna there are differences between a `FUNCTION` and a `PROCEDURE`, procedures can't return values.
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2017):

But maybe you're looking for a VIEW instead?

@lcobucci commented on GitHub (Nov 26, 2017): But maybe you're looking for a `VIEW` instead?
Author
Owner

@lcobucci commented on GitHub (Nov 26, 2017):

Closing since the question has been answered, please re-open if you feel the need of discussing it further.

@lcobucci commented on GitHub (Nov 26, 2017): Closing since the question has been answered, please re-open if you feel the need of discussing it further.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5733