Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-22703

DML error if you use same param twice in a query.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 2.0
    • Database SQL/XMLDB
    • None
    • MySQL
    • MOODLE_20_STABLE
    • Easy

      DML error if you use same param twice in a query for $DB->get_records_sql, $DB->get_record_sql, $DB->get_field_sql

      example:

      $sql = 'SELECT * FROM

      {user} as user where user.id = :id and user.id = :id';
      $param['id'] = $id;
      $DB->get_records_sql($sql,$params);

      causes

      Fatal error: Uncaught exception 'dml_exception' with message '[[invalidqueryparam]]' in ...\moodle\lib\dml\moodle_database.php:651 Stack trace: #0 ...\moodle\lib\dml\mysqli_native_moodle_database.php(651): moodle_database->fix_sql_params('SELECT * FROM {...', Array)

      Can be solved only in very ugly way now:

      $sql = 'SELECT * FROM {user}

      as user where user.id = :id and user.id = :id2';
      $param['id'] = $id;
      $param['id2'] = $id;
      $DB->get_records_sql($sql,$params);

            stronk7 Eloy Lafuente (stronk7)
            e.v.soldatkin E.V.Soldatkin
            Nobody Nobody
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.