PDA

View Full Version : [PHP]mysql_select_db e classe


bprogram
16-05-2004, 21:53
in questa classe


<?php
//=> [Classificazione] Classe Generale da inserire solamente
// nell'index.php dove verrano richiamati tutti gli altri file
// di FMP

//=> MySQL Db Classes
class MySQL {

//**Database connect and Select**
var $dbhost;
var $dbuser;
var $dbpass;
var $dbname;
var $dbhost;
var $dbuser;
var $dbpass;
var $dbname;
var $db_prefix;
var $query;
var $fetcharray;
var $conn;
var $select;
//**Database Error's**
var $is_error;
var $msg_error;

function MySQL ( $dbhost = '', $dbuser = '', $dbpass = '', $dbname = ''){

/*$this->host = (string) $dbhost;
$this->dbuser = (string) $dbuser;
$this->dbpass = (string) $dbpass;
$this->dbname = (string) $dbname;*/
$this->is_error = FALSE;
$this->msg_error = '';

//return is_resource( $this->Connect() ) ? $this->Connect() : null;

}


function Connect($dbhost = '', $dbuser = '', $dbpass = '', $dbname = ''){

$this->host = (string) $dbhost;
$this->dbuser = (string) $dbuser;
$this->dbpass = (string) $dbpass;
$this->dbname = (string) $dbname;
$this->is_error = FALSE;
$this->msg_error = '';

$this->conn = mysql_connect($this->host,$this->dbuser,$this->dbpass);
$this->select = mysql_select_db('cittaitnernet_config',$this->conn);

if( is_resource($this->conn) )
{
echo $this->dbname;
$this->select = mysql_select_db('cittaitnernet_config',$this->conn);
}
else
{
$this->is_error = TRUE;
$this->msg_error = 'connessione fallita'.mysql_errors;
return(0);
}



return $this->conn;
return $this->select;

}



function query($query = NULL)
{

$this->query = (string) $query;

if ( is_resource( $this->Connect() ) )
{

$this->query = mysql_query($this->query,$this->Connect());
if (! is_resource($this->query))
{
$this->is_error = TRUE;
$this->msg_error = mysql_error();

}
}
else
{
$this->is_error = TRUE;
$this->msg_error = 'connessione fallita ';
}

return $this->query;

}

function fetcharray($fetcharray = NULL)
{

if (!is_resource($fetcharray)) {
$this->is_error = TRUE;
$this->msg_error = 'risorsa non valida';
return FALSE;
}

$this->fetcharray = $fetcharray;


if ( is_resource( $this->Connect() ) )
{

$this->fetcharray = mysql_fetch_array($this->fetcharray);
if (! is_resource($this->fetcharray))
{
$this->is_error = TRUE;
$this->msg_error = mysql_error();

}
}
else
{
$this->is_error = TRUE;
$this->msg_error = 'connessione fallita';
}

return $this->fetcharray;

}

function close () {

mysql_close($this->Connect());

}

}
?>


Funziona tutto benissimo, tranne che il mysql_select_db, nn vuol funzionare in alcunissimo modo, il bello e che se scrivo ad esempio mysqlssss_select_db, mi da l'errore che dice che nn è una funzione riconoscita, e anke altre scemarie, pero, nn fa proprio il select -.-, secondo voi perke ?

Fenomeno85
17-05-2004, 18:24
function Connect($dbhost = '', $dbuser = '', $dbpass = '', $dbname = '')

la cosa che mi fa rimanere perplesso è perchè fai così la chiamata alla procedura, non so ma secondo me devi togliere = '' e farla divenatare:

function Connect($dbhost, $dbuser, $dbpass, $dbname)

perchè se no alle variabili che passi gli metti valore nullo.

MEMBRO DEL GRAN CONSIGLIO DELLE CACCOLE VERDI

~§~ Sempre E Solo Lei ~§~

McK
17-05-2004, 19:33
confermo quanto risposto sopra.
Più che altro non capisco la necessità di creare una classa in php... però no problem.

Se le variabili le avevi assegnate da fuori dentro la funzione, pre prenderne il valore le devi dichiarare come "global", altrimenti ti assegna a quel nome una nuova zona di memoria VUOTA, costringendoti a riassegnare!

Ciao, McK