So, I'd like to use the LIKE operator in a SQL query with a php variable. Basically I need to check if 'serie_nb' begins with the number contained by the variable $bloc.
Here is my code:
public function getSeriesCount($bloc){
$like = (String)$bloc . '_';
$query = 'SELECT COUNT(*) AS countSeries FROM projet_web.series WHERE serie_nb LIKE ' . $like;
$result = $this->_db->query($query);
$countSeries = 0;
if ($result->rowcount() != 0){
$countSeries = $result->fetch();
}
return $countSeries;
}
And here is the error I get (which is caught when the query is executed):
Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '2_' in 'where clause'
I don't really see why I get that error...
Thanks for the help !