I can’t seem to wrap my head around this, I can’t find where the issue lays.
My code works perfectly fine without the bind_param, however, with it, it keeps throwing out a 500 Error (Internal Server Error).
$connect = new PDO('mysql:host=localhost;dbname=db', 'root', '');
$data = array();
$query = "SELECT * FROM `events` WHERE `user_id`=? ORDER BY `id`";
$statement = $connect->prepare($query);
$statement->bind_param('i', $user_id); // casts error. Without it it works perfectly.
$user_id = $this->session->userdata('user_id'); // I've tested it and it works, it returns the correct id.
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$data[] = array(
'id' => $row["id"],
'title' => $row["title"],
'start' => $row["start_event"],
'end' => $row["end_event"]
);
}
if ($_SERVER['REQUEST_METHOD'] == "GET") { echo json_encode($data); }
The issue shall be somewhere in the SQL, the other code works just fine.