1

I'm modifying a plugin of the "Question2Answer" script, and after activating a plugin, I get the following error:

MySQL query error HY093: SQLSTATE [HY093]: Invalid parameter number: number of bound variables does not match number of tokens - Query: SELECT COUNT(event) FROM qa_eventlog WHERE datetime >= FROM_UNIXTIME(? ) AND ((userid = ? AND event LIKE "in_%") OR (event IN ("u_message", "u_wall_post") AND params LIKE "userid=?\t%"), referer: http://rankeo.test/index.php?qa=questions

The function where you produce such code, is like this:

private function getEventCount($last_visit, $userid)
        {
            $currentTime = (int)qa_opt('db_time');
            $maxageTime = $currentTime - (int)qa_opt('q2apro_onsitenotifications_maxage') * 86400;
            $fromTime = max($maxageTime, $last_visit);

            $eventlogCount = qa_db_read_one_value(qa_db_query_sub(
                'SELECT COUNT(event) FROM ^eventlog ' .
                'WHERE datetime >= FROM_UNIXTIME(#) AND (' .
                '(userid = # AND event LIKE "in_%") OR ' .
                '(event IN ("u_message", "u_wall_post") AND params LIKE "userid=#\t%")' .
                ')',
                $last_visit,
                $userid,
                $userid
            ));

            $pluginCount = qa_db_read_one_value(qa_db_query_sub(
                'SELECT COUNT(*) FROM ^q2apro_osn_plugin_notifications ' .
                'WHERE user_id = # AND created_at >= FROM_UNIXTIME(#)',
                $userid, $fromTime
            ));

            return $eventlogCount + $pluginCount;
        }
pppery
  • 3,731
  • 22
  • 33
  • 46
  • Does it work if you change `params LIKE "userid=#\t%"` and `$userid` to `params LIKE #` and `"userid=" . $userid . "\t%"` ? – etsuhisa Aug 16 '20 at 05:26

0 Answers0