Home > Backend Development > PHP Tutorial > pdo连接oracle读取数据,多条返回值中的Resource id怎样获取?

pdo连接oracle读取数据,多条返回值中的Resource id怎样获取?

WBOY
Release: 2016-06-06 20:32:10
Original
1246 people have browsed it

用pdo连接oracle数据库后,获取多条文章数据,返回值中包含Resource id,这些内容要怎样获取呢?

<code>$data_f = $ocl->query($sql);
print_r($data = $data_f->fetchAll(PDO::FETCH_ASSOC));
</code>
Copy after login
Copy after login

尝试这样,但获取到的都是最后一条数据的内容

<code>foreach($data as $v){
    echo stream_get_contents($v['CONTENT']);
}
</code>
Copy after login
Copy after login

而用不用fetchAll改用fetch,获取的条数倒有问题,例如sql语句中取10条,才输出3条

<code>while($v = $data_f->fetch(PDO::FETCH_ASSOC)){
    echo stream_get_contents($v['CONTENT']);
}
</code>
Copy after login
Copy after login

回复内容:

用pdo连接oracle数据库后,获取多条文章数据,返回值中包含Resource id,这些内容要怎样获取呢?

<code>$data_f = $ocl->query($sql);
print_r($data = $data_f->fetchAll(PDO::FETCH_ASSOC));
</code>
Copy after login
Copy after login

尝试这样,但获取到的都是最后一条数据的内容

<code>foreach($data as $v){
    echo stream_get_contents($v['CONTENT']);
}
</code>
Copy after login
Copy after login

而用不用fetchAll改用fetch,获取的条数倒有问题,例如sql语句中取10条,才输出3条

<code>while($v = $data_f->fetch(PDO::FETCH_ASSOC)){
    echo stream_get_contents($v['CONTENT']);
}
</code>
Copy after login
Copy after login

  1. 获取到的都是最后一条数据的内容, 这是一个已知的bug,在php上面有过讨论,无解

  2. fetch那里,是否是因为fetch只返回了一个字段 ? 我用循环fetch的时候,还算是正常的

我目前代码是:
`

<code>    while($row=$pStmt->fetch(PDO::FETCH_ASSOC)){
                $clobFields=$this->detectClob($row);
                if(count($clobFields)>0){
                    $this->retriveClobRow($row,$clobFields);
                }
                $rst[]=$row;
            }
            
    protected function retriveClobRow(&$row,$clobFields){
        if(count($clobFields)>0){
            foreach($clobFields as $colName){
                $row[$colName] =stream_get_contents($row[$colName]);
            }
        }
    }
            `</code>
Copy after login

总而言之, oracle pdo,就是个小玩具,即使这问题解决了,还有调用 存储过程时输出参数的问题绕不开。尽量避免使用 oracle pdo。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template