I'm flummoxed by this error, even worse is that the code seems to work sometimes but I can't see any pattern in the data that causes it.
The code is as follows:-
try { $insQuery = "INSERT INTO log "; // $insQuery .= "(seqno, year, month, day, hour, minute, waterway, pk, place, distance, eng_hrs, fuel_cm, fuel_lt, note, type, sailing)"; $insQuery .= "(seqno, year, month, day)"; $insQuery .= " VALUES "; // $insQuery .= "(:seqno, :year, :month, :day, :hour, :minute, :waterway, :pk, :place, :distance, :eng_hrs, :fuel_cm, :fuel_lt, :note, :type, :sailing );"; $insQuery .= "(:seqno, :year, :month, :day);"; $st = $db->prepare($insQuery); foreach ($rows as $row) { $row['seqno'] = $seqno++; $st->execute($row); } $st->closeCursor; } catch (PDOException $e) { dbglog("PDO() insert error" . $e->getMessage()); dbglog("insquery: $insQuery"); foreach($row as $k=>$v) { dbglog("k is: $k, v is $v"); } }
... and what I'm seeing in the log is:-
13:53:59 192.168.1.4: PDO() insert errorSQLSTATE[HY000]: General error: 25 bind or column index out of range 13:53:59 192.168.1.4: insquery: INSERT INTO log (seqno, year, month, day) VALUES (:seqno, :year, :month, :day); 13:53:59 192.168.1.4: k is: year, v is 2011 13:53:59 192.168.1.4: k is: month, v is 11 13:53:59 192.168.1.4: k is: day, v is 12 13:53:59 192.168.1.4: k is: hour, v is 10 13:53:59 192.168.1.4: k is: minute, v is 00e 13:53:59 192.168.1.4: k is: waterway, v is 13:53:59 192.168.1.4: k is: pk, v is 13:53:59 192.168.1.4: k is: place, v is Cappy 13:53:59 192.168.1.4: k is: distance, v is 13:53:59 192.168.1.4: k is: eng_hrs, v is 2695.3 13:53:59 192.168.1.4: k is: fuel_cm, v is 8.5 13:53:59 192.168.1.4: k is: fuel_lt, v is 13:53:59 192.168.1.4: k is: note, v is Engine started after replacing blown mega-fuse, all OK otherwise 13:53:59 192.168.1.4: k is: type, v is TEF 13:53:59 192.168.1.4: k is: price, v is 13:53:59 192.168.1.4: k is: sailing, v is 1 13:53:59 192.168.1.4: k is: seqno, v is 0
So what does "General error: 25 bind or column index out of range" actually mean, I could find nowhere that explains it. Now my guess is that it's telling me that I have a column name wrong somewhere but my 'log' table definitely has columns year, month, day and seqno of the correct type. Maybe I have the syntax wrong somehow for the VALUES() bit but again I can't find any really good explanation of exactly what the syntax is, it seems decidedly woolly.