Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/01/2012, 11:19
Avatar de miguec04
miguec04
 
Fecha de Ingreso: agosto-2008
Ubicación: Cimitarra, Santander
Mensajes: 378
Antigüedad: 16 años, 5 meses
Puntos: 15
Respuesta: Esta correcto esto ?

Algo importante en tu codigo veo muchos errores,

Código PHP:
Ver original
  1. <?php
  2. class Mysql {
  3.    
  4.     private static $conexion        = NULL;
  5.     private static $query           = NULL;
  6.  
  7.     const USUARIO                   = 'root';
  8.     const CLAVE                     = 'cxeducativa';
  9.     const SERVIDOR                  = 'localhost';
  10.     const BASE_DATOS                = 'colsanpedro';
  11.    
  12.     const BEGIN                     = 'BEGIN';
  13.     const COMMIT                    = 'COMMIT';
  14.     const ROLLBACK                  = 'ROLLBACK';
  15.    
  16.     const ERROR_SINTAXIS            = 'HA OCURRIDO UN ERROR VUELVA A INTENTARLO';
  17.    
  18.     public static function Conectar() {
  19.         self::$conexion     = mysql_connect(self::SERVIDOR,self::USUARIO,self::CLAVE);
  20.         mysql_select_db(self::BASE_DATOS,self::$conexion);
  21.     }
  22.    
  23.     public static function Begin() {
  24.         self::Conectar();
  25.         mysql_query(self::BEGIN,self::$conexion);
  26.     }
  27.    
  28.     public static function Query($sql) {
  29.         self::$query        = mysql_query($sql,self::$conexion);
  30.         if(!self::$query) {
  31.             throw new Exception(self::ERROR_SINTAXIS);
  32.         }
  33.     }
  34.    
  35.     public static function Num() {
  36.         return mysql_num_rows(self::$query);
  37.     }
  38.    
  39.     public static function Rows() {
  40.         return mysql_fetch_array(self::$query);
  41.     }
  42.    
  43.     public static function Free() {
  44.         mysql_free_result(self::$query);
  45.     }
  46.    
  47.     public static function Close($free) {
  48.         if(self::$query!=NULL && $free) {
  49.             mysql_free_result(self::$query);
  50.         }
  51.         mysql_close(self::$conexion);
  52.     }
  53.    
  54.     public static function Commit() {
  55.         mysql_query(self::COMMIT,self::$conexion);
  56.     }
  57.    
  58.     public static function Rollback() {
  59.         mysql_query(self::ROLLBACK,self::$conexion);
  60.     }
  61.    
  62.     public static function finTransaccion($guardar,$free=TRUE) {
  63.         if($guardar) {
  64.             self::Commit();
  65.         } else {
  66.             self::Rollback();
  67.         }
  68.         self::Close($free);    
  69.     }
  70. }
  71. ?>

te comparto mi conexion a la base de datos, espero te sirva, y te doy un ejemplo

Código PHP:
Ver original
  1. require_once 'Mysql.php';
  2. class ModeloDatos {
  3.    
  4.     protected $conexion;
  5.    
  6.     public function __construct() {
  7.        
  8.     }
  9.  
  10.         public function getSnParametrosInicialesConsulta($anoB) {
  11.         $sql            = "select * from sn_parametros_iniciales where ano=$anoB";
  12.         $resultado      = array();
  13.         try {
  14.             Mysql::Begin();
  15.             Mysql::Query($sql);
  16.             while($row = Mysql::Rows()) {
  17.                 $objeto         = new SnParametrosInicialesDto();
  18.                 Util::setAsignarObjetoConsulta($objeto, $row);
  19.                 $resultado[]    = $objeto;
  20.             }
  21.             Mysql::finTransaccion(TRUE);
  22.         } catch (Exception $e) {
  23.             Mysql::finTransaccion(FALSE);
  24.             echo $e->getMessage();
  25.         }
  26.         return $resultado;
  27.     }
  28. }
__________________
Desoftc Technology - Miguel Carmona
Creaciones Inteligentes - Cimitarra Colombia
[email protected]
http://www.desoftc.com.co