$Db->GetRows(TBSSQL_OBJECT,$sql)

30 views
Skip to first unread message

TomH

unread,
Sep 7, 2010, 10:17:39 AM9/7/10
to TinyButStrong Next Version
Hi Skrol29,

When I use $Db->GetRows(TBSSQL_OBJECT,$sql) with caching $Db-
>CacheTimeout = TBSSQL_1HOUR; -- the saved cache file result is saved
as an array of arrays.

Like this...

$CacheSql='SELECT *, CONCAT_WS(\' \',fname,lname) AS name FROM
mycontacts ORDER BY lname'; $Data=array (
0 =>
array (
'id' => '48',
'category' => 'Politician',
'lettername' => 'A',
'fname' => 'Joe',
'lname' => 'Archam',
'email' => 'J...@fribble.com',
),
1 =>
array (
'id' => '46',
'category' => 'Alien',
'lettername' => 'C',
'fname' => 'Duane',
'lname' => 'Cool',
'email' => 'du...@doobie.com',
),
...etc...

However... if I test the $result=GetRows(TBSSQL_OBJECT,$sql) with

$get_type = gettype($result[0]);
$check_for_object = print_r($result[0],true);

both these tests do indicate that the returned row (from cache) is an
object !!!

This implies that when operating with the row type set as
TBSSQL_OBJECT, that the cached result set is translated into array of
arrays before writing to cache file and then when reading the cache
file the arrays are translated back to objects.

Am I understanding this at all?

Thanks for TBS every day,
TomH





Skrol29

unread,
Sep 7, 2010, 4:30:38 PM9/7/10
to tbs-...@googlegroups.com
Hi TomH,

You're all right.

ezSQL works with data as objects in backstage, and convert them into
arrays if needed. I've not followed ezSQL because my benches were clear:
data as arrays is faster than data as objects. TbsSQL works in backstage
only with data as arrays (extracting data, save in cache, ...) and
convert them into objects when you choose the option. Don't worry, this
is very fast. I bet it's even faster than ezSQL. That's also why TbsSQL
returns arrays by default.

---------------------
Skrol29
www.tinybutstrong.com
---------------------


Le 07/09/2010 16:17, TomH a �crit :

TomH

unread,
Sep 7, 2010, 5:41:45 PM9/7/10
to tbs-...@googlegroups.com
Thanks for the concise explanation.

I just noticed by chance that the saved cache file was array of arrays.

No criticism of TbsSQL (or TBS) was intended, my apologies.

I am in the process of converting all of my ezSQL to TbsSQL - and trying to find
ways to make the migration as painless as possible - so let me ask a question
about it that will illustrate my complete ignorance of PHP OOP.

As an example, ezSQL uses the $Db->get_results while TbsSQL uses $db->GetRows
to get multiple row result set from the database.

The vast majority of my legacy code is like this:
$result=$Db->get_results($sql);

Is there a way for me to create a class extension that makes TbsSQL accept the
syntax $Db->get_results as if it were equivalent to $db->GetRows ???

Thanks for your endless patience with the unwashed!

Thanks for TBS every day,
TomH

Skrol29 wrote:
> Hi TomH, as equivalent to

Skrol29

unread,
Sep 8, 2010, 3:47:40 AM9/8/10
to tbs-...@googlegroups.com
Hello,

> Is there a way for me to create a class extension that makes TbsSQL accept
> the syntax $Db->get_results as if it were equivalent to $db->GetRows ???

Something like this ?

class ezSQL_mysql extends clsTbsSQL {
function get_results($query, $output = 'OBJECT') {
if ($output==='OBJECT') {
return $this->GetRows(TBSSQL_OBJECT,$ query);
} else {
return $this->GetRows($ query);
}
}
}


Regards,
Skrol29

-----Message d'origine-----
De : tbs-...@googlegroups.com [mailto:tbs-...@googlegroups.com] De la part
de TomH
Envoyé : mardi 7 septembre 2010 23:42
À : tbs-...@googlegroups.com
Objet : Re: [tbs-next] $Db->GetRows(TBSSQL_OBJECT,$sql)

--
You received this message because you are subscribed to "TinyButStrong next
version".
Post to this group: send email to tbs-...@googlegroups.com
Subscribe: send email to tbs-next+...@googlegroups.com
Unsubscribe: send email to tbs-next+u...@googlegroups.com
More options: http://groups.google.com/group/tbs-next

TomH

unread,
Sep 8, 2010, 5:19:07 PM9/8/10
to TinyButStrong Next Version
Skrol29,

You have so generously contributed to the single greatest improvement
in my PHP/TBS/TbsSQL platform - my deepest thanks.

It may seem trivial to you, but to us old timers (69 ans) who have
been passed by in the evolution to the world of OOP/classes, etc., the
"extends" feature is indeed a miraculous tool.

Not only did your little 'something' work instantly for migrating
legacy ezSQL code -- but with a little fiddling I was able to also
'extend' functions for customizing the CONSOLE look. feel, and
operation as well.

It gives so much freedom in customizing - and no more hacking to the
master class source (which always gets me in trouble, eventually).

My deepest thanks - I trust you will give me the honor to accept an
invitation to dinner when I am in France.

Thanks fore TBS every day,
TomH

Skrol29

unread,
Sep 9, 2010, 3:43:30 AM9/9/10
to tbs-...@googlegroups.com
> My deepest thanks - I trust you will give me the honor to accept an
invitation to dinner when I am in France.

Of courses, it would be a pleasure to meet you a take a time in Paris :)

Regards,
Skrol29

-----Message d'origine-----
De : tbs-...@googlegroups.com [mailto:tbs-...@googlegroups.com] De la part
de TomH

Envoyé : mercredi 8 septembre 2010 23:19
À : TinyButStrong Next Version
Objet : [tbs-next] Re: $Db->GetRows(TBSSQL_OBJECT,$sql)

Skrol29,

--

Reply all
Reply to author
Forward
0 new messages