A
A
Alexey Vasiliev2015-09-30 23:32:39
PHP
Alexey Vasiliev, 2015-09-30 23:32:39

How to display data from stored procedures in MySQL in PHP?

I have the following table in the database that describes categories with an infinite number of parents.
id, name, parent (where parent is the id of the parent category)
there is also a stored procedure that lists all categories as long as parent!=0, that is, as long as the category has no parent. The procedure has an input parameter - this is the id of the last element. (from it you need to bring the tree to the very top)

CREATE PROCEDURE `breadcrumbs`(IN cat INT)
BEGIN
    DECLARE i INT DEFAULT 0;
    WHILE cat!=0 DO
      SELECT * FROM category WHERE category.id=cat;
      SET cat=(SELECT category.parent FROM category WHERE category.id=cat);
    END WHILE;
  END;

If you run it in PHPMyAdmin, then such a query produces several resulting selections.
If you run it in PHP (CALL breadcrumbs(5)), then the result will always be the last selection, namely the category without a parent.
How to get these selections in PHP?
ps There must be a solution, because PHPMyAdmin somehow sees them!
pps multi_query tried...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Vasiliev, 2015-10-01
@FoasMat

Everything turned out to be trite ... There was a small error in the code above. And you can display the result of a MySQL stored procedure in PHP using a multi-query.
here is man: see 3 example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question