473,626 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem When Serializing Array With Multiline Text

Hello everyone.

I have a question, or problem if you will, that I'm sure someone knows
the answer to. I have a database that stores information on a given
user. The information is stored in a serialized array. This works
flawlessly when using only single line text. When I tried to store
multiline text, the problem arose.

When the serialized data is deserialized, the array breaks. Any
suggestions?

Apr 29 '07 #1
6 2989
dawnerd wrote:
Hello everyone.

I have a question, or problem if you will, that I'm sure someone knows
the answer to. I have a database that stores information on a given
user. The information is stored in a serialized array. This works
flawlessly when using only single line text. When I tried to store
multiline text, the problem arose.

When the serialized data is deserialized, the array breaks. Any
suggestions?
I don't even try to to store serialized data in a database. Rather, I
create a database which reflects the data being used.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 30 '07 #2
On Apr 30, 6:20 am, dawnerd <dawn...@gmail. comwrote:
Hello everyone.

I have a question, or problem if you will, that I'm sure someone knows
the answer to. I have a database that stores information on a given
user. The information is stored in a serialized array. This works
flawlessly when using only single line text. When I tried to store
multiline text, the problem arose.

When the serialized data is deserialized, the array breaks. Any
suggestions?
I test (on windows using CLI):

$a[] = "username";
$a[] = 15;
$a[] = "Not Found Street\n12345\n Nowhere City";
$a[] = "Not Found Street\r\n12345 \r\nNowhere City";
$k = serialize($a);
$u = unserialize($k) ;
var_dump($a);
var_dump($k);
var_dump($u);

Seems fine for me.

Please show us:
1. The content of the serialized variable before it stored to
database?
2. The content of the deserialized variable picked from database?
3. Field type you use to store serialized data?

Apr 30 '07 #3
On Apr 30, 1:20 am, dawnerd <dawn...@gmail. comwrote:
Hello everyone.

I have a question, or problem if you will, that I'm sure someone knows
the answer to. I have a database that stores information on a given
user. The information is stored in a serialized array. This works
flawlessly when using only single line text. When I tried to store
multiline text, the problem arose.

When the serialized data is deserialized, the array breaks. Any
suggestions?
Compare the length of the serialized string before and after. I bet
you it's a CRLF vs CR issue. The lengths of strings are stored in the
serialization data. If it loses or gains a character upon retrieval,
then unserial() won't work.

Apr 30 '07 #4
On Apr 29, 7:48 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
dawnerd wrote:
Hello everyone.
I have a question, or problem if you will, that I'm sure someone knows
the answer to. I have a database that stores information on a given
user. The information is stored in a serialized array. This works
flawlessly when using only single line text. When I tried to store
multiline text, the problem arose.
When the serialized data is deserialized, the array breaks. Any
suggestions?

I don't even try to to store serialized data in a database. Rather, I
create a database which reflects the data being used.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===

I would use a database just for the information, but the inforation
being stored is site owner defined. They can add or remove fields as
needed. I will post some more info on the problem when I get off work.

Apr 30 '07 #5
Do you use the relevant real_escape_str ing() function on the
serialized data before inserting into the database? It does escape
newlines, which I have never seen being a problem anyway, but it is
good practice nonetheless. If you are just using addslashes(), it's
not escaping newlines.

-Mike PII

Apr 30 '07 #6
dawnerd wrote:
I would use a database just for the information, but the inforation
being stored is site owner defined. They can add or remove fields as
needed. I will post some more info on the problem when I get off work.
The problem is that it will knacker your query time. Compare for example:

Surname* Forename(s)* Organisation Nationality
-------------------------------------------------------------------
Gates Bill Microsoft US
Jobs Steve Apple, Inc US
Torvalds Linus Linux Foundation FI

versus:

