1
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 code of model
<?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;
?>
@13dev I am starting!
– wribeiro
have you checked the file
controller/conexao.php
exists ? and is in the same directory that you indicated ?– 13dev
is yes! if I use the code of the Usuarios class directly in my index.php , it runs smoothly
– wribeiro