CLASE Link.php
Código PHP:
<?php
class Link{
private $conexion;
private $HOST;
private $USERNAME;
private $PASSWD;
private $DBNAME;
private $link;
private $consulta;
public function __construct()
{
$this->HOST = 'localhost';
$this->USERNAME = 'root';
$this->PASSWD = '';
$this->DBNAME = 'workshop';
}
public function conexion()
{
$this->link = @mysqli_connect($this->HOST, $this->USERNAME, $this->PASSWD, $this->DBNAME);
if(mysqli_connect_errno() != 0)
{
die("error de conexion a la base de datos. " . mysqli_connect_error());
}
}
public function consulta()
{
$this->consulta = "SELECT * FROM usuario limit 30";
return $this->consulta;
}
}
?>
Código PHP:
<?php
require_once 'Link.php';
$result = new Link();
$result->conexion();
$result->consulta();
while ($row = $result->fetch_object()) {
echo 'Nombre: '.$row->email.' '.$row->nombre.' <br />';
}
?>
Call to undefined method Link::fetch_object() in...