Im trying to return a record from my table with the following class...
class User {
public function getCredits($uid)
{
$rs = mysql_query("select bank from `users` where id = '$uid'");
$row=@mysql_fetch_object($rs);
return $row->bank;
}
}
I output this data with the following...
<?php print $User->getCredits(); ?>
Im not given anything however, as though my code cannot be read and my broweser just display a white page?
@in your code. It's hiding any errors that might occur. My guess ismysql_fetch_objectis throwing an error and you're suppressing it.mysql_*functions. Instead go withmysqli_or PDO!mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. People who want this message: gist.github.com/MadaraUchiha/3881905var_dump()of$uid, the actual query string, or of$rowwould have revealed this problem immediately. The first thing you should always do when code is not behaving the way you expect it to is to debug. You should of course also have code to handle all possible edge cases (query failure, query returning 0 rows, etc.).