Hey guys i am new to OOP and i am wanting to run two functions both requiring the same connection. I am struggling to declare the $mysqli variable in a way which will allow it to be used by both functions. I would rather just use the one as i will be adding many many more functions later. Any help greatly appreciated.
the error message i am receiving is;
Notice: Undefined variable: mysqli in C:\Users\PC\Documents\XAMPP\htdocs\test.php on line 13
<?php
class OOP
{
function __construct(){
$mysqli = new mysqli('localhost', 'c3337015', 'c3337015', 'iitb');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
function getMember(){
$stmt = $mysqli->prepare("SELECT First_Name FROM forum members");
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($First_Name);
while ($row = $stmt->fetch()) {
echo $First_Name;
}
}
function getForum(){
$stmt = $mysqli->prepare("SELECT ForumTitle FROM forum");
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($ForumTitle);
while ($row = $stmt->fetch()) {
echo $ForumTitle;
}
}
}