Tim Streater wrote: > I've got a temporary database with a blob column. I'm using the PHP > PDO interface, and I'd like to store some binary data into the blob; > it's actually an image. > At the moment I'm using str_replace to change any single-quote to two > single-quotes, and then doing as follows: > > $dbh->query ("update imagetable set imagedata='" . $bd . "' where linkid=" > . $linkid); > > but this is giving me: > > SQLite error: general code: HY000 error: 1, unrecognized token: > "'����/�Exif"
The single quotes are the least of your problems; all the other binary characters foul up the SQL parser. > What's the right way to get the data into the column? 1) Use SQLite blob literals, which are hex strings with an "x" prefix: ... set imagedata = x'ffd8ffe000104a46...' where ... 2) Use parameters (which is recommended in any case to avoid both formatting and SQL injection problems): $stmt = $dbh->prepare('update imagetable set imagedata = ? where linkid = ?'); $stmt->bindValue(1, $imgdata, PDO::PARAM_LOB); $stmt->bindValue(2, $linkid, PDO::PARAM_INT); $stmt->execute(); See also <http://php.net/manual/en/pdo.lobs.php>. Regards, Clemens _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users