Obtain individual fixes with PDO fetchAll

0

good morning, I'm trying to do some validations with fetch all

this is my code

    $usuariodb = strtolower($_POST['usuario']);
    $passworddb = strtolower($_POST['password']);

    $conn = new PDO('mysql:host=localhost;dbname=db;charset=UTF8','guest','guest');
    //$sql = "SELECT name FROM loginUsr WHERE name ='".strtolower($usuariodb)."'";
    $sql = "SELECT * FROM loginUsr BETWEEN name = $usuariodb AND password = $passworddb";
    $result = $conn->query($sql);
    //nombre del usuario en db para validar
    $rows = $result->fetchAll();


    if ($usuariodb == $rows['name']) {
        header('Location: prueba.php');
    }

The last part of the if I would like to directly access each of the data in the rows directly but I am getting as output Fatal error: Call to a member function fetchAll ()

    
asked by matteo 02.01.2017 в 19:58
source

2 answers

1

I think you need to indicate the type of fetchAll.

Try this way

$rows = $result->fetchAll(PDO::FETCH_ASSOC);
    
answered by 02.01.2017 в 21:28
1

The fetch method only returns a PDOStatement if the query is correct, otherwise it returns false and that is why it gives you the error.

    
answered by 03.01.2017 в 22:58