It's been a while since I touched mysql, for various reasons I had to do it I have a file of tests, when I execute my consula in phpmyadmin it works and returns data, if I place the query in a stored procedure it returns data, but I should not use stored procedure, I do not know what to do in the file to execute, now that I go up now I removed the ? ,? and replace them with the user and password but still without results.
I would greatly appreciate your help. Thank you in advance.
Session file
<?php
include("conexion.php");
class Sesion
{
function login($user, $password)
{
$newconex = new DataBase();
$quo=" SELECT U._ID AS '_ID',
TRIM(CONCAT(P.NOMBRE,' ',P.APELLIDO)) AS 'NOMBRE'
FROM 'usuarios' U, 'personas' P
WHERE P._ID=U._ID_PERSONA
AND U.USUARIO='admin'
AND U.'CONTRASEÑA'=SHA1('admin');";
$parametros = array($user,$password);
$resultado = $newconex->query($quo,$parametros);
$newconex=null;
if($resultado)
{
session_start();//inicia la sesion
$_SESSION['UCREA'] =$resultado[0]['_ID'];
$_SESSION['NOMBRE'] =$resultado[0]['NOMBRE'];
return 1;
}
else
{
return 0;
}
}
}?>
DB Class
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
/* clase de base da datos */
class DataBase {
private $conexion = null;
/* Construcctor */
public function __construct()
{
$HOST = "localhost";
$DBNAME = "test";
$USERNAME = "root";
$PASSWORD = "";
try {
$this->conexion = new PDO("mysql:host=".$HOST.";dbname=".$DBNAME, $USERNAME, $PASSWORD);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
public function desconectar()
{
if($this->conexion != null) $this->conexion = null;
}
public function query($sql,$parametros)
{
$make = $this->conexion->prepare($sql);
if(is_array($parametros))
{
$make->execute($parametros);
}
else
{
$make->execute();
}
$result = $make->fetchall();
$make->closeCursor();
return $result;
}
public function query_exec($sql,$parametros)
{
$make = $this->conexion->prepare($sql);
if(is_array($parametros))
{
$result = $make->execute($parametros);
}
else
{
$result = $make->execute();
}
$make->closeCursor();
return $result;
}
}
?>
Execution file
<?php
include("class/sesion.php");
$sesion =new Sesion();
echo $sesion->login("admin","admin");
?>
As annotations I want to emphasize that if I do a simple select like
Select 'something' as 'value';
I get results, if I delete the where I get results ... if I use consultation in a stored procedure I get results ... the details is that I can not use it, because it is necessary to see the code in php
/////////// APPENDIX STORED PROCEDURE
DELIMITER //
CREATE PROCEDURE CHECK_SESION(IN username VARCHAR(255),IN userpassword VARCHAR(255))
BEGIN
SELECT U._ID AS '_ID', TRIM(CONCAT(P.NOMBRE,' ',P.APELLIDO)) AS 'NOMBRE'
FROM 'usuarios' U, 'personas' P
WHERE P._ID=U._ID_PERSONA
AND U.USUARIO=username
AND U.'CONTRASEÑA'=SHA1(userpassword);
END //
DELIMITER ;