ID* Object
-------------------------------------------------------------
1 array('sn'=>'Ga tes', 'fn'=>'Gates', 'o'=>'Microsoft ', 'co'=>'US')
2 array('sn'=>'Jo bs', 'fn'=>'Steve', 'o'=>'Apple, Inc', 'co'=>'US')
3 array('sn'=>'To rvalds', 'fn'=>'Linus', 'o'=>'Linux Foundation', 'co'=>FI')

(An asterisk represents a primary key column. Note I'm using the case
where you'd never want to store more than one person with the same surname
and forename, which is arguably not very realistic.)

Now, say you want to store Rasmus Lerdorf of Yahoo. In the first model,
you'd just insert

'Lerdorf', 'Rasmus', 'Yahoo', 'GL'

And the database would reject it if there was already a Rasmus Lerdorf in
the database, as the Surname and Forename columns are the primary key.

In the latter, there would be no check for duplicates. If you wanted to
check for duplicates, your code would need to loop through the entire
table, read and parse each row to find duplicates, and only insert the
data when there is no duplicate. This might be fine for a table of 3
records, but when you have thousands, then it will cripple your
application's speed.

A search for all people with surname Gates who work at Microsoft would
similarly require your application to loop through each row and parse the
serialised object.

If you really do need to be able to define additional fields of data on
the fly, then you can easily do so through an "attributes " table. e.g.

[People]
Surname* Forename(s)* Organisation Nationality
-------------------------------------------------------------------
Gates Bill Microsoft US
Jobs Steve Apple, Inc US
Torvalds Linus Linux Foundation FI

[Attributes]
Surname* Forename(s)* Attribute Value
------------------------------------------------------
Gates Bill hair-colour Brown
Gates Bill favourite-os Windows Vista
Jobs Steve favourite-os Mac OS X (Leopard)
Torvalds Linus favourite-os Linux

This method should give you complete freedom to define new fields in the
Attributes table, while keeping the core fields in the People table. Easy.

You can even do complex joins to figure out, say, a list of people with
brown hair who like Windows Vista.

SELECT forename||' '||surname
FROM People p
INNER JOIN Attributes a1
ON al.surname=p.su rname AND a1.forename=p.f orename
INNER JOIN Attributes a2
ON a2.surname=p.su rname AND a2.forename=p.f orename
WHERE (a1.attribute=' hair-colour' AND a1.value='brown ')
AND (a2.attribute=' favourite-os' AND a2.value='Windo ws Vista');

which should return one row:

Bill Gates

(and is actually a remarkably accurate list of all people with brown hair
who like Windows Vista.)

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 1 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
8272
by: copx | last post by:
I want to save a struct to disk.... as plain text. At the moment I do it with a function that just writes the data using fprintf. I mean like this: fprintf(fp, "%d %d", my_struct.a, my_struct.b) This way I have to write another "serializing" function for every new kind of struct I want to write, though. Is there a way to write functions that can write/read any struct to/from plain text format in a portable way?
7
4026
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The problem is that only the modified data from the SingleLine TextBoxes are returned. The original data are returned for the MultiLine TextBoxes. Also, if the page is sent to the server (for validation, for instance), only the modified data for the...
0
2491
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type System.Object to an object of type ElectronicWallet.C2PTest.PaymentItem." :...
8
1997
by: David | last post by:
This is something I had never seen before. On an aspx page, upon pressing a link button for which I have an event handler in the code behind, the screen shows nothing but a line that says "true" up in the right upper corner of the browser. I have an XP and had just installed XP Service Pack II...against my better judgment. Please help. Thanks.
3
1904
by: Antonio Lopez Arredondo | last post by:
hi all again..... I have an ASP.NET application that has a multiline textbox and a single button. the user should be able to write inside the many paragraphs in the multiline textbox and then click the button to run the code behind. the problem is that when the user presses the ENTER key to insert a new line in the listbox, the button's code behind is executed.
4
3143
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is inherited from a
7
1790
by: Joe | last post by:
I've tracked the performance issue down to a single class. This class derives from CollectionBase and stores a basic value type such as string, int, double, etc... I also store the type itself which you can see I'm using when calling AddValue. I implemented ISerializable and GeteObjectData. Here's what I tried: for (int i = 0; i < this.Count; i++) info.AddValue("item" + i.ToString(), this, typeof(type) );
9
2064
by: norvinl | last post by:
Hi, I'm serializing a class and using shared memory / deserialization to send it to other processes. I can serialize with one app and deserialize with another instance of the same app. But if I try to deserialize with another different app, I get an exception (the assembly RegionViewer is the app that serialized the
2
2629
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8269
marktang
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...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2630
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
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.