Reply to Re: Database suggestion

Your name:

Reply:


Posted by Norman Peelman on 12/05/07 17:26

Mikhail Kovalev wrote:
> On 5 Des, 14:11, "C. (http://symcbean.blogspot.com/)"
> <colin.mckin...@gmail.com> wrote:
>> On 5 Dec, 11:13, Mikhail Kovalev <mikhail_kova...@mail.ru> wrote:
>>
>>> Hi.
>>> I work with recursive array trees of 10-20 levels in PHP. So far I
>>> have been using serialize() to store the arrays, generating files 5+
>>> MB large, which take 10-15 seconds to unserialize and about tenfold of
>>> RAM! I've been adviced to use MySQL (relational db's), but are there
>>> any other options beside that and var_export/include? Something that
>>> works in a similar way as MySQL when adding a new element without
>>> loading the whole database itself...
>>> Thanks!
>> Any relational DB can model a hierarchical data structure - at the
>> simplest level:
>>
>> node_id unique identifier, not null
>> parent_node null
>> payload whatever
>>
>> But getting the threaded structure is a bit tricky -
>>
>> SELECT parent.node_id as Parent_node_id, parent.payload as
>> parent_payload,
>> child.node_id as child_node_id, child.payload as child_payload
>> FROM mytable parent, mytable child
>> WHERE child.parent_node=parent.node_id
>> AND parent.node_id=$start_here
>>
>> .. i.e. by explicitly declaring aliases for each level in the tree you
>> can get the sub-nodes, but when you don't know how deep the tree is,
>> its not possible to return the whole structure in a single query using
>> standard SQL. Oracle allows you to compose queries returning
>> representations of hierarchical data (have a google for 'connect by' &
>> 'start with') but thats rather non-standard.
>
> I don't know how deep the tree is, but I don't need to return the
> whole structure in a single query. Alas, I don't know the nature of
> MySQL
>
> At this moment everything I do with my structure happens by calling
> addresses
> See my reply to The Natural Philosopher.
> Here's an example with one node at top level and it's childs:
>
> 112 (10)
> 225 (3)
> 930 (1)
> 11 (5)
>
> $array[112][COUNT] = 10;
> $array[112][NEXT][225][COUNT] = 3;
> $array[112][NEXT][225][NEXT][930][COUNT] = 1;
> $array[112][NEXT][225][NEXT][930][NEXT] = array();
> $array[112][NEXT][11][COUNT] = 5;
> $array[112][NEXT][11][NEXT] = array();
>
> An address is an array, f ex array(112, 225, 930)
>
> I then use the following mechanism:
>
> // retrieves a node with its two values as an array(COUNT, NEXT)
> // NEXT contain further childs, but i dont use them
> // array_1 is the whole structure, and array_2 is the address
> function function_7($array_1, $array_2) { return eval('retur
> $array_1'.function_8($array_2).';'); }
>
> // array(112, 225, 930) becomes "[112][NEXT][225][NEXT][930]"
> function function_8($array_1) { return implode('[NEXT]',
> array_map('function_9', $array_1)); }
>
> function function_9($integer_1) { return '['.$integer_1.']'; }
>
> // saves a value array_3 to an address array_2 in structure array_1
> function function_10($array_1, $array_2, $array_3)
> {
> eval('$array_1'.function_8($array_2).' = $array_3;');
> return $array_1;
> }

Tried to look up on Markov chains... are any of your addresses
duplicated? ie: can you have an address like 112, 225, 112 ?

Norm

[Back to original 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

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