Procedural PHP works for me, but when I try to code like I do in objective C I cannot seem to get the functions to work. I think it has something to do with my variable scope and the functions not returning any values. Where am I going wrong with my code here?
<?php
require_once("constants.php");
class Main {
public $menu;
public $connection;
function connectToDatabase() {
//connect to database & check connection
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
}
function queryDatabase($select, $from) {
$result = mysqli_query($connection,"SELECT $select FROM $from");
}
function closeDatabaseConnection() {
mysqli_close($connection);
}
function displayMenu() {
//connect to database & check connection
connectToDatabase();
//get menu data
queryDatabase(*, pages);
//construct menu data
echo '<ul class="mainNavigation">';
while($row = mysqli_fetch_array($result))
{
echo '<li><a href="' . $row['filename'] . '.php">';
echo $row['menu_name'];
echo '</a></li>';
}
echo '</ul>';
//close connection
closeDatabaseConnection();
}
function displayFooter() {
}
function getUser() {
}
function userLogIn() {
}
}
?>