quiero compartir con el foro una de las clases que he implementado para proveer acceso a base de datos, sucede que he estado construyendo un mini framework .net bajo php5, lo que pretendo es facilitar el uso de php para programadores .net ademas de aprender mediante el proceso de elaboracion de un pequeño core que es muy similar al ADO.NET.
P.D: lo hago a modo de practica para aprender mejorar mis conocimientos sobre OOP y es que me exista ver los codigos que publican algunos miembros como Enrique y GatorV entre otros.
Saludos al foro.
Enjoy It!!!..
Código PHP:
<?php
/**
* Class to provide access to a database Mysql on a server.
*
* @package
* @subpackage
* @name MySqlConnection
* @version $Id:$
* @author Jacksson Enrique Mosquera Rivas
*/
final class MySqlConnection implements IDbConnection
{
/******************************************************/
/* Internal Member */
/******************************************************/
private $ServerName;
private $UserName;
private $Password;
private $Database;
private $Connection;
/******************************************************/
/* Construct */
/******************************************************/
public function __construct($ServerName, $UserName, $Password, $Database ) {
$this->ServerName = $ServerName;
$this->UserName = $UserName;
$this->Password = $Password;
$this->Database = $Database;
}
/******************************************************/
/* Property */
/******************************************************/
public function get_ConnectionString () {
throw new Exception('Function not implemented yet');
}
public function set_ConnectionString ($value) {
throw new Exception('Function not implemented yet');
}
public function get_ServerName() {
return $this->ServerName;
}
public function set_ServerName($value) {
$this->ServerName = $value;
}
public function get_Database() {
return $this->Database;
}
public function set_Database($value) {
$this->Database = $value;
}
public function get_UserName() {
return $this->UserName;
}
public function set_UserName($value) {
$this->UserName = $value;
}
public function get_Password() {
return $this->Password;
}
public function set_Password($value) {
$this->Password = $value;
}
//Todo: Eliminar este metodo.
public function get_Connection () {
return $this->Connection;
}
/******************************************************/
/* FUNCTIONS */
/******************************************************/
public function BeginTransaction() {
throw new Exception('Function not implemented yet');
}
public function EndTransaction() {
throw new Exception('Function not implemented yet');
}
public function Close() {
mysql_close( $this->Connection );
}
public function Open() {
$this->Connection = mysql_connect( $this->get_ServerName(), $this->get_UserName(), $this->get_Password() );
if( $this->Connection ) {
mysql_select_db( $this->get_Database() );
}else{
throw new Exception('DataBase Error: ' . mysql_error() );
}
}
public function ChangeDatabase($Database){
$this->set_Database($Database);
if( $this->Connection ) {
$this->Close();
}
$this->Open();
}
/******************************************************/
/* Destruct */
/******************************************************/
public function __destruct() {
}
}
?>