My class code Users
<?php
class Usuarios {
function listar() {
require_once 'controller/conexao.php';
$sql = "SELECT * FROM usuarios";
$usuarios = $mysqli->query($sql);
while ($linhas = $usuarios->fetch_array()) {
echo '<p>'.$linhas['id'].'</p>';
}
}
function adicionar() {
require_once 'controller/conexao.php';
}
}
?>
My model code
<?php
require_once('model/Usuarios.class.php');
$user = new Usuarios();
$user->listar();
//$user->adicionar();
?>
My connection
<?php
define('SITE_URL', 'http://localhost/sistemas/objetos');
$host = 'localhost';
$user = 'root';
$pass = '1';
$db = 'wellisson';
$mysqli = new mysqli($host, $user, $pass, $db);
$mysqli->set_charset('utf8');
if ($mysqli->connect_error):
echo "Erro na conexao: " . $mysqli->connect_errno . $mysqli->connect_error;
endif;
?>