4

I've updated this question as a perplexing new twist to the problem has shown up.

MySQL is not handling hyphens or braces correctly.

SELECT * FROM users WHERE MATCH(firstname, lastname, about) AGAINST('-' IN BOOLEAN MODE) 

returns

syntax error, unexpected $end 

enter image description here

The same thing happens if I enter a ( or ). I know it's only those because entering anything else such as test works just fine

I'm on MySQL 5.7.4M

---UPDATE---
This error disappears if I switch from InnoDB to MyISAM. Is this a bug with the relatively new FULLTEXT support in InnoDB?


------OLD Question----
I'm implementing a "search users" feature in my application built off of Laravel and PHP, and I'm making use of the fulltext search in MySQL. Laravel not having a function for this, I used a basic DB::select() to get the job done. The problem is that while it is using a prepared statement, it's acting like it isn't (kinda).

My Code:

return DB::select("SELECT * FROM users WHERE MATCH(firstname,lastname,about) AGAINST(? IN BOOLEAN MODE)", array($query));

FYI for those who want to know, this is the DB::select() function

public function select($query, $bindings = array())
    {
        return $this->run($query, $bindings, function($me, $query, $bindings)
        {
            if ($me->pretending()) return array();

            // For select statements, we'll simply execute the query and return an array
            // of the database result set. Each element in the array will be a single
            // row from the database table, and will either be an array or objects.
            $statement = $me->getReadPdo()->prepare($query);

            $statement->execute($me->prepareBindings($bindings));

            return $statement->fetchAll($me->getFetchMode());
        });
    }

However, if I put in something like: -- (to emulate a comment in a mysql injection), I get the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 syntax error, unexpected '-'

I know it's only stuff like this, as putting in Test or Hello World works perfectly fine.

Kevin Pei
  • 5,800
  • 7
  • 38
  • 55
  • the error message is hardly googleable. Is it complete? Can't you try the same query in console, adding $query content to the query directly? – Your Common Sense Apr 01 '14 at 21:06
  • @YourCommonSense, I've updated the question with a query to the console – Kevin Pei Apr 01 '14 at 21:19
  • at least there are wrong quotes on the screenshot – Your Common Sense Apr 01 '14 at 21:32
  • @YourCommonSense those same wrong quotes execute successfully with `test` or any other input. It's just windows font rendering – Kevin Pei Apr 01 '14 at 21:33
  • Then use *stable* build – Your Common Sense Apr 01 '14 at 21:38
  • @YourCommonSense tried, same thing on stable 5.6 – Kevin Pei Apr 01 '14 at 21:38
  • the error nessages you are getting are highly unusual. especially from a screen... Heck. It's april fools question – Your Common Sense Apr 01 '14 at 21:41
  • @YourCommonSense I wish. Perhaps the error will disappear magically tomorrow. But the fact being that it's not working on 5.7 on my local machine nor 5.6 stable on my server, I doubt it's april fools :P. – Kevin Pei Apr 01 '14 at 21:42
  • @YourCommonSense I've updated my question slightly, only appears on InnoDB. Switch to MyISAM and it works – Kevin Pei Apr 01 '14 at 21:47
  • I've just run into the same error Kevin, on MariaDB 10.3.11. Disappears if I remove `IN BOOLEAN MODE`. Did you find any useful information on this error? I can work around it, but it's odd that it doesn't seem to be documented anywhere! – Codemonkey Dec 04 '18 at 16:41
  • https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Expected behaviour it seems. My fix: `$term = str_replace(['~', '"', '<', '>', '@', '-', '+', '*', '(', ')'], '', $term);` (I then add a plus sign in front of every word as that's the behaviour I want) – Codemonkey Dec 04 '18 at 17:01

1 Answers1

0

If it's not you, then it's someone else is joking on you.
But mysql error that looks like exactly as PHP syntax error is quite evident

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • It's not a PHP error, it IS a MySQL error: https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html Why does it have a dollar sign in it? No idea, but it definitely comes from MySQL, not PHP. Command line mysql returns it, for example. – Codemonkey Dec 04 '18 at 17:02