I would like to call mysql stored procedure with two in parameters say from and to and print the data in table. I have used the following code:
try
{
$age_from = $_POST['from'];
$age_to = $_POST['to'];
$stmt = $db->prepare("CALL proc_report_filtered(:age_from,:age_to)");
$stmt->bindParam(':age_from',$age_from);
$stmt->bindParam(':age_to',$age_to);
$records = $stmt->execute();
$records->setFetchMode(PDO::FETCH_ASSOC);
}
catch (PDOException $e)
{
die("Some problem getting data from database !!!" . $e->getMessage());
}
Later I used while loop as before to print the table data.
while ( $report = $records->fetch() )
Stored routine proc_report_filtered is a simple query to fetch data between the age range as follows:
select * from employee where age in between 30 and 40;
where 30 is $age_from and 40 is $age_to passed to stored routine.
Unfortunately the code doesnt work. Please correct me where I am going wrong. I am new to using php PDO.