BLOB field in a table returned as empty string on being fetched through php script.

I have a table in which I have a blob field in which i am storing an image data after base64 encoding it. When I fetch that record from php,  i get all fields correct except the BLOB field which is retrieved as empty string.

I can't figure it out, why it is happening ?
LVL 2
puneetdudejaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shinesh PremrajanEngineering ManagerCommented:
what is the database you are using.. ?
0
puneetdudejaAuthor Commented:
Mysql
0
NeoAshuraCommented:
can you please include your code and ill have a look for u mate.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

puneetdudejaAuthor Commented:
Please see the code below::

When I fetch the record, I get both the fields "ImgId and MimeType" correct, but "Image" field as empty string.
$params = $this->_request->getParams();
		
		
		if(isset($params['submitted']))
		{
			$fp = fopen($_FILES['file1']['tmp_name'], "rb"); 
            $content = base64_encode(fread($fp, filesize($_FILES['file1']['tmp_name']))); 

			
			$bubble->insertBubble($content,$_FILES['file1']['type']);
			move_uploaded_file($_FILES['file1']['tmp_name'],'/home/puneet/public_html/u2me/public/abc.gif');
			echo 'inserted ... ';
		}
		else
		{
			$arr = $bubble->fetchBubble();
			echo '<pre>';print_r($arr);echo '</pre>';

		}



public function insertBubble($data,$mime)
	{
		$arr = array( 'Image' =>  $data,
            'MimeType' => $mime
            );
		$db = $this->getAdapter();
		
		$db->insert('bubble_messages',$arr);
		

	}
	
	public function fetchBubble()
	{	
		$sql = 'SELECT * FROM bubble_messages order by ImgId desc';
		$db = $this->getAdapter();
		$res = $db->query($sql);
		$result = $res->fetch();
		return $result;
	}


CREATE TABLE `bubble_messages` (
  `ImgId` int(11) NOT NULL auto_increment,
  `Image` longblob,
  `MimeType` varchar(100) default NULL,
  PRIMARY KEY  (`ImgId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Open in new window

0
NeoAshuraCommented:
try this see what u get..
<?php
$params = $this->_request->getParams();
                
                
                if(isset($params['submitted']))
                {
                        $fp = fopen($_FILES['file1']['tmp_name'], "rb"); 
            $content = base64_encode(fread($fp, filesize($_FILES['file1']['tmp_name']))); 

                        
                        $bubble->insertBubble($content,$_FILES['file1']['type']);
                        move_uploaded_file($_FILES['file1']['tmp_name'],'/home/puneet/public_html/u2me/public/abc.gif');
                        echo 'inserted ... ';
                }
                else
                {
                        $arr = $bubble->fetchBubble();
                        echo '<pre>';print_r($arr);echo '</pre>';

                }



 function insertBubble($data,$mime)
        {
                $arr = array( 'Image' =>  $data,
            'MimeType' => $mime
            );
                $db = $this->getAdapter();
                
                $db->insert('bubble_messages',$arr);
                

        }
        
        function fetchBubble()
        {       
                $sql = 'SELECT * FROM bubble_messages order by ImgId desc';
                $db = $this->getAdapter();
                $res = $db->query($sql);
                $result = $res->fetch();
                return $result;
        }

?>

Open in new window

0
NeoAshuraCommented:
also.. i believe u are using zend frame work.. im not to hot on this but.. i also think u need to change line 2.. to the following...

$params = $this->_request->getParam('params');
0
NeoAshuraCommented:
ok i think i got it.. this returns a blank page for me.. there will be an error with my previous code.. on line 2. that is because $params is being caled out of a function.. so try this and let me know how it goes.. i get a blank page for this when i run it.. so hopefully u will see some data..


<?php
function param($params)
{
$params = $this->_request->getParams(params);


                if(isset($params['submitted']))
                {
                        $fp = fopen($_FILES['file1']['tmp_name'], "rb");
            $content = base64_encode(fread($fp, filesize($_FILES['file1']['tmp_name'])));


                        $bubble->insertBubble($content,$_FILES['file1']['type']);
                        move_uploaded_file($_FILES['file1']['tmp_name'],'/home/puneet/public_html/u2me/public/abc.gif');
                        echo 'inserted ... ';
                }
                else
                {
                        $arr = $bubble->fetchBubble();
                        echo '<pre>';print_r($arr);echo '</pre>';

                }



 function insertBubble($data,$mime)
        {
                $arr = array( 'Image' =>  $data,
            'MimeType' => $mime
            );
                $db = $this->getAdapter();

                $db->insert('bubble_messages',$arr);


        }

        function fetchBubble()
        {
                $sql = 'SELECT * FROM bubble_messages order by ImgId desc';
                $db = $this->getAdapter();
                $res = $db->query($sql);
                $result = $res->fetch();
                return $result;
        }

?>

Open in new window

0
puneetdudejaAuthor Commented:
NeoAshura, u have not changed anything in the code, and perhaps i think the problem is not with the syntax of the code, there is some basic thing missing out of it. Maybe some setting in mysql server or something we don't know.
0
NeoAshuraCommented:
perhaps if u look more closely u will see that

<?php
function param($params)
{
$params = $this->_request->getParams(params);
 

is changed.

public function is now called function..

my advice is dont use Zend frame work. ur more likely to get more help/
0
NeoAshuraCommented:
you cannot call a class outside of a function which u did previously.
0
puneetdudejaAuthor Commented:
The problem is :: We are not able to fetch a "longblob" field from the mysql table through "fetchAll" method of Zend_Db_Table_Adapter class. If I replace "longblob" with either of "blob, tinyblob, mediumblob" then everything is working fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.