Re: [PHP-DB] Storing an array on a table?

2005-09-02 Thread Fen Lu
Now you got tow ways. 
serialize or convernt to a string~
I think string is better~
maybe I'm getting old~
don't like new things like serialize...;-)

On 9/1/05, Miguel Guirao <[EMAIL PROTECTED]> wrote:
> 
> 
> 
> Hi!!
> 
> I want to store an array into a field on a MySQL table, Is it posible to
> save it? Maybe into a string field?
> Best Regards,
> 
> ---
> Miguel Guirao Aguilera
> Logistica R8 TELCEL
> Tel. (999) 960.7994
> 
> 
> Este mensaje es exclusivamente para el uso de la persona o entidad a quien 
> esta dirigido; contiene informacion estrictamente confidencial y legalmente 
> protegida, cuya divulgacion es sancionada por la ley. Si el lector de este 
> mensaje no es a quien esta dirigido, ni se trata del empleado o agente 
> responsable de esta informacion, se le notifica por medio del presente, que 
> su reproduccion y distribucion, esta estrictamente prohibida. Si Usted 
> recibio este comunicado por error, favor de notificarlo inmediatamente al 
> remitente y destruir el mensaje. Todas las opiniones contenidas en este mail 
> son propias del autor del mensaje y no necesariamente coinciden con las de 
> Radiomovil Dipsa, S.A. de C.V. o alguna de sus empresas controladas, 
> controladoras, afiliadas y subsidiarias. Este mensaje intencionalmente no 
> contiene acentos.
> 
> This message is for the sole use of the person or entity to whom it is 
> being sent. Therefore, it contains strictly confidential and legally 
> protected material whose disclosure is subject to penalty by law. If the 
> person reading this message is not the one to whom it is being sent and/or 
> is not an employee or the responsible agent for this information, this 
> person is herein notified that any unauthorized dissemination, distribution 
> or copying of the materials included in this facsimile is strictly 
> prohibited. If you received this document by mistake please notify 
> immediately to the subscriber and destroy the message. Any opinions 
> contained in this e-mail are those of the author of the message and do not 
> necessarily coincide with those of Radiomovil Dipsa, S.A. de C.V. or any 
> of its control, controlled, affiliates and subsidiaries companies. No part 
> of this message or attachments may be used or reproduced in any manner 
> whatsoever.
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
>From : Fen lu


Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread tg-php
Ahh..thanks Jordan.. sorry I missed that one and thanks for the info.  I 
assumed serialize was just magic and worked properly. hah.   Now I know.

I always thought it was sloppy to use anyway, but in a pinch, it's nice to know 
there's an option like that.   Imploding does sound better though.

-TG

= = = Original message = = =

Yes, this has been mentioned in this thread. But with serialize/ 
unserialize, you can run into other problems that may be more  
confusing/difficult to troubleshoot. e.g.:

http://www.php.net/serialize

> >As you can see, the original array :
> >$arr["20041001103319"] = "test"
> >
> >after serialize/unserialize is:
> >$arr[683700183] = "test"
>
> yepp, and i can explain it.
>
> the internal compiler of php does not hit anys rule wich foces him  
> to make that number a string during serialisation. since it becomes  
> an integer and php supports 32bit interger not arbitary bitwidth  
> this is what happens:
>
> "20041001103319"
> equals hexadecimal:
>
> 0x123A28C06FD7h
>
> if you cut away the frontpart cutting down to 32bis,
> you get:
>
> 0x28C06FD7h
>
> wich equals 683700183.


For simple arrays, I prefer storing everything as a simple imploded  
string. YMMV.

Jordan





On Sep 1, 2005, at 10:18 AM, <[EMAIL PROTECTED]>  wrote:

