从数据库值填充数组的最有效方法?
如果我想获取某个品牌的product_ids 列表。我会这样做:
$id_list = array();
$qry = 'SELECT product_id FROM products WHERE product_brand = :brand';
$STH = $this->pdo->prepare($qry);
$STH->execute(array("brand" => $brand));
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch())
{
$id_list[] = $row['product_id'];
}
有没有更快更有效的方法?似乎如果我只选择一列,应该有更好的方法来选择/插入到数组中。
If I wanted to get a list of product_ids with a certain brand. I would do this:
$id_list = array();
$qry = 'SELECT product_id FROM products WHERE product_brand = :brand';
$STH = $this->pdo->prepare($qry);
$STH->execute(array("brand" => $brand));
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch())
{
$id_list[] = $row['product_id'];
}
Is there a faster more efficient way? It seems like if I am only selecting 1 column there should be a better approach to selecting/inserting that into an array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
真的更快吗?本地基准:
..所以,至少这个脚本差异在我的服务器上更快......
Is it really faster? Local benchmarK:
.. so, at least this script difference, on my server, is faster...