dongxi2163
2017-11-01 06:58
浏览 51
已采纳

Prestashop 1.6.1.14 - 数据库查询在Execute上返回1

I am currently using the code below in Prestashop to retrieve a cart id.

    public function hookDisplayPDFInvoice($params) {

    $order_invoice = $params['object'];
    $id_order = (int)$order_invoice->id_order;

    $sql = 'SELECT id_cart FROM '._DB_PREFIX_.'orders WHERE id_order="'.$id_order.'"';
    //example id_cart
    $id_cart = Db::getInstance()->execute($sql);
    return $id_cart;

In database, there are id_cart and id_timeslot. Table is called ps_cart_timeslot.

I am quite stuck as I am baffled as to why the data return is 1 for any data I am retrieving.

$id_order is fine, it is returning the right value. Any data select I am querying will return 1.

Am I missing anything? Pardon me if this is a silly mistake.

Thank you.

图片转代码服务由CSDN问答提供 功能建议

我目前正在Prestashop中使用以下代码来检索购物车ID。 < pre> public function hookDisplayPDFInvoice($ params){ $ order_invoice = $ params ['object']; $ id_order =(int)$ order_invoice-&gt; id_order; $ sql = 'SELECT id_cart FROM'._DB_PREFIX _。'命令WHERE id_order =“'。$ id_order。'”'; //示例id_cart $ id_cart = Db :: getInstance() - &gt;执行($ sql); \ n返回$ id_cart;

在数据库中,有id_cart和id_timeslot。 表名为ps_cart_timeslot。

我很困惑,因为我感到困惑的是为什么我检索的数据的数据返回为1。

$ id_order很好,它返回正确的值。 我查询的任何数据选择都将返回1.

我错过了什么吗? 如果这是一个愚蠢的错误,请原谅我。

谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmie3526 2017-11-01 09:12
    已采纳

    For selects use Db::getInstance()->executeS($sql); or to get single value use Db::getInstance()->getValue($sql);

    However since PS 1.6 you should be using query builder.

    $query = new DbQuery();
    $query->select('id_cart')
          ->from('orders')
          ->where('id_order = ' . (int)$id_order);
    Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
    // Or array of values
    Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
    

    execute() method returns only true or false while executeS() will return an array of select results (method can only be used for select queries) and getValue() will return the first value found in result.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题