zend framework 2 autentification using DbTable failure

Posted by josepmra on Stack Overflow See other posts from Stack Overflow or by josepmra
Published on 2012-10-27T20:11:51Z Indexed on 2012/10/27 23:01 UTC
Read the original article Hit count: 359

I have followed the zend instructions for implement my web Authentication using a database table.

It's exactly the same code, but when render the page, the following exceptions appears:

    Zend\Authentication\Adapter\Exception\RuntimeException
    File:
    C:\xampp\htdocs\pfc\vendor\ZF2\library\Zend\Authentication\Adapter\DbTable.php
    Mensaje:
    The supplied parameters to DbTable failed to produce a valid sql statement, please
    check table and column names for validity.

produced by this other:

    Zend\Db\Adapter\Exception\InvalidQueryException
    File:
    C:\xampp\htdocs\pfc\vendor\ZF2\library\Zend\Db\Adapter\Driver\Mysqli\Statement.php
    Mensaje:
    Statement couldn't be produced with sql: SELECT `users`.*, (CASE WHEN `password` = ?
    THEN 1 ELSE 0 END) AS `zend_auth_credential_match` FROM `users` WHERE `mail` = ?

Seems to be that Statement.php can not execute the sql of above, but I send the sql by phpmyadmin replacing the ? for strings and work ok.

I am sure that $dbAdapter works ok also because I have tested it and the columns name are "mail" and "password".

This in my code, also I put the $dbAdapter test code.

    $dbAdapter = new DbAdapter(array(   //This DbAdapter Work ok sure!!
        'driver' => 'Mysqli',
        'database' => 'securedraw',
        'username' => 'root',
        'password' => ''
    ));

    $fp = function($name) use ($dbAdapter) { return $dbAdapter->driver->formatParameterName($name);};
    $sql = 'SELECT * FROM ' . $qi('users') . ' WHERE id = ' . $fp('id');
    $statement = $dbAdapter->query($sql);
    $parameters = array('id' => 1);
    $sqlResult = $statement->execute($parameters);
    $row = $sqlResult->current();
    $mail = $row['mail'];
    $password = $row['password'];  //until here test $dbAdapter exitly!!

    //Start the auth proccess!!
    $authAdapter = new AuthDbTableAdapter($dbAdapter);
    $authAdapter->setTableName('users')
    ->setIdentityColumn('mail')
    ->setCredentialColumn('password');
    $authAdapter->setIdentity('josep')
    ->setCredential('josep');
    $authResult = $authAdapter->authenticate();   //This is the fail method!!!

© Stack Overflow or respective owner

Related posts about authentication

Related posts about zend-framework2