Reputation: 1
I try to do a simple SQL query in php but the WHERE clause is not working. If I remove the WHERE condition I get all the results and If I execute the query directly in the SQL Editor of the Database I get the correct response. What am I doing wrong?
$dbConnection = new PDO('mysql:dbname=XYZ;host=XYZ;', 'XYZ', 'XYZ');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$statement = $dbConnection->prepare("
SELECT produktId, datum_gebucht
FROM tric.lager_umbuchungen
WHERE datum_gebucht LIKE '2025-02-25 - 10:40:29'
");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
Structure:
produktid bigint(20)
datum_gebucht varchar(50)[1]
Example:
produktId datum_gebucht
5901341895 2025-02-25 - 10:40:29
Query I used in the Editor directly:
SELECT produktId, datum_gebucht
FROM lager_umbuchungen
WHERE datum_gebucht LIKE '2025-02-25 - 10:40:29'
Output of print_r($result)
Array ( )
Upvotes: 0
Views: 44