Skip to Content
Former Member
Nov 13, 2014 at 08:57 PM

Problems writing binary files to Sybase SQL Anywhere from PHP


Hi there

We are trying to write PDF, Word, JPG and other binary files to a Sybase SQL Anywhere database using PHP.

We are connecting with PHP using PHP_DBLIB through PDO and are using the code below to read and a file and write into a column:


// Read file

$filename = “/path/to/file/pdf.pdf";

$handle = fopen($filename, "rb");

$contents = fread($handle, filesize($filename));

// Attempt to write file

$query = $db->prepare('INSERT INTO table_name (id, document_blob) VALUES (1, ?)’);

$query->bindParam(1, $contents, \PDO::PARAM_LOB);



The whole query just fails with a generic error message, however we are able to use the above code to write to a MySQL database.

Any thoughts / inspiration gratefully received.