The code below returns nothing, but if I remove this line:
'desc' => $row['DESC'],
from the function it works fine.
DESC Is a valid column in the database and when I run the full query in phpmyadmin, it returns the desired result.
I am not sure why this line
'desc' => $row['DESC'],
breaks the return of the result.
=======
After more investigating I can see the JSON output has the same issue. Altering the column name (since DESC is a keyword) and reflecting the changes in the query has no effect.
========
function get_all_subjects($db1) {
$stmt = $db1->query("SELECT DISTINCT NAME, DESC, CLASSCODE FROM tbl_subjects WHERE VISIBLE = 1 ORDER BY NAME ASC");
$stmt->execute();
$count = $stmt->rowCount();
$column = array();
if ($count >0)
{
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$column[] = array(
'name' => $row['NAME'],
'desc' => $row['DESC'],
'cc' => $row['CLASSCODE']
);
}
return json_encode(array('subjects' =>$column));
}
else
{
return $count;
}
}
descis reserved keyword of sql language, use quotesDESCis a reserved word of MySQL