Welcome Guest, Not a member yet? Register   Sign In
PDO and CI 3.0
#1

[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.)
#2

[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]




Theme © iAndrew 2016 - Forum software by © MyBB