gpt4 book ai didi

php - 使用 HandlerSockets 时,我可以指定要从查询中接收哪些字段吗?

转载 作者:行者123 更新时间:2023-11-29 04:24:36 24 4
gpt4 key购买 nike

我可以在使用 HandlerSockets 时指定我想从查询中接收哪些字段吗? ?

这是我的示例表

CREATE TABLE pushed_media
(
user_id BINARY(12) NOT NULL,
story_id BINARY(12) NOT NULL,
sent_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY ( user_id, story_id )
);

下面是查询它的php代码

$hs = new HandlerSocket($host, $port);
if (!($hs->openIndex(1, $dbname, $table, HandlerSocket::PRIMARY, 'user_id,story_id,sent_date')))
{
echo $hs->getError(), PHP_EOL;
die();
}

$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);

我只需要 sent_date 因为我已经知道另外两个值。是否可以不再通过网络传输它们?

最佳答案

您可以通过简单地在 openIndexfield 参数中指定您希望从查询中接收的字段来指定它们方法。
如您所见here ,这段代码:

<?php
$hs->openIndex(1, 'db', 'table', 'PRIMARY', 'k,v');
$ret = $hs->executeSingle(1, '>=', array('K1'));
var_dump($ret);
?>

相当于下面的SQL语句:

SELECT k,v FROM table WHERE k >= 'K1' LIMIT 1

回到您的示例,如果您只想读取 sent_date 字段值:

$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>");

结果输出应该是这样的:

Array
(
[0] => 0
[1] => 1
[2] => 2013-02-01 22:18:39
)

HandlerSocket protocol documentation状态:

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.

关于php - 使用 HandlerSockets 时,我可以指定要从查询中接收哪些字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14497726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com