I’m working on a Telegram bot project and running into issues when trying to fetch information from my MySQL database.
I have a database table called university
with three columns: event_date
, weekday
, and classes
. My goal is to retrieve today’s class schedule from this table and send it to users through the bot.
Here’s the database code I’m using:
<?php
// Database connection setup
$connection = new mysqli('host', 'username', 'password', 'database_name');
// Get current date
$today = date('Y-m-d');
// Query to fetch schedule data
$sql = "SELECT classes FROM university WHERE `event_date` = '$today'";
$result = $connection->query($sql);
$data = $result->fetch_assoc();
// Bot response logic
if($userMessage == "schedule")
{
$currentDate = date('Y-m-d');
$response = $data;
sendTelegramMessage($userId, $response);
}
The bot responds to other commands fine, but when it tries to pull data from the database, nothing gets sent back to the user. I’ve double checked my database connection settings and the table has data for today’s date. Can anyone spot what might be causing this issue?