Reputation: 2126
I am using this code...
$sql = "INSERT INTO images (imgname,imgtype,imgwidth,imgheight,imgdata,imgthumb,status) VALUES (?,?,?,?,?,?,?)";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $name, PDO::PARAM_STR);
$stmt->bindParam(2, $type, PDO::PARAM_STR);
$stmt->bindParam(3, $width, PDO::PARAM_INT);
$stmt->bindParam(4, $height, PDO::PARAM_INT);
$stmt->bindParam(5, file_get_contents($url), PDO::PARAM_LOB);
$stmt->bindParam(6, file_get_contents($thumburl), PDO::PARAM_LOB);
$stmt->bindParam(7, '0', PDO::PARAM_INT);
$stmt->execute();
But I am getting the error:
Message: Call to undefined method CI_DB_pdo_mysql_driver::prepare()
Is there some other way to insert a blob using PDO in CodeIgniter 3.0? Everything else seems to work fine with the database helper.
Upvotes: 0
Views: 1166
Reputation: 2126
Found it. As hjpotter92 says, $this->db isn't really a PDO object. But CodeIgniter does pass through functions to PDO if you use the conn_id PDO pointer. I replaced:
$this->db->prepare($sql);
with
$this->db->conn_id->prepare($sql);
And everything works fine now.
Upvotes: 3