Jump to content

Traverse a blob


franzwarning

Recommended Posts

After doing some research, I think I can do it like this:

<?php
$result    = ibase_query("SELECT blob_value FROM table");
$data      = ibase_fetch_object($result);
$blob_data = ibase_blob_info($data->BLOB_VALUE);
$blob_hndl = ibase_blob_open($data->BLOB_VALUE);
echo         ibase_blob_get($blob_hndl, $blob_data[0]);
?>

But what is ibase? Is it like mysql_query but for BLOBS?

Link to comment
Share on other sites

Why are you trying to store multiple user id's in a blob?  Just store one per row in a normal int column.  As for ibase, it is a different database system.  If your using mysql, you use it's functions not the ibase* functions.

 

As for working with binary data, you'd use pack and unpack but I believe your approach is incorrect.

 

Link to comment
Share on other sites

I feel like that's less efficient though. I have a table called groups, where each row contains a group id, and all the member of that group in a BLOB.

 

No, what your proposing is less efficient and harder to use.  Databases are designed to work with tables composed of many rows.  Creating a new row per id is what it will do and handle best.

 

Think about this, what happens when you decide you want to list out all the members of a group and their details (name, email, phone, whatever you have).

 

With your method you have to:

- Select the BLOB from the table

- Use PHP to decode the ID's from the table

- Run a second query to get the details for each user

- Display the results

 

If you do one row per user ID, then all you have to do is

- Run a single query for the details

- Display the results

 

What if you decide you want to paginate the results because there are a lot of members?  Your method becomes increasingly more complicated and harder to deal with, while one-row-per-user method only has to alter the query to include a LIMIT clause.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.