CodeIgniter Forums
PDO and CI 3.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: PDO and CI 3.0 (/showthread.php?tid=60743)



PDO and CI 3.0 - El Forum - 06-17-2014

[eluser]Unknown[/eluser]
I am trying to insert a blob with CI 3.0 and PDO. Everything else seems to work fine but I cannot insert blobs. I also tried the prepare/execute method of PDO handling but that doesn't work either. I tried this code:

$sql = "INSERT INTO images (imgname,imgtype,imgwidth,imgheight,imgdata,imgthumb,status) VALUES (?,?,?,?,?,?,?)";
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $name, PDO:TongueARAM_STR);
$stmt->bindParam(2, $type, PDO:TongueARAM_STR);
$stmt->bindParam(3, $width, PDO:TongueARAM_INT);
$stmt->bindParam(4, $height, PDO:TongueARAM_INT);
$stmt->bindParam(5, file_get_contents($url), PDO:TongueARAM_LOB);
$stmt->bindParam(6, file_get_contents($thumburl), PDO:TongueARAM_LOB);
$stmt->bindParam(7, '0', PDO:TongueARAM_INT);
$stmt->execute();

and I get this error: Call to undefined method CI_DB_pdo_mysql_driver::prepare()

Any ideas?

(yes, I have set up for pdo as my driver in the database.php config file and other 'regular' queries are working fine.)


PDO and CI 3.0 - El Forum - 06-19-2014

[eluser]a_h_abid[/eluser]
Probably doesn't have prepare() method, so you getting this error.

One way to fix your issue is to use $this->db->conn_id->prepare($sql).... like this

[pre]
$sql = “INSERT INTO images (imgname,imgtype,imgwidth,imgheight,imgdata,imgthumb,status) VALUES (?,?,?,?,?,?,?)”;
$stmt = $this->db->conn_id->prepare($sql);
$stmt->bindParam(1, $name, PDO:TongueARAM_STR);
$stmt->bindParam(2, $type, PDO:TongueARAM_STR);
$stmt->bindParam(3, $width, PDO:TongueARAM_INT);
$stmt->bindParam(4, $height, PDO:TongueARAM_INT);
$stmt->bindParam(5, file_get_contents($url), PDO:TongueARAM_LOB);
$stmt->bindParam(6, file_get_contents($thumburl), PDO:TongueARAM_LOB);
$stmt->bindParam(7, ‘0’, PDO:TongueARAM_INT);
$stmt->execute();
[/pre]