You can specify the fields that you want to receive from the query by simply specifying them in the field
parameter of the openIndex method.
As you can read here, this code:
<?php
$hs->openIndex(1, 'db', 'table', 'PRIMARY', 'k,v');
$ret = $hs->executeSingle(1, '>=', array('K1'));
var_dump($ret);
?>
Is equivalent to the following SQL statement:
SELECT k,v FROM table WHERE k >= 'K1' LIMIT 1
Back to your example, if you want to read only the sent_date
field value:
$hs = new HandlerSocket($host, $port);
if (!$hs->openIndex(1, $dbname, $table, myHandlerSocket::PRIMARY, 'sent_date')) {
die($hs->getError());
}
$user_id = pack('H*', substr(md5('ruslan'), 0, 24));
$story_id = pack('H*', substr(md5('story1'), 0, 24));
$retval = $hs->executeSingle(1, '=', array($user_id, $story_id), 1, 0);
die("<pre>".print_r($retval,true)."</pre>");
The resulting output should be something like this:
Array
(
[0] => 0
[1] => 1
[2] => 2013-02-01 22:18:39
)
The HandlerSocket protocol documentation states:
Once an 'open_index' request is issued, the HandlerSocket plugin opens the specified index and keep it open until the client connection is closed. Each open index is identified by <indexid>. If <indexid> is already open, the old open index is closed. You can open the same combination of <dbname> <tablename> <indexname> multple times, possibly with different <columns>. For efficiency, keep <indexid> small as far as possible.