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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: Database SQL/XMLDB
    • Labels:
      None
    • Database:
      MySQL
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_20_STABLE

      Description

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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: