I've been fighting this one for a couple of days now ...
Just after connection to db -
$this->sqladdimport = $this->db->prepare('INSERT INTO `importqueue`
(`user_id`, `service_id`, `format`, `comment`, `data`, `status`)
VALUES (:user, :service, :format, ":commment", :file, :status)',
array(PDO::ATTR_EMULATE_PREPARES=>true));
Called by -
function addImportQueue($filename, $user, $format, $service_id, $comment, $status = IMPORT_NEW ){
$fh = fopen($filename, 'r');
if (!$fh) {
return false;
}
$params = array( ':user' => $user['user_id'],
':format' => $format,
':service' => $service_id,
':comment' => $comment,
':status' => $status) ;
$this->sqladdimport->bindParam(':file', $fh, PDO::PARAM_LOB);
foreach ($params as $key => &$val){
$this->sqladdimport->bindParam($key,$val);
}
$this->sqladdimport->execute();
$id = $this->db->lastInsertId();
return $id;
}
But I just get
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'
on the execute line.
In case it's relevant, the table is defined thus:
CREATE TABLE `importqueue` (
`import_id` INT(11) NOT NULL AUTO_INCREMENT,
`service_id` INT(11) NOT NULL DEFAULT '0',
`format` INT(11) NULL DEFAULT '0',
`user_id` INT(11) NULL DEFAULT '0',
`comment` TEXT NULL,
`date` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`data` MEDIUMBLOB NULL,
`status` INT(11) NULL DEFAULT NULL,
INDEX `Index 1` (`import_id`)
)
COMMENT='Import queue/archive'
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;
I've fairly new to PDO, and especially BLOBs, so I'm probably doing something really obviously stupid, but it's currently escaping me!
Thanks!
Edit: I note the references to the quotes around :comment in the prepare - this was an artefact of my debugging, and I have removed those again with no change.
Have also simplified the function to
$fh = fopen($filename, 'r');
$this->sqladdimport->bindValue(':file', $fh, PDO::PARAM_LOB);
$this->sqladdimport->bindValue(':user', $user['user_id']);
$this->sqladdimport->bindValue(':format', $format);
$this->sqladdimport->bindValue(':service', $service_id);
$this->sqladdimport->bindValue(':comment', $comment);
$this->sqladdimport->bindValue(':status', $status);
$this->sqladdimport->execute();
and I still get the same error (using either bindParam or bindValue)