I am currently trying to execute some MySQL query and save the results into an array using bind_params for 2 params: userUniqueId (String) and limit (used to LIMIT query records). I've tried to do sth on my own but seems the code does not work properly. I've tried different ways to do that but still nothing. Can you try to help me? Query works fine cause I've tested it in phpMyAdmin The function I want to write must fetch records into and array and then I would like to json_encode that array using that array as a result of the function.
Here is my function code:
public function getUserFavouriteRecipes($user_unique_id, $limit) {
$stmt = $this->conn->prepare("SELECT recipe.`unique_id`, recipe.`title`, recipe.`img_tumbnail_link`, recipe.`add_date`, recipe.`kitchen_type`, recipe.`meal_type`, user.`name`, user.`surname`,
(SELECT count(*) from `like` WHERE recipe.`unique_id` = `like`.`recipe_unique_id_fk`) AS like_count
FROM `recipe`
JOIN `favourite` ON (recipe.`unique_id` = `favourite`.`recipe_unique_id_fk`)
JOIN `user` ON (recipe.`user_unique_id_fk` = user.`unique_id`)
WHERE favourite.`user_unique_id_fk` = ?
ORDER BY recipe.`add_date` DESC
LIMIT ?, 10");
$converted_limit = intval($limit);
$stmt->bind_param("si", $user_unique_id, $limit);
$result = $stmt->execute();
if ($result) {
$myArray = array();
// Fetching Rows From Query
while ($row = $result->get_result()->fetch()) {
$myArray[] = $row;
}
$stmt->close();
return $myArray;
} else {
return NULL;
}
}
Here I try do encode it:
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// Receiving The Post Params
$user_unique_id = $_POST['user_unique_id_fk'];
$limit = $_POST['limit'];
// Getting Result Array
$resultArray = $db->getUserFavouriteRecipes($user_unique_id, $limit);
echo json_encode($resultArray);
?>
Thanks in advance for your help.

[]as an aoutput which means the tabel is null inside.