Intente hacer una mezcla de los dos y me sale lo siguiente.
Cita: Fatal error: Call to undefined function connect() in C:\xampp\htdocs\2015\class\Connection.php on line 31
Tendría que imprimir algun echo del if o del else no?
Código PHP:
<?php
class Connection
{
private $server;
private $user;
private $password;
private $db;
public function __construct()
{
$this->server = "localhost";
$this->user = "root";
$this->password = "";
$this->db = "database";
}
public function connect()
{
$connect = new mysqli( $this->server, $this->user, $this->password, $this->db );
if($connect->connect_errno){
die('No se pudo conectar a la BBDD');
}else{
echo 'Conexión realizada';
}
return $connect;
}
}
$conexion = new Connection();
$conexion = connect();
Gracias