bueno io mi conexion la realizo de esta forma:
Código PHP:
var $hostname = "localhost";
var $database = "basedatos";
var $username = "user";
var $password = "password";
var $conexion;
/*---CONSTRUCTOR---*/
function conexionbd()
{
if(!isset($this->conexion))
{
$this->conexion = mysql_connect($this->hostname, $this->username, $this->password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($this->database, $this->conexion) or die(mysql_error());
}
}
/*---FUNCIONES---*/
function consulta($consulta)
{
$this->total_consultas++;
$resultado = mysql_query($consulta,$this->conexion);
if(!$resultado)
{
echo 'MySQL Error: '.mysql_error();
exit;
}
return $resultado;
}
Espero te sirva