Bases de datos en PHP

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 :

  1. $sql = new sql();
  2. $sql->conectar();
  3. $sql->insertarRegistro(‘INSERT INTO ejemplo VALUES(’1′,’ejemplo’)');
  4. $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. Por Rendy en 9 diciembre 2011 a las 20:02

    -1…

    below are some links I found useful…

  2. Mediafire and Megaupload link…

    [...]found this great release site[...]……

  3. Por YouLikeHits Blot Collections en 29 marzo 2012 a las 19:48

    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

  1. 0x01

    Ojo que para PostgreSQL se necesita otra libreria en PHP, pronto la publicare.

    Comentado 26 octubre 2006 a las 23:30 | Permalink
  2. nice production but i consider it should by solon around message from primary relation of article. Btw recognise on industrialist
    over IP

    Comentado 25 enero 2012 a las 11:28 | Permalink
  3. 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.

    Comentado 4 abril 2012 a las 18:10 | Permalink

Escribe un Comentario

Tu e-mail nunca será compartido. Los campos requeridos están marcados *

*
*

dokshor.com (RSS) + Sator-ii theme by Felipe Lavín and finally edited by dokshor.

hacker emblem