Retrieving data from blob data type - cakephp 3

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieving data from blob data type - cakephp 3

Ryan de Haast
Hi All

Can anybody explain to me how to get the data from column type that is a blob. when I retrieve the data from the database I'm able to get the details for all the columns however when a column is a blob it returns a resource. When I do a vardump on the data that's returned it shows it as resource stream

Here's some of my code, the part where I'm trying to get the contents:
foreach($list as $anArt)
{
 
pd($anArt);
  print_r($anArt->article_serialized);
  var_dump($anArt->article_serialized);
  $contents = fread($anArt->article_serialized, 1000000);
  pd($contents);
  $data = "";
  while (!feof($anArt->article_serialized)) {
   
$data .= stream_get_line($anArt->article_serialized, 1000000);
  }
 
pd($data);
}

The pd function is debug function used in the above code is just to print out the data as I'm working through it. The data in the specific column is stored as a serialized string

Please advise...

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving data from blob data type - cakephp 3

Ryan de Haast
Also when I print the final array I get the following:
[data] => Resource id #1638

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving data from blob data type - cakephp 3

Aday Talavera
In reply to this post by Ryan de Haast
For Cake3, look at these manual entries:

http://book.cakephp.org/3.0/en/orm/saving-data.html#saving-complex-types
http://book.cakephp.org/3.0/en/orm/database-basics.html#adding-custom-database-types

For Cake2 you could use SerializableBehaviour from CakeDC/Utils plugin:

https://github.com/CakeDC/utils

El domingo, 10 de mayo de 2015, 4:16:54 (UTC+1), Ryan de Haast escribió:
Hi All

Can anybody explain to me how to get the data from column type that is a blob. when I retrieve the data from the database I'm able to get the details for all the columns however when a column is a blob it returns a resource. When I do a vardump on the data that's returned it shows it as resource stream

Here's some of my code, the part where I'm trying to get the contents:
foreach($list as $anArt)
{
 
pd($anArt);
  print_r($anArt->article_serialized);
  var_dump($anArt->article_serialized);
  $contents = fread($anArt->article_serialized, 1000000);
  pd($contents);
  $data = "";
  while (!feof($anArt->article_serialized)) {
   
$data .= stream_get_line($anArt->article_serialized, 1000000);
  }
 
pd($data);
}

The pd function is debug function used in the above code is just to print out the data as I'm working through it. The data in the specific column is stored as a serialized string

Please advise...

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving data from blob data type - cakephp 3

mark_story
Blobs come back as file resources to try and save memory. You can use normal stream functions to read the conte ts incrementally or all at once.

-mark

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving data from blob data type - cakephp 3

Vivek Doshi
In reply to this post by Ryan de Haast
Try this : 

http://stackoverflow.com/questions/32275558/upload-files-using-cakephp-3-and-store-it-in-a-blob

On Sunday, May 10, 2015 at 8:46:54 AM UTC+5:30, Ryan de Haast wrote:
Hi All

Can anybody explain to me how to get the data from column type that is a blob. when I retrieve the data from the database I'm able to get the details for all the columns however when a column is a blob it returns a resource. When I do a vardump on the data that's returned it shows it as resource stream

Here's some of my code, the part where I'm trying to get the contents:
foreach($list as $anArt)
{
 
pd($anArt);
  print_r($anArt->article_serialized);
  var_dump($anArt->article_serialized);
  $contents = fread($anArt->article_serialized, 1000000);
  pd($contents);
  $data = "";
  while (!feof($anArt->article_serialized)) {
   
$data .= stream_get_line($anArt->article_serialized, 1000000);
  }
 
pd($data);
}

The pd function is debug function used in the above code is just to print out the data as I'm working through it. The data in the specific column is stored as a serialized string

Please advise...

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.