MYSQL Query无法从数据库中提取数据

时间:2014-10-10 22:19:39

标签: php mysql sql null prepare

我遇到的问题是我的查询:

SELECT * FROM administradores WHERE nombre_administrador=? AND password=?

不会将任何内容从数据库中拉出来。

var_dump显示:

  public 'affected_rows' => null, public 'insert_id' => null
  public 'num_rows' => null
  public 'param_count' => null
  public 'field_count' => null
  public 'errno' => null
  public 'error' => null
  public 'error_list' => null
  public 'sqlstate' => null
  public 'id' => null

的login.php

<?php
    class login{
        //Variable for MySql connection
        private $hookup;
        private $sql;
        private $tableMaster;

        //Field Variables
        private $pass;
        private $name;

        public function __construct()
        {
            //Get table name and make connection
            $this->mysqli=UniversalConnect::doConnect();

            //Get data from HTML form
            $this->name=$_POST['name'];
            $this->pass=$_POST['pass'];
            //Call private methods for MySql operations
            $this->dologin();
            $this->mysqli->close();
        }

        private function dologin()
        {
            if ($stmt = $this->mysqli->prepare("SELECT * FROM administradores WHERE nombre_administrador=? AND password=?")){
                var_dump($stmt);
                /* bind parameters for markers */
                $stmt->bind_param('ss', $this->name, $this->pass);
                var_dump($this->name);
                var_dump($this->pass);
                /* execute query */
                $stmt->execute();

                /* bind result variables */
                $stmt->bind_result($id,$nombre_administrador,$password,$ubicacion,$nombre,$apellido);

                /* fetch value */
                $stmt->fetch();
                /*get number of rows*/
                $num_row =$stmt->num_rows;

                if($num_row==1){
                    echo 'true';
                    $_SESSION['Name'] = $row['nombre_administrador'];
                    $_SESSION['Id'] = $row['id'];
                    header("location:  http://localhost/SCAF1.0/indexSCAF.html");
                } else {
                    echo "<script>alert('wrong password');</script>";
                    echo 'false';
                }
            } else{
                echo "Falló la conexión con MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error;
            }

            $stmt->close();
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

反引号不应该是一个问题,但它们不一定是必需的。听起来可能存在连接错误。