I'm currently doing a populating/editing my DB using PHP on a webpage I'm going to build. I'm relatively new to PHP so please excuse my "greenhorn" knowledge. My DB connection works, however, I don't understand why my function "displaySQL" and then counting the quantity as an array is not generating anything on my webpage. There's no number displayed on the screen, I was going to have that value put inside an HTML table afterwards. My DB settings are also established for the parameter part (host, username, password). Thanks for any help.
class User{
var $conn;
function __construct($hostname,$username,$password){
try{
$conn = new PDO("mysql:host=$hostname;dbname=pjj5",
$username, $password);
echo "Connected successfully <br>";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
}
//display all users information
function displaySQL(){
$sql = "SELECT * FROM accounts";
$q = $conn->prepare($sql);
$q->execute();
$results = $q->fetchAll();
return $results;
}
$db = new User($hostname,$username,$password);
$res = $db->displaySQL();
echo count($res);