2014-01-28 35 views
0

也許我的問題是關於方法和變量的範圍,但我不明白,有人可以建議我如何以正確的方式做到這一點?

我有這個在我的包含文件User_query.php:

$stmt = $db->prepare("SELECT * FROM users WHERE user_id=:user_id"); 
$stmt->bindValue(':user_id', $user_id, PDO::PARAM_INT); 
$stmt->execute(); 
$row = $stmt->fetch(PDO::FETCH_ASSOC); 

我有這個在我的index.php文件:

include APP_PATH . 'User_query.php'; /* I have just an query here */ 
Pages::buildPage(); 

我的類方法:

class Pages { 

    public function buildPage() { 
    include APP_PATH . 'Headers.php'; /* I try to print $row['something'] in-here */ 
    include APP_PATH . 'Contents.php'; /* I think this will not work either... */ 
    include APP_PATH . 'Footers.php'; /* ... and I will get undefined indexes */ 
    print $row['something'] /* Even this do not work, no difference I think than the above */ 
    } 

} 

當我嘗試使用print $ row ['something']在頭文件中的數據庫查詢中打印某些內容時,我有「注意:Undefined v ariable:row「錯誤。我很困惑。 (我做了這樣的方式來學習的類和方法)

回答

0

沒有命名爲$row['something']這是給錯誤的原因,任何數組或變量..

+0

我在包括文件中有這樣的:$語句= $ db-> prepare(「SELECT * ........; $ row = $ stmt-> fetch(PDO :: FETCH_ASSOC); –

相關問題