I just upgraded to PHP 5.2 and the following query doesn’t seem to work anymore. I just get an error that there is an error in the syntax. Any clue why, or how to fix it?
try{
$db = DB::getInstance ();
$sql = "SELECT *
FROM view_names
WHERE name NOT Like :myname
";
$stmt = $db->query($sql);
$stmt->bindParam (':myname', $name, PDO::PARAM_STR );
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}catch(PDOException $e){
echo $e->getMessage();
}
When I use phpMyAdmin the query works, but it doesn’t work in the code. I checked and the $name variable does have a value.
I get this error - “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 ‘:myname’ at line 50”
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 ‘:myname’ at line 50
I have only ever used LIKE and when doing so, you need to surround the value/variable with ‘%these jobbies%’
Say for example you want to find a word that is like ‘sday’, well to find those which end in ‘sday’ you would use ‘%sday’ so you would get back Tuesday, Wednesday Thursday.
And if you want to find words beginning with ‘Mon%’, the % goes at the end, where #mon’ would join with ‘ney’ or ‘day’ giving money and monday, for example.
like this
select col_name
from table where col_name like '%sday'
I imagine that not like would work similarly so give it a try, if you like.
Oh, I should’ve said that instead of the :myname, use ‘myname’ and add the % to the end if you want to find ‘mynameis%’ or some other words, where there are characters after the inputted word.