This is a function I have inside a class. $db is a mysqli object injected in at creation. I cannot get this to return any data. and cannot see where I have gone wrong. I have tried removing the if statement in case the problem was there.
function getStat($statName) {
/**
* Gets latest value assigned to the statName for the given charID
*/
$sql = "select statValue from charStat where charID =".$this->charID." and statName =".$statName." order by timerstamp DESC limit 1";
$result = $this->db->query($sql);
if ($this->db->affected_rows == '1'){
$row = $result->fetch_row();
return $row[0];
} else {
return "error";
}
I would try to change:
To this to display the error:
This should return the last MySQL error message, unless the connection to the database is closed in the db->query call.
That is…if it’s returning “error”. If not, then $row[0] is empty. You’d need to show the code from the $db class to figure out more information.