Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Incorrect number of query parameters. Expected 3, got 2. #9

Closed
cyberjames opened this issue May 29, 2018 · 3 comments
Closed

Comments

@cyberjames
Copy link

Hi,

After upgrading my Moodle from version 3.0+ to 3.3.5 and block_studentstracker from 2015051100 to 1.5 (2017062200), when viewing one of my courses is showing error message below. I will appreciate if you can help and advise? Thanks

Warning: Invalid argument supplied for foreach() in /path/to/moodle/blocks/studentstracker/locallib.php on line 36
ERROR: Incorrect number of query parameters. Expected 3, got 2.
Debug info:
Error code: invalidqueryparam
Stack trace:
line 913 of /lib/dml/moodle_database.php: dml_exception thrown
line 1211 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->fix_sql_params()
line 1558 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
line 1631 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
line 1841 of /lib/dml/moodle_database.php: call to moodle_database->get_field_sql()
line 42 of /blocks/studentstracker/locallib.php: call to moodle_database->count_records_sql()
line 117 of /blocks/studentstracker/block_studentstracker.php: call to studentstracker::has_role()
line 288 of /blocks/moodleblock.class.php: call to block_studentstracker->get_content()
line 230 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
line 1205 of /lib/blocklib.php: call to block_base->get_content_for_output()
line 1257 of /lib/blocklib.php: call to block_manager->create_block_contents()
line 579 of /lib/outputrenderers.php: call to block_manager->ensure_content_created()
line 39 of /theme/bootstrapbase/renderers/core_renderer.php: call to core_renderer->standard_head_html()
line 46 of /theme/lambda/layout/columns3.php: call to theme_bootstrapbase_core_renderer->standard_head_html()
line 1162 of /lib/outputrenderers.php: call to include()
line 1092 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
line 244 of /course/view.php: call to core_renderer->header()

@cyberjames
Copy link
Author

I managed somehow to fix it. Here's the changes on locallib.php.

    public static function has_role($rids, $courseid, $uid) {
        global $DB;
        $params = array();
        //foreach ($rids as $role) {
        //    array_push($params, (int)$role);
        //}
        array_push($params, $rids, $courseid, (int)$uid);
        $roles = join(',', array_fill(0, count($rids), '?'));
        $r = $DB->count_records_sql("SELECT COUNT(id) FROM {role_assignments} WHERE roleid IN($roles) AND contextid=? AND userid=?",
        $params);
        if ($r > 0) {
            return true;
        } else {
            return false;
        }
    }

@Hipjea
Copy link
Owner

Hipjea commented Mar 2, 2021

Thanks for the report. This error has been fixed for a while (1.6 and 1.7 versions are ok).

@Hipjea Hipjea closed this as completed Mar 2, 2021
@cyberjames
Copy link
Author

Hi @Hipjea ,

Sorry to resurrect this thread again but I do appreciate your advise what could be wrong with my current situation...

I'm using version 1.7 and I have got a strange error below for the specific course only. The rest of the course were fine.

Warning: Invalid argument supplied for foreach() in /documentroot/blocks/studentstracker/locallib.php on line 237

Warning: count(): Parameter must be an array or an object that implements Countable in /documentroot/blocks/studentstracker/locallib.php on line 241

Error
ERROR: Incorrect number of query parameters. Expected 3, got 2.
Debug info:
Error code: invalidqueryparam
Stack trace:
line 945 of /lib/dml/moodle_database.php: dml_exception thrown
line 1268 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->fix_sql_params()
line 1671 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
line 1744 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
line 1954 of /lib/dml/moodle_database.php: call to moodle_database->get_field_sql()
line 243 of /blocks/studentstracker/locallib.php: call to moodle_database->count_records_sql()
line 168 of /blocks/studentstracker/locallib.php: call to studentstracker::has_role()
line 120 of /blocks/studentstracker/block_studentstracker.php: call to studentstracker->get_enrolled_users()
line 341 of /blocks/moodleblock.class.php: call to block_studentstracker->get_content()
line 235 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
line 1181 of /lib/blocklib.php: call to block_base->get_content_for_output()
line 1239 of /lib/blocklib.php: call to block_manager->create_block_contents()
line 374 of /lib/blocklib.php: call to block_manager->ensure_content_created()
line 3950 of /lib/outputrenderers.php: call to block_manager->region_has_content()
line 40 of /theme/boost/layout/columns2.php: call to core_renderer->blocks()
line 1374 of /lib/outputrenderers.php: call to include()
line 1304 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
line 253 of /course/view.php: call to core_renderer->header()

So I tried to print the value of variable $roles at line 241 at file locallib.php by adding the code below, it returns with roles = ?.

        $roles = join(',', array_fill(0, count($roleids), '?'));
        print_object("roles = " . print_r($roles, true));
        $r = $DB->count_records_sql("SELECT COUNT(id) FROM {role_assignments} WHERE roleid IN($roles) AND contextid=? AND userid=?",
        $params);

Any advise is deeply appreciated.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants