Jump to content

Fulltext search of mySql database using PDO - apostrophe in string


blizzardofozz

Recommended Posts

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();
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.