Codice PHP:
<?php
class db_select
{
private $host= '';
private $user= '';
private $pass= '';
private $db= '';
public function __construct($host, $user, $pass, $db) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->db = $db;
$this->connect();
}
private function connect(){
$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->db);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
public function select($sql)
{
$this->sql = $sql;
if($this->result = $this->conn->query($this->sql, MYSQLI_USE_RESULT)){
while($this->row = $this->result->fetch_row()) {
print $this->row[0]."
\r\n";
}
$this->result->close();
}
}
}
La query è sbagliata non può mettere
un nome tabella con degli spazi.
Con l'if prima del while eviti gli errori.
se sei su php5 ti conviene usare la visibilità
delle proprietà/metodi.