2

I'm trying to save a byteArray of a jpg from an as3 project through amfphp to then use php/mySQL to save it to a BLOB on my database. Here's my php function

function saveImage($uid, $name, $tag1, $tag2, $tag3, $ba) {
        $result = mysql_query("INSERT INTO images (uid,name,tag1,tag2,tag3,thumb) VALUES ('$uid','$name','$tag1','$tag2','$tag3','$ba->data');");

        $error = mysql_error();
        if ($error) {
            return $error;
        }
        else {
            return $result;
        }
    }

but i keep getting this error back:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄ' at line 1

Any suggestions on how to resolve this?

brybam
  • 5,009
  • 12
  • 51
  • 93

1 Answers1

2

For future reference, if you want to save binary file to blob cell in mysql, you can use addslashes function to your data, like:

addslashes($blob_data);

An example of working code is located here: try addslashes on binary data variable. addslashes($variable)

Vahid Farahmand
  • 2,528
  • 2
  • 14
  • 20
  • Hey, hopefully real quick, do you have any idea how to read it back? you could put it in the Answer. I tried something like this `$img = new ByteArray(stripslashes($row['thumb']));` but no luck im not getting anything back – brybam Jan 30 '13 at 02:51
  • Hey thanks for coming back. I just tried what you suggested but im not having any luck, would you mind taking a quick look at what I posted in the question above? – brybam Jan 30 '13 at 03:33
  • do some debugging like print $img variable right after you get data from db. check if you have something on that variable, also connect to mysql using command line and select data from mysql and see if it contains data or export your db and see if you have any data in your cell. – Vahid Farahmand Jan 30 '13 at 03:38