Código PHP:
<?php
class Mysql
{
private $_server = "localhost";
private $_user = "user";
private $_pass = "pass";
private $_db = "db";
private $_conexion;
private $_flag = false;
public function __construct()
{
$this->_connect();
}
private function _connect()
{
$this->_conexion = mysql_connect($this->_server, $this->_user, $this->_pass);
if($this->_conexion){
if(mysql_select_db($this->_db, $this->_conexion)){
$this->_flag = true;
return $this->_conexion;
}else{
print "No se ha seleccionado BD";
}
}else{
print "Error de conexion";
}
}
public function query($query)
{
return mysql_query($query);
}
public function close()
{
if($this->_flag == true){
mysql_close($this->_conexion);
}
}
?>
Código PHP:
<?php
include("_class/_mysql.php");
class Operacion extends Mysql
{
public function __construct()
{
$this->sql();
}
private function sql()
{
$sql = $this->query("SELECT * FROM tabla") or die(mysql_error());
}
}
$operacion = new Operacion();
?>
Código PHP:
No database selected
Un saludo