Page 1 of 1

Mysqli and blob insert

Posted: Tue Jul 19, 2011 8:16 pm
by CCostemo
Hey,

I've got a bit of a problem with a web site i've been working on. I can't seem to get the php script to insert all the data into the database. I'm sending a byte array from flash to a php script to insert into a data base, and though it inserts it, it only inserts part of it. I dunno if the data is getting corrupted or the data just isn't being inserted all the way (when retrieving the photo comes out half grey). I've written a script in java to do the same thing and it works perfectly (I haven't had much experience in php). here's the php script...

Code: Select all

        $query = $link->prepare("UPDATE PHOTO SET PHOTO_DATA=? WHERE PHOTO_ID='".$id."'");
        $query->bind_param('s', $photo);
        $data = fopen("php://input", 'r');
        while(!feof($data)){
            $query->send_long_data(0,  fread($data, 8192));
        }
        fclose($data);

        if (!$query->execute())
            die("Unable to query" . mysql_error());
I've also tried similar scripts with $HTTP_RAW_POST_DATA and the same happens... I can't use java because the people i'm doin the site for don't wanna pay the extra R$10 a month. here's the flex script....

Code: Select all

...
			var fdataRequest:URLRequest = new URLRequest(insertUrl);
			var fdataLoader:URLLoader = new URLLoader();
			fdataRequest.contentType = 'application/octet-stream';
			fdataRequest.method = URLRequestMethod.POST;;
			fdataRequest.data = photo.picture;
			fdataLoader.addEventListener(Event.COMPLETE, fdataChannelComplete);
			fdataLoader.addEventListener(IOErrorEvent.IO_ERROR, ioError);
			fdataLoader.load(fdataRequest);
...

...
		private function fdataChannelComplete(e:Event):void{
			//e.target.removeEventListener(Event.COMPLETE, fdataChannelComplete);
			var response:String = e.target.data;
			if(response == 'success'){
				var evt:NetworkEvent = new NetworkEvent(NetworkEvent.PHOTO_DATA_INSERT_COMPLETE);
				this.dispatchEvent(evt);
			} else {
				Alert.show("Não foi possivel communicar com o servidor\n ERROR:::"+response);
			}
		}
This has been driving be crazy... First I thought it was a timeout error and it wasnt then i thought it was a client side error and i don't think it is (since it works fine with java) if somebody could help me to see what im doing wrong i'd greatly appreciate it...

Re: Mysqli and blob insert

Posted: Fri Aug 05, 2011 11:23 pm
by yacahuma
most likely is not php but some database configuration, check the size of the data you are using and check for limitations on the typoe your are using. I will suggest to store photos in a directory structure and not inside the database. I have been in that road many times. Backups will be a pain.

Re: Mysqli and blob insert

Posted: Sat Aug 06, 2011 1:07 pm
by McInfo
Try binding with the blob type ('b') instead of the string type ('s').

Code: Select all

$query->bind_param('b', $photo);
However, I agree with yacahuma. Store images in the filesystem.