You are here: Re: serialize with UPDATE query « PHP Programming Language « IT news, forums, messages
Re: serialize with UPDATE query

Posted by Erwin Moller on 10/27/90 11:32

crescent_au@yahoo.com wrote:

> hi all,
>
> How do I use serialize with MySQL's UPDATE query?
>
> I have an array, $x = (1, 5, 9).
>
> My MySQL table:
>
> id x_id y_id
> --- ------- --------
> 1 1 5
> 2 1 4
> 3 2 5
> 4 1 2
>
> I would like to update the table with values of array $x where x_id ==
> 1. How do I achieve this using serialize()?
>

Hi Ben,

I am confused.
which column do you want to update?
And what values should it be?

Do you want to store a serialized array in some column and cannot figure out
the syntax?

Here is some example, but it may not be appropriate in your situation
because I do not understand 100%.

***********************
// example:
create table tbltest (
testid serial primary key,
somevalue text
)

$x = array(1,5,9);
// store serialized array $x in column where x_id is 1 in tbltest
$thevalue = serialize($x);
$SQL = "UPDATE tbltest SET somevalue='".$thevalue."' where testid=1;";

// go execute $SQL

***********************

Hope that helps.
If you serialize some array, the result is a string. So maybe add a function
that makes the string (stored in $thevalue here above) safe, just to be
sure that the serialized string contains no characters that might screw up
the query (like ').
In mysql that is called mysql_escape_string().

mysql_escape_string -- Escapes a string for use in a mysql_query
Description
string mysql_escape_string ( string unescaped_string )


Hope this help.
Regards,
Erwin Moller

> Thank you!!
> Ben

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация