Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5077

Re: string to array

From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: string to array
Date 2012-03-02 18:03 +0100
Message-ID <9rccqeF18lU1@mid.uni-berlin.de> (permalink)
References <9rbvjcFo5nU1@mid.uni-berlin.de> <jiqmg0$ft6$1@dont-email.me>

Show all headers | View raw


Am 02.03.2012 15:46, schrieb Jerry Stuckle:
> On 3/2/2012 8:17 AM, M. Strobel wrote:
>> Hi,
>>
>> I am just testing with hstore in postgresql, this is a datatype providing a
>> key-value-store in one column (http://www.postgresql.org/docs/9.1/static/hstore.html).
>>
>> The php question is:
>>
>> A select from the table looks like this:
>>
>> trans1=>  select * from testh;
>>                               Tabelle testh
>>      n    |                              h
>> ---------+-------------------------------------------------------------
>>   Michael | "age"=>"89", "weight"=>"91", "haircolor"=>"braun"
>>   Peter   | "weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true"
>> (2 Zeilen)
>>
>> And a select gives me the h column back as a string:
>>
>> array(2) {
>>      ["n"]=>
>>      string(5) "Peter"
>>      ["h"]=>
>>      string(59) ""weight"=>"82", "haircolor"=>"rot", "has spaces"=>"is true""
>>
>> This looks like php source code. How could I just eval it to get a php array?
>>
>> /Str.
> 
> Don't use it.  It's a bad design and fails normalization (one value in a column).  It
> also s not easily searchable nor can you modify values easily.  You also don't run
> into problems like this.
> 
> A much better way is to have a separate table with key and value columns and a
> reference column.

"bad design" and "fails normalization" is generally true, but I am just fed up with
yet another properties table. hstore is made for it, it is searchable and changeable,
but nonstandard.

I think it would be an elegant solution if I would not have to read in the properties
separately, but the whole class in one take, and "explode" this string into an array.

/Str

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 14:17 +0100
  Re: string to array Captain Paralytic <paul_lautman@yahoo.com> - 2012-03-02 06:02 -0800
    Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:09 +0100
      Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 13:07 -0500
  Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 09:46 -0500
    Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:03 +0100
      Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 13:09 -0500
        Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 19:38 +0100
          Re: string to array Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-02 14:49 -0500
    Re: string to array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-03-02 18:37 +0100

csiph-web