473,385 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

mysql and serialized php objects?Q

Hello,

following problem: I use a mysql query string like

$arg= " insert into ".$sometable;
$arg.=" (id, col1) ";
$arg.="values ( '$this->id', '$data' ) ";
^^^^^^
$data is a product of
serialize($some_object)

The serialization has many different symbols and I experience problems from
MySQL.
I have tried to use just another string or the base64-variant of my
serialized object and it works!

So, is there some more elegant way of saving objects as strings than
encoding them after serialization
as base64?

thanks
-- Peter


Jul 17 '05 #1
3 3462
PeterF wrote:
following problem: I use a mysql query string like

$arg= " insert into ".$sometable;
$arg.=" (id, col1) ";
$arg.="values ( '$this->id', '$data' ) ";
^^^^^
$data is a product of serialize($some_object)


Well, addslashes() to it, or mysql_escape_string() it

$data = addslashes($data);

/* OR */

$data = mysql_escape_string($data);
before building the sql query string.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Hi Peter,

On Tue, 9 Mar 2004 17:57:18 +0100, "PeterF"
<NO*************@pf-webservices.de> wrote:
Hello,

following problem: I use a mysql query string like

$arg= " insert into ".$sometable;
$arg.=" (id, col1) ";
$arg.="values ( '$this->id', '$data' ) ";
^^^^^^
$data is a product of
serialize($some_object)
Try using mysql_escape_string() on the insert only. Also check out
get_magic_quotes_runtime() and stripslashes()

HTH, Jochen

The serialization has many different symbols and I experience problems from
MySQL.
I have tried to use just another string or the base64-variant of my
serialized object and it works!

So, is there some more elegant way of saving objects as strings than
encoding them after serialization
as base64?

thanks
-- Peter


--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #3
On Tue, 9 Mar 2004 17:57:18 +0100, "PeterF" <NO*************@pf-webservices.de>
wrote:
following problem: I use a mysql query string like

$arg= " insert into ".$sometable;
$arg.=" (id, col1) ";
$arg.="values ( '$this->id', '$data' ) ";
^^^^^^
$data is a product of
serialize($some_object)

The serialization has many different symbols and I experience problems from
MySQL.
What SORT of problems?

Errors? Which ones? What messages?
Corruption? How could you tell? What did you try?
Explosions? What colour was the smoke?
I have tried to use just another string or the base64-variant of my
serialized object and it works!

So, is there some more elegant way of saving objects as strings than
encoding them after serialization
as base64?


Some would say that saving it in a schema that itself represents the
attributes of the object is more elegant, rather than serialising and storing
in an unstructured column.

What column type are you using, anyway?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #4

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

Similar topics

1
by: Tejus | last post by:
Hi all, I have a diffculty. I am writing a set serialized objects into a file and sending it over to socket to another prog. Now the prog should read the object and do some work and after...
1
by: Nels P. Olsen | last post by:
If you serialize an object graph to persist it somewhere (e.g. a database) between application sessions, then you run into trouble if the serialized objects' existing field order or datatypes change,...
0
by: Ray Mitchell | last post by:
Hello, The result of auto-converting some Java code to C# yielded the following upgrade issue regarding the original Java call to "reset()": public virtual void writeObj(Object obj) {...
0
by: Wim Hollebrandse | last post by:
Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML. For...
1
by: Bill Cohagan | last post by:
We are attempting to convert an already existing application over to using multiple worker processes; thus we need to store state via session state server rather than in process. Since this app...
7
by: Neal Andrews | last post by:
Hi All, Does anyone know how to stop Events from being serialized in a class that uses the <Serializable()> attribute? I have tried using the <NonSerialized()> attribute but for some bizarre...
0
by: rlaemmler | last post by:
Hi, I just migrated my web app to .NET 2.0. Part of the app creates some business objects from a MySQL query which is returned by a web service. Some of those objects contain DateTime...
3
by: MMiGG | last post by:
Hi Our project need parse JAVA serialized object string in C, has any library? Thanx
9
by: PI | last post by:
Hi Guys, I need some assistance with the following scenario please. I know this might be more of a MySQL post than a PHP one, but it is likely some developer has been here before and would be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.