Código:
Gestion.php<?php require_once '../ds/Gestion.php'; class LoginModel{ public function ValidarEmpleado($usuario,$clave){ try{ $consulta="select * from usuario where usuario='".$usuario."' and clave='".$clave."'"; $gestion=Gestion::getInstancia(); $lista=$gestion->executeQuery($consulta); if(count($lista)==0){ //throw new Exception("Usuario No Existe."); } $rpta=false; if($clave==$lista[0]["Clave"]){ $rpta=true; } return $rpta; }catch(Exception $e){ throw $e; } }//Fin Del Metodo } ?>
Código:
<?php class Gestion{ //Sigleton private static $instancia = null; public static function getInstancia(){ try{ if( self::$instancia == null){ self::$instancia = new Gestion(); } }catch(Exception $e){ throw $e; } //return self::$instancia;a } public $cn = null; function __construct(){ try{ $this->cn=mysql_connect("localhost","root",""); if(!$this->cn){ $this->cn = null; throw new Exception("Error En La Conexión Con El Servidor."); } $db=mysql_select_db("colegio",$this->cn); if(!$db){ mysql_close($this->cn); $this->cn = null; throw new Exception("Base De Datos No Existe."); } }catch(Exception $e){ error_log($e->getMessage()."\n\n",3,"../Log/Error.log"); throw $e; } } public function executeQuery($consulta){ try{ $rs=mysql_query($consulta,$this->cn); if(mysql_error($this->cn)!=0){ throw new Exception(mysql_error($this->cn)); } $lista=array(); while($row=mysql_fetch_assoc($rs)){ $lista[]=$row; } mysql_free_result($rs); return $lista; }catch(Exception $e){ error_log($e->getMessage()."\n\n",3,"../Log/Error.log"); error_log("Query: $consulta\n\n",3,"../Log/Error.log"); throw $e; } } //Metodo que ejecuta actualizacion(update,insert,delete) public function ejecutarActualizacion($consulta){ try{ mysql_query($consulta,$this->cn); if(mysql_errno($this->cn)!=0){ throw new Exception("Error al ejecutar $sql"); } } catch(Exception $ex){ error_log($ex->getMessage()."\n\n",3,"../log/Error.log"); throw $ex; //Disparamos el error hacia otro nivel } //fin del catch } //fin del metodo } ?>
me sale este error al logearme :
Fatal error: Call to a member function executeQuery() on a non-object in C:\xampp\htdocs\clase10\model\loginmodel.php on line 9