Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Your error have been to serialize the datas into the DB.
The serialization is a process that turns a data type into a string representation.
If you wanted to store a flexible data structure, you should have created a normalized DB schema, and stored each of the object values in the db individually.
The db cannot search (or with much difficulty, and very unoptimized) because the structure of the datas you saved is not usable as is, it needs to be processed again to be usable.
You should have 2 tables for the datas: 1 with the "header", another with the fields.
As PHP is not strongly typed, you can use a varchar type for each variables, like this
Code:
create table header(
headerId integer not null auto_increment,
primary key headerId
);
create table vals(
headerFk integer not null,
valName varchar(255) not null,
val varchar(255) not null,
primary key (headerFk, valName)
);
With this, you can create 1 header, and attach as many variable with their values as you need.
Looking for a particular value is a matter of a select in the vals table, which will return you an headerFk value, and allows you to get back every variables attached to that header.
Once you will have separated your structure that way, you won't need any data mangling or (un)serialization to lookup your datas.
__________________
Only a biker knows why a dog sticks his head out the window.
|