blizzardofozz Posted January 12, 2012 Share Posted January 12, 2012 Can you please help me on this?: I have a method of a class that uses PDO to search mysql database and it works but the problem is with apostrophe in a search string - it shows “Syntax error or access violation: 1064”. When single or double quotes in the string the script works fine – no slashes and no errors. This is the case when the site is on local WAMPSERVER 2.1. When I put the same site on a live server the characters (apostrophe, quotes) are escaped with slashes? Even if I use PDO? Any ideas why? public static function searchstring($per_page=0, $pg_offset=0, $search=0){ global $database; $sql = "SELECT * FROM tablename WHERE MATCH (fieldname) AGAINST (:searchstr IN BOOLEAN MODE) LIMIT {$per_page} OFFSET {$pg_offset}"; try { $database->prepare($sql); $database->bindParam(':searchstr', $search); $database->execute(); $result_array = $database->fetch_array($sql); return $result_array; } catch (Exception $e) { echo $e->getMessage(); } } Quote Link to comment https://forums.phpfreaks.com/topic/254893-fulltext-search-of-mysql-database-using-pdo-apostrophe-in-string/ Share on other sites More sharing options...
Pikachu2000 Posted January 12, 2012 Share Posted January 12, 2012 Check to make sure magic_quotes_gpc is off in your php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/254893-fulltext-search-of-mysql-database-using-pdo-apostrophe-in-string/#findComment-1307019 Share on other sites More sharing options...
fenway Posted January 12, 2012 Share Posted January 12, 2012 Post the raw SQL. Quote Link to comment https://forums.phpfreaks.com/topic/254893-fulltext-search-of-mysql-database-using-pdo-apostrophe-in-string/#findComment-1307022 Share on other sites More sharing options...
blizzardofozz Posted January 12, 2012 Author Share Posted January 12, 2012 Thanks Pikachu2000, magic_quotes_gpc is ON and probably this is the reason it behaves differently when site is on the hosting server. The script, which I posted above works fine, there was an error in other function. Sorry if I have wasted your time. Quote Link to comment https://forums.phpfreaks.com/topic/254893-fulltext-search-of-mysql-database-using-pdo-apostrophe-in-string/#findComment-1307029 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.