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($cla ssname->packed);
mysql_query("UP DATE $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 1 2320
"Johannes" <sp*********@ly cos.de> wrote in message
news:f1******** *************** **@posting.goog le.com... 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.
Read the manual carefully. You have to assign names to the variables you're
unpacking. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stacy Mader |
last post by:
Greetings all,
I have a VMS binary file with weather data. The record
on each line is 1xint(8) 12xint(2)
Using the perl unpack function, I can decode the
binary file like this:
<snip>
|
by: Wiktor Zychla |
last post by:
I would like to be able to convert enums to their string representation but
I would like to be able to apply a custom formatting, so that I could write
for example:
enum E { a, b, c };
string s1 = E.a.ToString( "d" ); // returns for example 'a'
string s2 = E.a.ToString( "f" ); // returns for example 'this is an enum
value a'
|
by: Mark Jerde |
last post by:
(If these are the wrong groups please suggest the right one(s). Thanks.)
I need to come up with a way to test potentially thousands of data (files /
records / streams) to determine if they match one of about thirty defined
data formats. If a record partially matches one of the formats I need to
log why it failed.
The formats are byte-oriented. Byte 0 is the type, byte 1 is the subtype,
bytes 2-5 give the total record length, etc. ...
|
by: taskswap |
last post by:
I'm converting an application that relies heavily on a binary network
protocol. Within this protocol are a lot of byte arrays of character
data, like:
public unsafe struct MsgAddEntry {
public byte MsgType;
public uint Tag;
public fixed byte ID;
public fixed byte Val1;
|
by: tomerfiliba |
last post by:
hey
i've been seeing lots of config-file-readers for python. be it
ConfigObj (http://www.voidspace.org.uk/python/configobj.html) or the
like. seems like a trend to me.
i came to this conclusion a long time ago: YOU DON'T NEED CONFIG FILES
FOR PYTHON. why re-invent stuff and parse text by yourself, why the
interpreter can do it for you? and anyway, i find this a very ugly
format:...
| |
by: gogaz |
last post by:
Hi,
PHP has a function called pack() (http://us2.php.net/pack). I need to
translate some code that uses this function to C#. What's the C#
equivalent of pack()?
Basically in php
$i = 1038;
pack("N", $i);
|
by: craigkenisston |
last post by:
I need to send a big amount of data to one server in the query string.
It is like 3kb of text information, in ascii code with linefeeds and
carriage returns.
I noticed that using winzip I can get the file 1kb long. I'm not sure
if there are zip utilities for C#/Asp.Net, but I guess there are and
I'm counting on this.
Now, which methods do I have available to send the zipped file on the
query string ? I was thinking of converting the...
|
by: andmarti |
last post by:
If I build a strict with:
import struct
print struck.pack ('i', 1)
it returns a '\n'.
What's wrong with it???
:(
--
|
by: giddy |
last post by:
hi ,
I' know what the StructLayoutAttribute does. I've seen it being used.
But what does the Pack field do!?
This is what MSDN says:
Controls the alignment of data fields of a class or structure in
memory.
This field indicates the packing size that should be used when the
LayoutKind.Sequential value is specified. The value of Pack must be 0,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |