douzhanyan5015 2013-05-13 07:00
浏览 46

具有多个参数的mysqli get_result替代方案

SELECT * FROM `ware_house_indents` WHERE `has_cancel` = ? AND `eid`= ? 

i need to get result above query in mysqli. but i cant use get_result() function because it is not working in server.i have found this below function and it is working fine.but that function not possible to pass multiple parameters.please help me to solve this problem.

function db_bind_array($stmt, &$row)
{
    $md = $stmt->result_metadata();
    $params = array();
    while($field = $md->fetch_field()) {
        $params[] = &$row[$field->name];
    }
    return call_user_func_array(array($stmt, 'bind_result'), $params);
}
function db_query($db, $query, $types, $params)
{
    $stmt = $db->prepare($query);
    $bindRet = call_user_func_array(array($stmt,'bind_param'),
                                    array_merge(array($types), $params));
    $stmt->execute();
    $result = array();
    if (db_bind_array($stmt, $result) !== FALSE) {
        return array($stmt, $result);
    }
    $stmt->close();
    return FALSE;
}
if (($qryRes = db_query($mysqli, $sql, 'i', array(&$var))) !== FALSE) {
    $stmt = $qryRes[0];
    $row = $qryRes[1];
    while ($stmt->fetch()) {
        print_r($row);
    }
    $stmt->close();
}
  • 写回答

1条回答 默认 最新

  • donglu9978 2013-05-13 07:13
    关注

    Let me suggest you a quite indirect solution.
    You'd do yourself a huge favor if start using PDO instead of mysqli

    It has no mysqli disadvantages when dealing with prepared statements as it has a way better implementation of above functions out of the box. So, it will let you to get your data in a few lines:

    $sql = "SELECT * FROM ware_house_indents WHERE has_cancel = ? AND eid= ?";
    $stm = $pdo->prepare($sql);
    $stm->execute(array($cancel,$eid));
    $data = $stm->fetchAll(); // or fetch() if you need only one row
    

    that's all

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)