• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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 ?
0
puneetdudeja
Asked:
puneetdudeja
  • 6
  • 4
1 Solution
 
Shinesh PremrajanTechnical 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now