【问题标题】:Query not assigned into the variable / Not going into the condition查询未分配到变量/未进入条件
【发布时间】:2016-03-11 15:28:34
【问题描述】:

我正在为我的项目编写此代码,但我似乎无法将查询的值放入 $currentRow。保存到变量 $currentrow 中的所有内容都是 22,这是数据库中的行数。我想访问所有查询结果。请帮忙。这是代码。

public function getBSIConfig(){
    $conn = oci_connect("472proj","system","//localhost/XE");
    $sql = oci_parse($conn,"SELECT conf_id, conf_key, conf_value FROM bsi_configure");
    oci_execute($sql);
    echo "0";
    while($currentRow = oci_fetch_all($sql,$res)){
        echo "1.5";
        echo $currentRow;
        if($currentRow["conf_key"]){
        echo "1";
            if($currentRow["conf_value"]){
                $this->config[trim($currentRow["conf_key"])] = trim($currentRow["conf_value"]);
                echo "2";
            }else{
                $this->config[trim($currentRow["conf_key"])] = false;
                echo "3";
            }
        }
    }
}

而且输出只有:
0
1.5
22

【问题讨论】:

  • 我从未使用过oci_fetch_all,但fetch_all 不会给你一个包含所有行的数组吗?所以我认为你会在分配数组后foreach ;例如没有while

标签: php arrays oracle loops if-statement


【解决方案1】:

阅读此http://php.net/manual/en/function.oci-fetch-all.php,您可能会知道出了什么问题。

【讨论】:

    【解决方案2】:

    此函数的结果存储在第二个参数中,而不是直接返回。看看这是否适合你:

    $results = array();
    $numResults = oci_fetch_all($sql, $results);
    foreach ($results as $result) {
        if ($result["conf_key"]) {
            // etc ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      相关资源
      最近更新 更多