View Full Version : How does the datastore system work?
There are some aspects of vb that are not obvious. The datastore looks interesting. Can someone familiar with the code provide an overview of how it works?
Andreas
11-24-2004, 09:12 PM
Well ... datastore is nothing mysterious.
The table holds serialized content of variables (mostly arrays).
If you want to read one of those you must include the key in $specialtemplates, init.php will then load the according rows from the table into $datastore
To get your stuff use $myarray = unserialize($datastore['mykey']);
To write your stuff call build_datastore('mykey', serialize($myarray)), this function is defined in functions_databuild.php.
That's it.
Natch
11-24-2004, 09:32 PM
Nice succinct answer, KirbyDE :D well done mate...
Andreas
11-24-2004, 09:35 PM
Thanks. I wanted to keep bandwidth usage low ^.^
Reeve of shinra
11-25-2004, 05:06 AM
If it still calls from the DB, what are the real advantages of it and what would be a good example of where to use / not use it? =p
Andreas
11-25-2004, 11:16 AM
Well the advantage is that you don't need an additional query, as init.php will load all required rows with just 1 query.
So it is easy to store custom data without having to modify existing queries or introduce new ones.
I'd suse this for data that needs to be read often/all the time, but is only being updated seldom (as you can see, datastore holds things like user record, smilies, bbcode, etc).
Thanks. What confused me is that I started by looking at the raw data. While it doesn't quite look encrypted, it has a:n or s:n but other times it just has numbers. I don't quite get what those a: or s: stand for?
Natch
11-25-2004, 08:29 PM
a = array
s = string
and the numbers indicate how many characters are included to reconstruct the object ...
To get your stuff use $myarray = unserialize($datastore['mykey']);
To write your stuff call build_datastore('mykey', serialize($myarray))How would you store just a string instead of a whole array?
Then how would you call it back?
I tried
$testvar="ted";
build_datastore('mytest', $testvar);
Which successfully put "ted" into "mytest" in the datastore table. However to get it back I tried
$anothertestvar=$datastore[mytest];
as well as
$anothertestvar=$datastore[testvar];
and it didn't work.
After putting 'mytest' in specialtemplates before calling global.php,
$datastore['mytest'] worked.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.