Salve ragazze, sto cercando di imparare a programmare OOP in php, per ora è andato tutto a buon fine, fino alla connessione del db, ho creato un phpadmin un database chiamato corso, una tabella e poi ho fatto due pagina php, una contenente le classi e un altro una select, ma nonostante i dati del db siano esatti mi dice:
codice:
No database selectedNo database selected
Il tutto avviene in localhost, il file delle classi è questo_
codice:
Prova (contiene le classi
<?php
codice:
class database {
private $hostname;
private $username;
private $password;
private $database;
private $connection;
private $query;
private $where;
private $order;
private $result = array();
var $lastQuery;
# the constructor initializes the mysql connection
public function mysql() {
$this->hostname = 'localhost';
$this->username = 'root';
$this->password = '';
$this->database = 'corso';
$connection = mysql_connect($this->hostname, $this->username, $this->password);
mysql_select_db($this->database, $connection) or die(mysql_error());
return true;
}
# selects the data from the table
public function select($query, $where, $order) {
$this->query = $query;
$this->where = ($where == NULL) ? NULL : $where;
$this->order = ($order == NULL) ? NULL : $order;
$fullQuery = $this->query . $this->where . $this->order;
$this->lastQuery = $fullQuery;
$this->result = mysql_query($fullQuery);
if ($this->result()) { return true; }
return false;
}
# used to validate result from select()
private function result() {
if ($this->result) { return true; }
echo mysql_error();
return false;
}
# displays the data from the select() member
public function display() {
if ($this->select($this->query, $this->where, $this->order)) {
echo '<h3>' . $this->lastQuery . '</h3><br />';
while ($row = mysql_fetch_array($this->result, MYSQL_ASSOC)) {
echo '<b>' . $row['id'] . ' </b>' . $row['file_name'] . '<br />';
}
return true;
}
return false;
}
}
?>
Secondo file
Codice PHP:
<?phpinclude 'prova.php';
$photos = new database();
$query = "SELECT * FROM page_text";$where = NULL;$order = NULL;
$photos->select($query, $where, $order);$photos->display();?>
ma non si connette ad database in localhost
Ringrazio chiunque mi può aiutare in anticipo