I have got an error in a php script:
PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 in /var/www/html/a.php:143
Pay attention it says near ''(two single quotations).
This script used to work correctly on my previous server but when I moved to the new server, it kept showing this error. My PHP version is 7.0 and Mysql version is 5.7.22.
How I connected to mysql:
try{
$pdo = new PDO("mysql:host=localhost;dbname=db_name", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
It prints: "Connected successfully". These are lines 142 and 143 which contain PDO queries:
$stmt = $pdo->prepare("SELECT has_paid FROM info WHERE chat_id=".$chat_id);
$stmt->execute();
I visited similar questions but they didn't help.
How can I solve this?