Originariamente inviato da zacca94
Errore: Unable to select database. MySQL reported: No database selectedCodice PHP:class Database
{
var $config;
var $p_connect = false;
var $db;
var $num_query = 0;
function Database($config, $p_connect)
{
$this->config = $config;
$this->p_connect = $p_connect;
$this->num_query = 0;
$this->connect();
$this->select_db();
}
function connect()
{
if ($this->p_connect == true)
$this->db = mysql_pconnect($this->config['dbhost'], $this->config['dbuser'], $this->config['dbpass']);
else
$this->db = mysql_connect($this->config['dbhost'], $this->config['dbuser'], $this->config['dbpass']);
if (!$this->db)
die('Unable to connect to MySQL server. MySQL reported: '.mysql_error());
}
function select_db()
{
if(!mysql_select_db($this->config['dbname']))
die('Unable to select database. MySQL reported: '.mysql_error());
}
# .................
L'errore è piuttosto chiaro: non selezioni il database.
Tu richiami in sequenza i seguenti metodi nel costruttore della classe:
$this->connect();
$this->select_db();
ma in connect() fai subito un controllo per verificare se la connessione è o no andata a buon fine ed essendo a quel punto il database non ancora selezionato ovviamente ti riporta l'errore, quello che devi fare è eliminare dal costruttore il richiamo di questo metodo ( $this->select_db(); ) e inserirlo nel connect();
Tipo così:
Codice PHP:function Database($config, $p_connect)
{
$this->config = $config;
$this->p_connect = $p_connect;
$this->num_query = 0;
$this->connect();
}
function connect()
{
if ($this->p_connect == true)
$this->db = mysql_pconnect($this->config['dbhost'], $this->config['dbuser'], $this->config['dbpass']);
else
$this->db = mysql_connect($this->config['dbhost'], $this->config['dbuser'], $this->config['dbpass']);
self::select_db();
if (!$this->db)
die('Unable to connect to MySQL server. MySQL reported: '.mysql_error());
}
function select_db()
{
if(!mysql_select_db($this->config['dbname']))
die('Unable to select database. MySQL reported: '.mysql_error());
}

Rispondi quotando