title: ByteArray to MySQL from ActionScript 3 -> PHP via ZendAMF
body: <p>I have an ActionScript 3 application that's sending an object to PHP via ZendAMF. The object contains a byteArray from an image. </p>
  
  <p>I have it currently saving the byteArray into a Blob like so: </p>
  
  <pre><code>$ba = new Zend_Amf_Value_ByteArray ( $im-&gt;bArray );
  $data = mysql_real_escape_string ( $ba-&gt;getData () );
  
  $query = "INSERT INTO  image ( byteArray ) VALUES ( '".$data."' );";
  $result = mysql_query($query);
  $error = mysql_error();
  
  if($error)
   return "Error: " . $error;
  else
   return true;
  </code></pre>
  
  <p>This seems to be working fine and I can see the image in the DB (this is running local and I'm using SequelPRO to view the DB).</p>
  
  <p>The problem is when I'm sending the byteArray back to Flash, Flash reports the byteArray length as 0.</p>
  
  <p>Here is my return method in PHP:</p>
  
  <pre><code>$result = mysql_query ( 'SELECT * FROM image');
  $array = array();
  
  while ( $row = mysql_fetch_assoc ( $result ) )
  {
   $ba = new Zend_Amf_Value_ByteArray ( $row['byteArray'] );
  
   $image = new Image ();
   $image-&gt;id = $row['id'];
   $image-&gt;file = $row['filePath'];
   $image-&gt;bArray = $ba-&gt;getData();
  
   array_push ( $array, $image );
  }
  
  return ( $array );
  </code></pre>
  
  <p>Is there a better way to do this?
  Any help would be greatly appreciated.</p>
  
  <p>Thank you</p>