如何获取数据?

时间:2013-08-13 16:39:28

标签: php mysql

此声明提供错误

  

无法从数据库中获取结果

$res =$dbcon->exec("select *from tablename ");
$res->fetch();

发出错误。

2 个答案:

答案 0 :(得分:2)

您的查询中需要一个空格:

$res = $dbcon->exec("select * from tablename");

根据$dbcon的不同,您可能需要使用查询方法(alok.kumar的答案的一部分):

$res = $dbcon->query("select * from tablename");

参考:http://www.php.net/manual/en/pdo.query.php

答案 1 :(得分:2)

只更改一个查询

          $res =$dbcon->exec("select *from tablename "); 
               to
                  $res =$dbcon->query("select *from tablename ");