0

I want to make an output that shows in a table.

I made a stored procedure:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `studentlist`(OUT `v_stuid` VARCHAR(10), OUT `v_stuname` VARCHAR(100), OUT `v_status` VARCHAR(20), OUT `v_email` VARCHAR(40), OUT `v_contact` VARCHAR(20), OUT `v_address` VARCHAR(100), OUT `v_class` VARCHAR(20))
begin
DECLARE v_stuid varchar(10);
DECLARE v_stuname varchar(100);
DECLARE v_status varchar(20);
DECLARE v_email varchar(40);
DECLARE v_contact varchar(20);
DECLARE v_address varchar(100);
DECLARE v_class varchar(20);
DECLARE My_Cursor CURSOR FOR 
select studentid,student_name,status,email,contact,address,classname
from student;
OPEN My_Cursor;
FETCH My_Cursor INTO v_stuid,v_stuname,v_status,v_email,v_contact,v_address,v_class;
CLOSE My_Cursor;
END$$
DELIMITER ;

and when I tried to run it in my PHP with this code:

$conn = mysqli_connect('localhost', 'root', '', 'student');

//run the store proc
$sql = "CALL STUDENTLIST(@out,@out,@out,@out,@out,@out,@out)";
$result = mysqli_query($conn,$sql) or die( mysqli_error($conn));

//loop the result set
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo 
"<tr>
<td>" .$row[0]."</td>
<td>".$row[1]."</td>
<td>".$row[2]."</td>
<td>".$row[3]."</td>
<td>".$row[4]."</td>
<td>".$row[5]."</td>
<td>".$row[6]."</td>

......

I get this error Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given at the while ($row....) statement.

I think it might relate with my stored procedure but I can't figure what's wrong with it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
K.G
  • 33
  • 6
  • You should not give parameters the same names as declared variables (or vice-versa) – P.Salmon Jun 07 '20 at 14:03
  • The Warning means your MySQL Link is not available (anymore) - many times its `MySQL server has gone away (error 2006)`. Use `var_dump($result)` after the mysqli_query to see what the variable type is – ChrisG Jun 07 '20 at 15:16

0 Answers0