FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » string to array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: string to array [message #177266 is a reply to message #177261] Fri, 02 March 2012 18:09 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 3/2/2012 12:03 PM, M. Strobel wrote:
> 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
>

Property tables are quite useful. And how much of your design are you
going to have to change if you do need to go to another database like
Oracle, SQL Server, DB2 or even MySQL?

I do not like being tied to a single database. I've seen too many
disasters that way.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Name of page itself?
Next Topic: How to place an image within another image at a certain position while retaining transparency using gd
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 01:47:55 GMT 2024

Total time taken to generate the page: 0.04062 seconds