Abstract class, singleton pattern and database

General discussions related to php

Moderators: macek, egami, gesf

slacker
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Aug 18, 2012 8:38 am

Abstract class, singleton pattern and database

Postby slacker » Sat Aug 18, 2012 11:06 am

Hi everyone,

I'm starting to code a web platform with php 5.3 + MySQL and i'm trying to coded this abstract class

Code: Select all

include_once '../eEstadoConexion.php';  // --> Enum for connections states

class cConexionMySQL
{
   //   Atributos
   private $_IP_Servidor;
   private $_Nombre_DB;
   private $_Puerto;
   private $_NombreUsuario;
   private $_Password;

   private $_Conexion = NULL;

   private $_EstadoConexion = eEstadoConexion::_Cerrada;
   
   private static $_Instancia = NULL ;

   //   Getters ...
        //      Setters ...
        //      Other functions ...
}


I extended the class cUsuarioMySQL from the class i just wrote.

Code: Select all

include_once "../abstractas/cConexionMySQL.php";

final class cUsuarioMySQL extends cConexionMySQL
{
   //   Atributos
   private static $_Instancia = NULL;
   private $_SQL_ValidarUsuario = "call sp_Veterinaria_ValidarUsuario(?,?, @registro)";

   //   Constructor
   private function __construct ( )
   {
   }

   //   Obtenedor de instancia
   public static function obtenerInstancia ( $pIP_Servidor, $pNombre_DB, $pPuerto, $pNombreUsuario, $pPassword )
   {
      if ( !( self::$_Instancia instanceof self) )
      {
         self::$_Instancia = new self ( );
         self::$_Instancia -> setIP ( $pIP_Servidor, $pPuerto );
         self::$_Instancia -> setNombreDB ( $pNombreDB );
         self::$_Instancia -> setNombreUsuario ( $pNombreUsuario, $pPassword );
      }

      return self::$_Instancia;
   }

        //  Other functions ...
}


And this is the way i used the extended class..

Code: Select all

<?php

include_once 'clases/datos/cUsuarioMySQL.php';

$nombre = "user";
$password = "password";

try
{
   $conexion = cUsuarioMySQL::obtenerInstancia("localhost", "db", 3306, "user", "password" );
}
catch( Exception $ex )
{
    echo $ex -> getMessage ( );
}
?>


And here it is the problem... When i execute the code i keep getting a Error de HTTP 500 (Internal Server Error) from google chrome (Also tried this on firefox and i get the same result) and i don't know why, yet. I googled and the way i coded isn't wrong as far as i know. I tried also to change the singletton pattern to the class that extend the cConexionMySQL class. Also tried changing the self

Someone know where is the bug ???

Thanks.

NigelRen
php-forum Active User
php-forum Active User
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Abstract class, singleton pattern and database

Postby NigelRen » Sat Aug 18, 2012 11:56 pm

You should be able to look at the server log files to see what errors - if any are being recorded. Have a look at the apache log files.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Abstract class, singleton pattern and database

Postby johnj » Tue Aug 21, 2012 9:01 pm

Try a simple example in php like a hello world example without using objects and classes and see if you are able to access this example/page from your server. If you cannot access/run this example then you know the problem has nothing to do with abstract classes, the problem is with your set up.


Return to “PHP General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest