Código PHP:
No database selected
Código PHP:
class Connectar{
var $usuario;
var $pass;
var $host;
var $error;
var $basedatos;
var $enlace;
var $db_select;
function __construct($host,$usuario,$pass,$basedatos){
$this->host=$host;
$this->usuario=$usuario;
$this->pass=$pass;
$this->basedatos=$basedatos;
}
/*function err(){
echo $this->error = mysql_error();
}*/
function conecta(){
$this->enlace=mysql_connect($this->host,$this->usuario,$this->pass) or die(mysql_error());
$this->db_select=mysql_select_db($basedatos,$this->enlace)or die(mysql_error());
}
}
$obj = new Connectar("localhost","root","","oop_db");
$obj->conecta();
/* clase para consultar datos */
class Consulta extends Connectar{
var $consulta;
var $resultado;
var $query;
var $tabla;
var $row;
/*function __construct(){
$this->query=$query;
}*/
function datos($query){
$this->consulta=mysql_query($query,$this->db_select)or die("Error en consulta ".mysql_error());
}
}
$obj2 = new Consulta();
$obj2->datos("SELECT * FROM tbl_usuarios");