Ok, A couple of things here.
the php styled table doesn't return data like you may expect. It keeps data sorted by actually adding whatever you insert into the table into a sub-table, indexed by number. As you may or may not know, Lua will sort numerically indexed tables by the order in which they were added for you, but if you use keyed indexes (like a string) it actually sorts it by the hash value of the key. php:Table is an answer to this.
So, if you do phptable['me'] = "tsuujin", the metatable information on phptable diverts the information into a hidden subtable, in order to maintain organization. This is why you can't just display(phptable), because display looks at the raw table information without respecting the metatable data.
Here's a piece of code I just verified as working from my actual system:
lua for row,results in dba.query([[SELECT * FROM player_relations]]):pairs() do display(results) end
This calls display not on the base table, but on the results table for each entry in it. You can use this to see each and every result, it's kind of handy. The key to remember here is that when you call pairs() on a php:Table, you're going to get the numerical index as the first argument ("row") and a table containing that rows data ("results") that you can work with.
php:Table is actually public code that I've just modified in a small way, but one of those modifications is very important to another of your questions. I added a count() feature, which returns the number of rows in the table. So, if you wanted to quickly see how many results you returned, do:
local results = dba.query([[some query]])
display(results:count())
You could of course expand that into expanded error checking or data reporting.
On a side note: learn to use string.format. Your life will be much less complex once you realize how damned useful it is, and how much cleaner your code is to read.
Instead of:
results = dba.query([[select * from slain where name like "%]] .. matches[3]:trim() ..[[%" order by count desc]])
do
results = dba.query(string.format([[SELECT * FROM slain WHERE name LIKE "%%%s%%" ORDER BY count DESC]], matches[3]:trim()))
While I know the requirement of escaping percents with a double percent is kind of ugly, you won't always run into this, and it's still much easier to read than breaking the string down into parts and concatenating. Also helps because a lot of syntax highlighters get confused with the opening and closing quotations. Finally, string.format tends to be faster, and avoids a bug in Lua's core coding regarding bulk concatenation and the garbage collector.