Hi,
I tried to pack eight integer values and one string into one binary
string, which I would like to store in a mysql db.
I encountered two problems doing this:
1)
$this->packed = pack('N8A*', $this->value1, $this->value2,
$this->value3, $this->value4, $this->value5, $this->value6,
$this->value7, $this->value8, $this->stringvalue);
$array = unpack('N8A*', $this->packed);
print_r($array);
returns:
Array ( [A*1] => 0 [A*2] => 0 [A*3] => 2 [A*4] => 0 [A*5] => 0 [A*6]
=> 91 [A*7] => 0 [A*8] => 1 )
instead of packing the string also. 'N8 A*' doesn't work at all.
2)
I started storing only the seven integers in the binary string and
wanted to write them into the database.
I used a column "packed varchar(50) binary not null default '';".
To store the data I used
$packed = addslashes($classname->packed);
mysql_query("UPDATE $table SET packed='$packed' WHERE ...");
as well as without addslashes().
I also changed the column type to "packed tinyblob not null;" what I
didn't liked much as I would like to reduce the amount of space as
much as possible.
Whatever I did, I got a string back that looked simular when I print
it, but it didn't unpack() to the former values.
Now I have two questions:
- How can I pack several data types into one binary string (8
integers and one string) using pack()? How should the format string
look like?
- How can I store such a binary string in a database?
Thanks in advance,
Johannes