0

Changing from mysqli to PDO, I've started getting errors in my prepared queries regarding the number of parameters given, like so - "PDOStatement::bindParam() expects at most 5 parameters, 7 given"

The above was the result of running this code;

$stmt = $pdo->prepare("INSERT INTO methadone_dosing (id, date_time, methadone_mls, dose_code, nurse, witness)
                    VALUES (?, ?, ?, ?, ?, ?)");
                    $stmt->bindParam("ssssss", $id, $date_time, $meth_dose, $dose_code, $nurse, $witness);
                    $stmt->execute();

Is there another way to bind parameters without using an array or such, or am I mixing syntaxes somewhere? Any help would be most appreciated.

Carbs
  • 23
  • 5
  • 3
    You are binding parameters using mysqli style, which will not work, please refer to the doc: https://www.php.net/manual/en/pdostatement.bindparam.php – catcon Jul 27 '20 at 01:50
  • So I am. Much appreciated. – Carbs Jul 27 '20 at 01:53
  • 2
    `bindParam` isn't even needed. `$stmt->execute(array($id, $date_time, $meth_dose, $dose_code, $nurse, $witness));` Insert with `id` is usually questionable, I'd use autoincrement. – user3783243 Jul 27 '20 at 01:54
  • The ID corresponds to a patient ID, so it is necessary, but the rest looks a lot easier than writing out six statements every time I want to update. Thank you. – Carbs Jul 27 '20 at 01:58
  • 2
    You might like https://phpdelusions.net/pdo and https://phptherightway.com/ – Bill Karwin Jul 27 '20 at 02:13
  • I'll check them out. Thanks Bill! – Carbs Jul 27 '20 at 03:43

0 Answers0