Skip to content

Instantly share code, notes, and snippets.

@rooven
Created February 27, 2013 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rooven/5051105 to your computer and use it in GitHub Desktop.
Save rooven/5051105 to your computer and use it in GitHub Desktop.
conexion a base de datos SQL con PHP
<?php
class ConexionBD
{
var $servidor;
var $base_datos;
var $usuario;
var $password;
var $conexion;
function ConexionBD($usr,$bd,$srvr,$pass)
{
$this->base_datos=$bd;
$this->servidor=$srvr;
$this->usuario=$usr;
$this->password=$pass;
}
function conectar()
{
$this->conexion=mysql_connect($this->servidor,$this->usuario,$this->password);
mysql_select_db($this->base_datos,$this->conexion);
}
function desconectar()
{
mysql_close($this->conexion);
}
function ejecutarsentencia($sql)//esta funcion ejecuta la sentencia y devuelve el resultado de la operacion
{
$this->conectar();
$resultados=mysql_query($sql,$this->conexion);
if(preg_match("/insert/i", $sql))
$resultados = mysql_insert_id($this->conexion);
$this->desconectar();
return $resultados;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment