cancel
Showing results for 
Search instead for 
Did you mean: 

Problems writing binary files to Sybase SQL Anywhere from PHP

Former Member
0 Kudos

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:

<?php

// 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);

$query->execute();

?>


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.

Cheers

Ed

Accepted Solutions (1)

Accepted Solutions (1)

former_member188493
Contributor
0 Kudos

FWIW SQL Anywhere has it's own support for PHP.

Former Member
0 Kudos

Hi Breck

Thanks for getting in touch - much appreciated.

Here's the error message we're seeing...

General SQL Server error: Check messages from the SQL Server [102] (severity 15) [(null)]

Does that help?

Also, thanks for the info about Sybase's direct support for PHP - unfortunately we don't have control of the platform it is running on and can only talk to it from afar across the ether.

Cheers
Ed

former_member188493
Contributor
0 Kudos

AFAIK that message is not coming from SAP/Sybase SQL Anywhere, it is coming from Microsoft SQL Server... are you expecting that?

FWIW you don't need close contact with the SQL Anywhere server in order to call the SQL Anywhere PHP API from your client-side code. You can download the SAP Sybase SQL Anywhere PHP Module here.

Answers (1)

Answers (1)

former_member188493
Contributor
0 Kudos

Please show the error message.