I'm doing a SQL that counts how many names in the table begin with any letter but an error is being returned:
Column not found: 1054 Unknown column 'A' in 'where clause'
For the following SQL:
SELECT COUNT(*) FROM author WHERE name LIKE 'A%';
Excuting directly on the MySQL console works fine, but when using PDO, error 1054 is returned.
$count = 'SELECT COUNT(*) FROM author WHERE name LIKE \'' . $consulta->letter . '%\'';
echo $count; //Resultado : SELECT COUNT(*) FROM author WHERE name LIKE 'A%'
$stmt = $conn->prepare($count);
Note: I am using PDO
and Mysql
.