我正在 Codeigniter 中处理一个过程,以获取用户上传的图像(使用 CI 上传库管理)并将其插入 SQLServer 数据库中的 varbinary(max) 字段。我的控制器和型号代码如下。
if($this->upload->do_upload($upload_name)) {
    //get temp image
    $tmpName  = $config['upload_path'] . $config['file_name'];  
    // Read it into $data variable
    $fp      = fopen($tmpName, 'rb');
    $data = fread($fp, filesize($tmpName));
    fclose($fp);
    //insert into DB
    $this->the_model->storeImage($data, $user_id);
    //delete temp image      
    unlink($config['upload_path'] . $config['file_name']);
}
/***** Function from the_model ************/
function storePropertyImage($image_data, $user_id) {
    $my_db = $this->load->database('admin');
    $stmt = "INSERT INTO my_table (UserID, ImageData) VALUES (" . $my_db->escape($user_id) . ", " . $my_db->escape($image_data) . ")";
    $insert = $my_db->query($stmt);
    return $insert;
}
这一切看起来应该没问题,但是当我运行代码时,我得到了错误:
Fatal error: Uncaught exception 'PDOException' with message 
'SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters' 
in {my app path}\helpers\mssql_helper.php on line 213
我对此错误消息进行了一些谷歌搜索,结果似乎表明这是 $data 值中有一个冒号字符被发送到模型的结果,使数据库认为我正在尝试传递一个命名参数当我不在的时候。但是,我找不到任何与我的特定用例相匹配的报告,或者关于如何更正错误的大量信息。
我会很感激任何关于我可能会绊倒的地方的见解。