Aca pongo un pequeño script que he ido modificando con el tiempo, para la conexion a las bases de datos y operaciones basicas de esta.
Lo he probado con PostgreSQL y con MySQL y ha funcionado de maravillas, espero sus opiniones.
class sql
{
var $host;
var $usuario;
var $password;
var $db;
var $enlace;// Constructor Method
function sql()
{
$this->host=”localhost”;
$this->usuario=”ricamato_ricaDB”;
$this->password=”password”;
$this->db=”ricamato_ricaDB”;
$this->enlace=$enlace;
}function conectar()
{
if (!$this->enlace=mysql_connect($this->host,$this->usuario,$this->password,$this->db))
{
die(‘Error conectando con la base de datos: ‘ . $host);
}if (!mysql_select_db($this->db,$this->enlace))
{
die(‘Error seleccionando la base de datos: ‘ . $db);
}
}function consulta($sentenciaSQL)
{
$this->consulta=mysql_query($sentenciaSQL,$this->enlace);
}function obtenerResultado(){
$this->resultado=mysql_fetch_array($this->consulta);
return $this->resultado;
}function insertarRegistro($sentenciaSQL){
if (mysql_query($sentenciaSQL,$this->enlace))
{
$insertar=TRUE;
}
}function desconectar()
{
mysql_close($this->enlace);
}
}
?>
Para utilizarla basta con editar el nombre de usuario, contraseña, nombre de la base de datos y el host.
Un ejemplo claro seria :
- $sql = new sql();
- $sql->conectar();
- $sql->insertarRegistro(‘INSERT INTO ejemplo VALUES(’1′,’ejemplo’)');
- $sql->desconectar();
Frente a cualquier duda posteala en comentarios.

3 Trackbacks
Puedes enviar un trackback usando esta URL: http://www.dokshor.com/bases-de-datos-en-php/trackback
-1…
below are some links I found useful…
Mediafire and Megaupload link…
[...]found this great release site[...]……
youlikehits bot download…
I mean, we aren’t ALL expert writers are we? The difficulty is though, if you are wanting to be successful online, you HAVE be able to generate excellent Quality content, and just as prominently, unique content! Article Magic Cash System is Just an Pe…
3 Comentarios
Ojo que para PostgreSQL se necesita otra libreria en PHP, pronto la publicare.
nice production but i consider it should by solon around message from primary relation of article. Btw recognise on industrialist
over IP
Hey not to go off topic but can anyone give me a review of. New York Car Insurance Reform 295 Greenwich St, New York, NY 10007 (646) 351-0824 They’re just down the block from me. I was wondering once they were a good insurance agency. I need to acquire coverage, it is the law you know, but I need to have a good price price plus I want friendly service.