Io dico...
Un metodo della classe x la connessione al db è cosi..
Codice PHP:
function query($sql = '') {
if (empty($sql)) {
return false;
}
$this->errornum = 0;
$this->errormsg = '';
$array = array();
$this->cursor = mysql_query(database::getescaped($sql), $this->resource);
if (!$this->cursor) {
$this->errornum = mysql_errno($this->resource);
$this->errormsg = mysql_error($this->resource);
return false;
}
$this->number = mysql_num_rows($this->cursor);
while($row = mysql_fetch_assoc($this->cursor)) {
$array[] = $row;
}
mysql_free_result($this->cursor);
return $array;
}
Su in un'altra classe devo utilizzare questo metodo.. le due classi non hanno niente a che vedere tra loro..
Istanzio un nuovo oggetto database... $this->db = new database; (all'interno della classe)
Se adesso io voglio utilizzare il metodo sopracitato x esempio x trovare i record all'interno di una tabella faccio cosi..
Codice PHP:
function tabella_elementi() {
$this->elementi = $this->db->query('SELECT * FROM tabella');
print_r($this->elementi);
}
Il print_r dovrebbe darmi l'array con i campi della tabella.. o sbaglio??? in vece mi dà solo Array ([0] => ) xke????
Se non riuscite a capire posto qualcosa in piu ma il problem è qui.. Grazie in anticipo a chi risponde..