Gracias funciona, la ultima pregunta.
Ahora mismo tengo el codigo de esta forma, pero si quito las variables en private funciona correctamente no? Mi pregunta es la siguiente, la pongo más abajo.
Código PHP:
private $server;
private $user;
private $password;
private $db;
public function __construct()
{
$this->server = "localhost";
$this->user = "root";
$this->password = "";
$this->db = "database";
}
Si modifico el codigo y lo pongo de esta forma, aparecen un monton de warning y notice y no entiendo el porque. Yo diria que de esta forma esta bien.
Código PHP:
private $server = "localhost";
private $user = "root";
private $password = "";
private $db = "database";
public function __construct( $server, $user, $password, $db )
{
$this->server = $server;
$this->user = $user;
$this->password = $password;
$this->db = $db;
}
Cita: Warning: Missing argument 1 for Connection::__construct(), called in C:\xampp\htdocs\2015\class\Connection.php on line 29 and defined in C:\xampp\htdocs\2015\class\Connection.php on line 9
Warning: Missing argument 2 for Connection::__construct(), called in C:\xampp\htdocs\2015\class\Connection.php on line 29 and defined in C:\xampp\htdocs\2015\class\Connection.php on line 9
Warning: Missing argument 3 for Connection::__construct(), called in C:\xampp\htdocs\2015\class\Connection.php on line 29 and defined in C:\xampp\htdocs\2015\class\Connection.php on line 9
Warning: Missing argument 4 for Connection::__construct(), called in C:\xampp\htdocs\2015\class\Connection.php on line 29 and defined in C:\xampp\htdocs\2015\class\Connection.php on line 9
Notice: Undefined variable: server in C:\xampp\htdocs\2015\class\Connection.php on line 11
Notice: Undefined variable: user in C:\xampp\htdocs\2015\class\Connection.php on line 12
Notice: Undefined variable: password in C:\xampp\htdocs\2015\class\Connection.php on line 13
Notice: Undefined variable: db in C:\xampp\htdocs\2015\class\Connection.php on line 14