Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/01/2017, 13:36
infoturnosya
 
Fecha de Ingreso: diciembre-2015
Ubicación: rosario
Mensajes: 69
Antigüedad: 8 años, 5 meses
Puntos: 5
Respuesta: Problema consulta php POO

Código PHP:
Ver original
  1. class ConnectDB{
  2.  
  3.     private $host;
  4.     private $user;
  5.     private $pass;
  6.     private $db;
  7.     public $conexion;
  8.  
  9.     function ConnectDB($host, $user, $pass, $db){
  10.         $this -> host = $host;
  11.         $this -> user = $user;
  12.         $this -> pass = $pass;
  13.         $this -> db = $db;
  14.     }
  15.  
  16.     public function ConectarMySQL(){
  17.         return $this -> conexion = mysqli_connect($this -> host, $this -> user, $this -> pass);
  18.     }
  19.    
  20. }

Código PHP:
Ver original
  1. require("ConnectDB.php");
  2.  
  3.  
  4. class Registro{
  5.     private $usuario;
  6.     private $password;
  7.     private $PassEncrypt;
  8.     public  $objCnn;
  9.    
  10.     function __construct(){
  11.         $conexion = new ConnectDB('127.0.0.1', "tuuser","", "tupass");
  12.         $this->objCnn = $conexion -> ConectarMySQL();
  13.     }
  14.    
  15.     function RegistrarUsuario($p_usuario, $p_password){
  16.         $this -> usuario = strtoupper($p_usuario);
  17.         $this -> password = strtoupper($p_password);
  18.         $this -> PassEncrypt = sha1($this -> usuario.":".$this -> password);
  19.         $tildes = $this->objCnn->query("SET NAMES 'utf8'"); //Para que se inserten las tildes correctamente
  20.         /*AQUI NECESITO SABER COMO ESTABLECER UNA SENTENCIA, PORQUE NO ENTIENDO COMO
  21.         LLAMAR A LA CONEXION, YA QUE SALE "QUERY NON OBJECT" ALGO ASI, Y NO LOGRO REGISTRAR
  22.         AL USUARIO.*/
  23.         mysqli_select_db($this->objCnn, "prueba");
  24.         $query = "
  25.             INSERT INTO user (usuario, contrasenia) VALUES ('".$this->usuario."','".$this -> password."');";
  26.         echo '$query '.$query ;
  27.        
  28.         if(mysqli_query($this->objCnn, $query)){
  29.             echo "Records added successfully.";
  30.         } else{
  31.             echo "ERROR: Could not able to execute $sql. " . mysqli_error($this->objCnn);
  32.         }
  33.        
  34.  
  35.         echo "<h2>Thank you for your Comment!</h2>";
  36.  
  37.         mysqli_close($this->objCnn);
  38.  
  39.     }
  40. }
  41.  
  42.  
  43. $registrar = new Registro();
  44. $registrar -> RegistrarUsuario('julio','564564');