> Sorry, didn't catch this thread from the beginning, but did anyone  
> recommend trying the serialize() and unserialize() commands?   
> They'll convert the array to a block of text that can be stored,  
> retrieved and unserialized.
>
> My gut instinct is that if you're trying to store any array in a  
> database, you may not have thought through your design very well.
> BUT.. I also know that there are cases where you might want to  
> (I've actually done it before... being lazy in that case..hah) so  
> dont take that as criticism, just wondering if there's a "more  
> right" way to do it.
>
> If that's what you need to do though, definitely check out  
> serialize (unless someone knows something I don't).
>
> Serialize() should do essentially what's being proposed below, just  
> without having to figure out what string may not be in your array.
>
> good luck!
>
> -TG
>
>
> = = = Original message = = =
>
> if you just have a simple array with automatic numeric keys and text
> you could just implode the data to a string with a separator not
> found in your data:
> $dataArray = array("hello", "goodbye", "etc.");
> $storable = implode("", $dataArray);
> // $storable becomes "hellogoodbyeetc."
>
> //then, use explode to get the original array back again
> $dataArray = explode("", $storable);
>
> you could use a similar technique if you want to put the keys in as
> well, albeit slightly more complicated (e.g. use "" to separate
> each element in the array and "||" to separate each key from its
> value). Just find a divider you know your data will not contain, such
> as a pipe: "|".
>
> This has worked well for me.
>
> Jordan
>
>
>
> On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:
>
>
>
>>
>> I want to store an array into a field on a MySQL table, Is it
>> posible to
>> save it? Maybe into a string field?


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Storing an array on a table?

2005-09-01 Thread Miguel Guirao


Thanks to you all for your replies!!
They are of great help

---
Miguel Guirao Aguilera
Logistica R8 TELCEL
Tel. (999) 960.7994



-Original Message-
From: Jordan Miller [mailto:[EMAIL PROTECTED]
Sent: Jueves, 01 de Septiembre de 2005 10:28 a.m.
To: [EMAIL PROTECTED]
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Storing an array on a table?


Yes, this has been mentioned in this thread. But with serialize/ 
unserialize, you can run into other problems that may be more  
confusing/difficult to troubleshoot. e.g.:

http://www.php.net/serialize

> >As you can see, the original array :
> >$arr["20041001103319"] = "test"
> >
> >after serialize/unserialize is:
> >$arr[683700183] = "test"
>
> yepp, and i can explain it.
>
> the internal compiler of php does not hit anys rule wich foces him  
> to make that number a string during serialisation. since it becomes  
> an integer and php supports 32bit interger not arbitary bitwidth  
> this is what happens:
>
> "20041001103319"
> equals hexadecimal:
>
> 0x123A28C06FD7h
>
> if you cut away the frontpart cutting down to 32bis,
> you get:
>
> 0x28C06FD7h
>
> wich equals 683700183.


For simple arrays, I prefer storing everything as a simple imploded  
string. YMMV.

Jordan





On Sep 1, 2005, at 10:18 AM, <[EMAIL PROTECTED]>  wrote:

> Sorry, didn't catch this thread from the beginning, but did anyone  
> recommend trying the serialize() and unserialize() commands?   
> They'll convert the array to a block of text that can be stored,  
> retrieved and unserialized.
>
> My gut instinct is that if you're trying to store any array in a  
> database, you may not have thought through your design very well.
> BUT.. I also know that there are cases where you might want to  
> (I've actually done it before... being lazy in that case..hah) so  
> dont take that as criticism, just wondering if there's a "more  
> right" way to do it.
>
> If that's what you need to do though, definitely check out  
> serialize (unless someone knows something I don't).
>
> Serialize() should do essentially what's being proposed below, just  
> without having to figure out what string may not be in your array.
>
> good luck!
>
> -TG
>
>
> = = = Original message = = =
>
> if you just have a simple array with automatic numeric keys and text
> you could just implode the data to a string with a separator not
> found in your data:
> $dataArray = array("hello", "goodbye", "etc.");
> $storable = implode("", $dataArray);
> // $storable becomes "hellogoodbyeetc."
>
> //then, use explode to get the original array back again
> $dataArray = explode("", $storable);
>
> you could use a similar technique if you want to put the keys in as
> well, albeit slightly more complicated (e.g. use "" to separate
> each element in the array and "||" to separate each key from its
> value). Just find a divider you know your data will not contain, such
> as a pipe: "|".
>
> This has worked well for me.
>
> Jordan
>
>
>
> On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:
>
>
>
>>
>> I want to store an array into a field on a MySQL table, Is it
>> posible to
>> save it? Maybe into a string field?
>>
>>
>>
>
>
> ___
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta 
dirigido; contiene informacion estrictamente confidencial y legalmente 
protegida, cuya divulgacion es sancionada por la ley. Si el lector de este 
mensaje no es a quien esta dirigido, ni se trata del empleado o agente 
responsable de esta informacion, se le notifica por medio del presente, que su 
reproduccion y distribucion, esta estrictamente prohibida. Si Usted recibio 
este comunicado por error, favor de notificarlo inmediatamente al remitente y 
destruir el mensaje. Todas las opiniones contenidas en este mail son propias 
del autor del mensaje y no necesariamente coinciden con las de Radiomovil 
Dipsa, S.A. de C.V. o alguna de sus empresas controladas, controladoras, 
afiliadas y subsidiarias. Este mensaje intencionalmente no contiene acentos.

This message is for the sole use of the person or

Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread Jordan Miller
Yes, this has been mentioned in this thread. But with serialize/ 
unserialize, you can run into other problems that may be more  
confusing/difficult to troubleshoot. e.g.:


http://www.php.net/serialize


>As you can see, the original array :
>$arr["20041001103319"] = "test"
>
>after serialize/unserialize is:
>$arr[683700183] = "test"

yepp, and i can explain it.

the internal compiler of php does not hit anys rule wich foces him  
to make that number a string during serialisation. since it becomes  
an integer and php supports 32bit interger not arbitary bitwidth  
this is what happens:


"20041001103319"
equals hexadecimal:

0x123A28C06FD7h

if you cut away the frontpart cutting down to 32bis,
you get:

0x28C06FD7h

wich equals 683700183.



For simple arrays, I prefer storing everything as a simple imploded  
string. YMMV.


Jordan





On Sep 1, 2005, at 10:18 AM, <[EMAIL PROTECTED]> [EMAIL PROTECTED]> wrote:


Sorry, didn't catch this thread from the beginning, but did anyone  
recommend trying the serialize() and unserialize() commands?   
They'll convert the array to a block of text that can be stored,  
retrieved and unserialized.


My gut instinct is that if you're trying to store any array in a  
database, you may not have thought through your design very well.
BUT.. I also know that there are cases where you might want to  
(I've actually done it before... being lazy in that case..hah) so  
dont take that as criticism, just wondering if there's a "more  
right" way to do it.


If that's what you need to do though, definitely check out  
serialize (unless someone knows something I don't).


Serialize() should do essentially what's being proposed below, just  
without having to figure out what string may not be in your array.


good luck!

-TG


= = = Original message = = =

if you just have a simple array with automatic numeric keys and text
you could just implode the data to a string with a separator not
found in your data:
$dataArray = array("hello", "goodbye", "etc.");
$storable = implode("", $dataArray);
// $storable becomes "hellogoodbyeetc."

//then, use explode to get the original array back again
$dataArray = explode("", $storable);

you could use a similar technique if you want to put the keys in as
well, albeit slightly more complicated (e.g. use "" to separate
each element in the array and "||" to separate each key from its
value). Just find a divider you know your data will not contain, such
as a pipe: "|".

This has worked well for me.

Jordan



On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:





I want to store an array into a field on a MySQL table, Is it
posible to
save it? Maybe into a string field?






___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread tg-php
Sorry, didn't catch this thread from the beginning, but did anyone recommend 
trying the serialize() and unserialize() commands?  They'll convert the array 
to a block of text that can be stored, retrieved and unserialized.

My gut instinct is that if you're trying to store any array in a database, you 
may not have thought through your design very well.   BUT.. I also know that 
there are cases where you might want to (I've actually done it before... being 
lazy in that case..hah) so dont take that as criticism, just wondering if 
there's a "more right" way to do it.

If that's what you need to do though, definitely check out serialize (unless 
someone knows something I don't).

Serialize() should do essentially what's being proposed below, just without 
having to figure out what string may not be in your array.

good luck!

-TG


= = = Original message = = =

if you just have a simple array with automatic numeric keys and text  
you could just implode the data to a string with a separator not  
found in your data:
$dataArray = array("hello", "goodbye", "etc.");
$storable = implode("", $dataArray);
// $storable becomes "hellogoodbyeetc."

//then, use explode to get the original array back again
$dataArray = explode("", $storable);

you could use a similar technique if you want to put the keys in as  
well, albeit slightly more complicated (e.g. use "" to separate  
each element in the array and "||" to separate each key from its  
value). Just find a divider you know your data will not contain, such  
as a pipe: "|".

This has worked well for me.

Jordan



On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:


>
> I want to store an array into a field on a MySQL table, Is it  
> posible to
> save it? Maybe into a string field?
>
>


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Storing an array on a table?

2005-09-01 Thread Jordan Miller
if you just have a simple array with automatic numeric keys and text  
you could just implode the data to a string with a separator not  
found in your data:

$dataArray = array("hello", "goodbye", "etc.");
$storable = implode("", $dataArray);
// $storable becomes "hellogoodbyeetc."

//then, use explode to get the original array back again
$dataArray = explode("", $storable);

you could use a similar technique if you want to put the keys in as  
well, albeit slightly more complicated (e.g. use "" to separate  
each element in the array and "||" to separate each key from its  
value). Just find a divider you know your data will not contain, such  
as a pipe: "|".


This has worked well for me.

Jordan



On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:




I want to store an array into a field on a MySQL table, Is it  
posible to

save it? Maybe into a string field?




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Storing an array on a table?

2005-09-01 Thread Bastien Koert
yes, check out the serialize and unserialize fuinctions in the manual 
(www.php.net/serialize)


bastien



From: Miguel Guirao <[EMAIL PROTECTED]>
To: php-db@lists.php.net
Subject: [PHP-DB] Storing an array on a table?
Date: Thu, 01 Sep 2005 08:55:24 -0500



Hi!!

I want to store an array into a field on a MySQL table, Is it posible to
save it? Maybe into a string field?
Best Regards,

---
Miguel Guirao Aguilera
Logistica R8 TELCEL
Tel. (999) 960.7994


Este mensaje es exclusivamente para el uso de la persona o entidad a quien 
esta dirigido; contiene informacion estrictamente confidencial y legalmente 
protegida, cuya divulgacion es sancionada por la ley. Si el lector de este 
mensaje no es a quien esta dirigido, ni se trata del empleado o agente 
responsable de esta informacion, se le notifica por medio del presente, que 
su reproduccion y distribucion, esta estrictamente prohibida. Si Usted 
recibio este comunicado por error, favor de notificarlo inmediatamente al 
remitente y destruir el mensaje. Todas las opiniones contenidas en este 
mail son propias del autor del mensaje y no necesariamente coinciden con 
las de Radiomovil Dipsa, S.A. de C.V. o alguna de sus empresas controladas, 
controladoras, afiliadas y subsidiarias. Este mensaje intencionalmente no 
contiene acentos.


This message is for the sole use of the person or entity to whom it is 
being sent.  Therefore, it contains strictly confidential and legally 
protected material whose disclosure is subject to penalty by law.  If the 
person reading this message is not the one to whom it is being sent and/or 
is not an employee or the responsible agent for this information, this 
person is herein notified that any unauthorized dissemination, distribution 
or copying of the materials included in this facsimile is strictly 
prohibited.  If you received this document by mistake please notify  
immediately to the subscriber and destroy the message. Any opinions 
contained in this e-mail are those of the author of the message and do not 
necessarily coincide with those of Radiomovil Dipsa, S.A. de C.V. or any of 
its control, controlled, affiliates and subsidiaries companies. No part of 
this message or attachments may be used or reproduced in any manner 
whatsoever.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Storing an array on a table?

2005-09-01 Thread Miguel Guirao


Hi!!

I want to store an array into a field on a MySQL table, Is it posible to
save it? Maybe into a string field?
Best Regards,

---
Miguel Guirao Aguilera
Logistica R8 TELCEL
Tel. (999) 960.7994


Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta 
dirigido; contiene informacion estrictamente confidencial y legalmente 
protegida, cuya divulgacion es sancionada por la ley. Si el lector de este 
mensaje no es a quien esta dirigido, ni se trata del empleado o agente 
responsable de esta informacion, se le notifica por medio del presente, que su 
reproduccion y distribucion, esta estrictamente prohibida. Si Usted recibio 
este comunicado por error, favor de notificarlo inmediatamente al remitente y 
destruir el mensaje. Todas las opiniones contenidas en este mail son propias 
del autor del mensaje y no necesariamente coinciden con las de Radiomovil 
Dipsa, S.A. de C.V. o alguna de sus empresas controladas, controladoras, 
afiliadas y subsidiarias. Este mensaje intencionalmente no contiene acentos.

This message is for the sole use of the person or entity to whom it is being 
sent.  Therefore, it contains strictly confidential and legally protected 
material whose disclosure is subject to penalty by law.  If the person reading 
this message is not the one to whom it is being sent and/or is not an employee 
or the responsible agent for this information, this person is herein notified 
that any unauthorized dissemination, distribution or copying of the materials 
included in this facsimile is strictly prohibited.  If you received this 
document by mistake please notify  immediately to the subscriber and destroy 
the message. Any opinions contained in this e-mail are those of the author of 
the message and do not necessarily coincide with those of Radiomovil Dipsa, 
S.A. de C.V. or any of its control, controlled, affiliates and subsidiaries 
companies. No part of this message or attachments may be used or reproduced in 
any manner whatsoever.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php