Ostico / PhpOrient

PhpOrient - Official Php driver based on the binary protocol of OrientDB.
Other
68 stars 37 forks source link

Question: Retrieving Binary Data #10

Closed robsteven192 closed 9 years ago

robsteven192 commented 9 years ago

Hello I am working with PhpOrient as well as the Java API and have ORecordBytes being stored and am having trouble retrieving the actual data with PhpOrient. I get the rid for the record but when I load the record from the database I do not know how to retrieve the binary data. Any help would be greatly appreciated!

Ostico commented 9 years ago

Hi @robsteven192 , Can you provide me an example, a record in the db and the query you're trying to do on that field?

If there is a bug i've to try to recreate the behaviour.

robsteven192 commented 9 years ago

Hi I upload a picture using this method uploadmethod and can retrieve it and all other ones properly through Java with this retrievaljava The problem I am running into is I am not sure how to retrieve this data through PHP. I can obtain the Record for the Picture and the "binary" field contains an ID to another Record and I am not sure how to retrieve information about that Record to extract the binary data it is storing. There probably isn't a bug I just have no idea how to get the binary data. Thanks!

robsteven192 commented 9 years ago

I decided to store the binary data in the document and not in a separate Record which made things a lot easier to do in PHP. Thanks for your time!

Ostico commented 9 years ago

There was a bug and i fixed it.

Now, you can use this code to retrieve binary data:

require "vendor/autoload.php";
use PhpOrient\PhpOrient;

$client = new PhpOrient( 'localhost', 2424 );
$client->dbOpen( 'test', 'admin', 'admin' );

$user = $client->query( "select * from user where username = 'domenico'" );

/**
 * @var \PhpOrient\Protocols\Binary\Data\Record $user[0]
 */
$record = $client->recordLoad( $user[0]->getOData()['pictures'][0] );

/**
 * @var \PhpOrient\Protocols\Binary\Data\Record $record[0]
 */
$pic = $client->recordLoad( $record[0]->getOData()['binary'] );

/**
 * @var \PhpOrient\Protocols\Binary\Data\Record $pic[0]
 */
file_put_contents( "my_file.png", $pic[0]->getOData()[0] );
robsteven192 commented 9 years ago

Thank you! Especially for the quick fix!