Created
February 27, 2013 19:51
-
-
Save rooven/5051105 to your computer and use it in GitHub Desktop.
conexion a base de datos SQL con PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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