Why is this code causing an SQL error? I wrote code to select records from the database, but it is causing the following error:


  PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error 
      in your SQL syntax; check the manual that corresponds to your MySQL server version for the 
      right syntax to use near 'FROM pricepackages pricepackages' at line 1: SELECT FROM 
      {pricepackages} pricepackages; Array ( ) in view_packages() (line 25 of D:\xampp\htdocs
      \talyllyn\sites\all\modules\pricepackages\pricepackages.module).


What is wrong with the code I am using?

function view_packages() {
    $list = '&lt;table&gt;';
    $query = db_select('pricepackages')-&gt;execute();
    $i = 0;

    while ($record = $query-&gt;fetchAssoc()) {
        $list .= '&lt;tr&gt;&lt;td&gt;';
        $list .= $record['packageName']."&lt;/td&gt;";
        $list .= '&lt;td&gt;'.$record['packageDescp']."&lt;/td&gt;";
        $list .= '&lt;td&gt;'.$record['pPrice']."&lt;/td&gt;";
        $list .= '&lt;/tr&gt;';
        $i++;
    }

    $list .= '&lt;/table&gt;';
    return $list;
}
This is your current query as it's executed:

SELECT 
FROM 
{pricepackages} pricepackages


Which is obviously wrong; an SQL SELECT query needs one or more fields. To SELECT *:

$query = db_select('pricepackages')-&gt;fields('pricepackages')-&gt;execute();     


Or specific fields:

$fields = array('foo', 'bar');
$query = db_select('pricepackages')-&gt;fields('pricepackages', $fields)-&gt;execute();