franzwarning Posted April 4, 2012 Share Posted April 4, 2012 Hi there, How could I get the value of every 4 bytes of a BLOB? Additionally, how can I add an item to the end of a BLOB and store it back in the database? Cheers, George Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/ Share on other sites More sharing options...
Xtremer360 Posted April 4, 2012 Share Posted April 4, 2012 I'm not sure about this but curious on the purpose of it. Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334440 Share on other sites More sharing options...
franzwarning Posted April 4, 2012 Author Share Posted April 4, 2012 I plan on storing multiple user_id's in binary format, assuming each id is an int (4 bytes). Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334441 Share on other sites More sharing options...
franzwarning Posted April 4, 2012 Author Share Posted April 4, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334443 Share on other sites More sharing options...
kicken Posted April 4, 2012 Share Posted April 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334447 Share on other sites More sharing options...
franzwarning Posted April 4, 2012 Author Share Posted April 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334448 Share on other sites More sharing options...
kicken Posted April 4, 2012 Share Posted April 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334450 Share on other sites More sharing options...
franzwarning Posted April 4, 2012 Author Share Posted April 4, 2012 Alright, you've convinced me. Cheers, Raymond Quote Link to comment https://forums.phpfreaks.com/topic/260356-traverse-a-blob/#findComment-1334480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.