2013-02-10 53 views
-1

我想列出表中两个特定列的数据。每当我去到文件,它都会返回一个服务器错误。当我删除while循环时,它执行完美,所以我不知道我在做什么错误。PDO声明不提取数据

这里的错误:

Server error The website encountered an error while retrieving http://dayzlistings.com/reg-whitelist.php . It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

try { 
    $dbh = new PDO('mysql:host=localhost;dbname=dbname','dbuser','dbpass'); 
      $sql = "SELECT * from wp_cimy_uef_data"; 
      $q = $dbh->prepar($sql); 
      $q->execute(); 
       while($row = $q->fetchall() { 
        echo $row['USER_ID']; 
        echo $row['VALUE']; 
       } 
    } 
$dbh = null; 
} catch (PDOException $e) { 
    print "Error from Dedicated Database!: " . $e->getMessage() . "<br/>"; 
    die(); 
} 
+0

什么是错误 – Nate 2013-02-10 01:40:08

+0

服务器错误 该网站在检索http://dayzlistings.com/reg-whitelist.php时遇到错误。它可能因维护而关闭或配置不正确。 以下是一些建议: 稍后重新加载此网页。 HTTP错误500(内部服务器错误):服务器试图完成请求时遇到意外情况。 – Ryahn 2013-02-10 01:40:40

+0

您在'$ q = $ dbh-> prepar($ sql);'行有错字。应该'准备'而不是'prepar' – peterm 2013-02-10 01:52:50

回答

0

500意味着什么错了,当你与服务器,例如互动访问数据库。 和$row['USER_ID']将永远不会工作,而应该使用$row[0]['USER_ID']

0

不整台fetchAll()回报作为数组..

你不需要while循环$行..只是做? $row = $q->fetchAll()没有while和print_r整个阵列,看看你得到什么..

如果你仍然想做,而我认为你可以使用

while($row = $q->fetch()){ 
// rest of the code here 
} 

而且你不能把annything尝试捕捉之间..

try{ 
//code 
} 
$dbh = null; //**This is not allowed by the way...** 
catch(PDOException $e){ 
    //code 

}

DINS

+0

它仍然抛出相同的错误。我有另一个连接到同一个数据库的文件,它工作正常。 – Ryahn 2013-02-10 01:48:43

+0

我更新了评论..我不确定这将解决你的问题..你将需要检查你的Apache日志500错误..但只是为了让你知道,没有人可以进来尝试和赶上... – Dinesh 2013-02-10 02:10:24