[討論] 碰到了個滿奇特的問題(結果是PDO的bug)
class web{
public $dbh;
function __construct(){
$this->dbh = new pdo(...)
}
$sql = " SELECT.... ";
$sth = $this->dbh->prepare($sql);
$sth->execute();
$res = $sth->fetch(PDO::FETCH_OBJ)
// 這一次OK
$sql = " SELEC... ";
$sth = $this->dbh->prepare($sql);
$sth->execute();
$res = $sth->fetchAll(PDO::FETCH_OBJ)
這裡下第二次Query時
這裡在測試主機 PHP 5.2.9 是OK的
可是在正式主機 PHP 5.1.6 就會錯誤了 $this->dbh是bool(false)
}
不過我把$dbh丟到class 外面去連續執行兩次
$dbh = new pdo(..)
...
$sth = $dbh->prepare($sql); OK
$sth->execute();
$res = $sth->fetch(PDO::FETCH_OBJ)
$sth = $dbh->prepare($sql); OK
$sth->execute();
$res = $sth->fetch(PDO::FETCH_OBJ)
感覺起來是兩個版本對class上的差異 @.@
==============找到問題了=============
就跟bug一樣的神奇,很多次只要把問題丟到ptt上後,
就會很快的找到問題的解答 XDDDD
最後發現這是一個PDO的 Bug
剛剛發現的文章
http://www.joehorn.idv.tw/archives/2010/05/27/814
剛剛文章的問題並不是因為物件的關係,是因為上面提到
在PDO交差使用不同模式的fetch或query造成的bug
$db->query();
$db->prepare();
or
$sth->fetchAll();
$sth->fetch();
所以我只要從$sth取得值後unset($sth)就解決了。
而看來PHP5.2的PDO也解決了這個bug
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.105.241.201
※ 編輯: JYHuang 來自: 112.105.241.201 (09/07 13:47)
※ 編輯: JYHuang 來自: 112.105.241.201 (09/07 14:01)
推
09/07 14:03, , 1F
09/07 14:03, 1F
推
09/07 14:14, , 2F
09/07 14:14, 2F
→
09/07 14:37, , 3F
09/07 14:37, 3F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章