Since the rewrite of rollator into a full-fledged OOP structure, I’ve been asking myself, as well as been queried a few times by curious parties: “How will it work?”
I’ve tried to make it as painless as possible. If you note my prior post, you’ll see that all DB specific queries have been made abstract, so you need not know what the DB is. You are, however, required to format proper SQL queries. ;)
Here’s how it might look:
$myDB =& new rollatorDB(”$myHost”, ”$myUser”, ”$myPass”, ”$myName”, ”$mydbType”);
$array = $myDB->fetchAssoc(‘SELECT id, content FROM mycontentdb LIMIT 1’);
echo “fetchAssoc ”;
print_r($array);
$rowArray = $myDB->fetchAssocRow(‘SELECT urltitle, fullurl FROM urldb LIMIT 1’);
echo “fetchAssocRow ”;
print_r($rowArray);
$myDB->dbClose();
?>
It’s pretty simple, no? Sure, it can use a bit of further abstraction, but for the most part, the logic’s entirely written. It works with single array and row queries, raw queries, and as demonstrated above, it will fetch all associative fields, either in an array, or in the fairy common ‘row’ format.
The difference lies in that arrays return the type searched for with the name, and the row merely returns the data. For our test sample, let us assume the following is returned:
fetchAssoc Array
(
[0] => Array
(
[id] => 1
[content] => Hey this is my content. Is it not great? I think it is so! Please, send me much money so I might make such wonderful content for you!
)
)
fetchAssocRow Array
(
[0] => Array
(
[0] => Sweet Cuppin Cakes
[1] => http://www.homestarrunner.com/main18.html
)
)
You’ll find that the array query returns the variable name as the identifier of the data, whereas the row merely returns the data.
Personally, I like the ability to discern the data type more with the array, but if one is entirely sure that they will continue to use the same exact format and return their data, er, proper, the row lookup does have a trivial amount of speed increase.
Of course, to fully see what rollatorDB supports, you might just want to see the source.