The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement

前端 未结 7 2219
终归单人心
终归单人心 2021-01-25 01:53

I have the following exception Caught exception: The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and colum

相关标签:
7条回答
  • 2021-01-25 02:33

    Ok so first off I need to make all aware that this answer has been patented and licensed under one of those linceses that mean that you can't even read or come up with a similar answer.(you know I kidding right?). Ok ok to the point ....

    After 3 days I stumbled upon a solution. A weird one of cause but it fixed my problem. So things were not working and no one had answered my question so I got hold of this new zend book that I bought to just try and distract myself from the problem. A further distraction was to boot into Linux instead of windows (I dual boot you know).

    In Linux i just decided to create a virtual host for the problematic project and just try and run it. To my supprise it run without problems. I was able to login. Then i took a look at phpmyadmin and saw that I the mysql version is 5.1 where as the one on my widows setup is 5.5. So I thought why not downgrade the mysql in windows from 5.5 to 5.1.

    So i did et viola my problem was gone. I don't know what the folks at mysql did to it but it seems ver 5.5 may have issues with SHA1. Not sure if it applies to other hash functions though. May be someone will comfirm this suspicion?

    0 讨论(0)
  • 2021-01-25 02:37

    As Kervin has already answered, this error appears because of collation mismatch between php and mysql.

    You can either stop using utf8 as suggested in the above solution or you can change the database table to use utf8.(It worked for me only after I deleted the data inside the table and reinserted them.)

    0 讨论(0)
  • 2021-01-25 02:43
        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
    
        $version = $dbAdapter->getServerVersion();
    
        if (!is_null($version))
        {
            if (version_compare($version, '5.5', '>=')){
                $credentialTreatment = 'CAST(SHA1(CONCAT(?, salt)) AS CHAR) AND active = 1';
            }else{
                $credentialTreatment = 'SHA1(CONCAT(?, salt)';
            }
        }
    
    
        $authAdapter->setTableName('users')
        ->setIdentityColumn('username')
        ->setCredentialColumn('passwd')
        ->setCredentialTreatment($credentialTreatment);
    
        return $authAdapter;
    

    Please check this

    As of MySQL 5.5.3, the return value is a nonbinary string in the connection character set. Before 5.5.3, the return value is a binary string; see the notes at the beginning of this section about using the value as a nonbinary string.

    It's works for me.

    0 讨论(0)
  • 2021-01-25 02:51

    It depends on MySQL version as described above. Following MySQL Documentations for version 5.5:

    "If an application stores values from a function such as MD5() or SHA1() that returns a string of hex digits, more efficient storage and comparisons can be obtained by converting the hex representation to binary using UNHEX() and storing the result in a BINARY(N) column. Each pair of hex digits requires one byte in binary form, so the value of N depends on the length of the hex string. N is 16 for an MD5() value and 20 for a SHA1() value."

    So, instead of downgrading MySQL version, you may do as follows:

    • change type of 'password' column from varchar(32) to binary(16)
    • add 'UNHEX()' MySQL function to your MySQL query in ZF code, for example:
    $adapter = new Zend_Auth_Adapter_DbTable(
        $db,
        'user',
        'login',
        'password',
        'UNHEX(MD5(CONCAT(?, passwordSalt)))'
    );
    

    It works well in my case.

    Edit -- If your password salt is also stored in a binary column (e.g. if it too was a hex string generated through the SHA1 function) then the last parameter of the Zend_Auth_Adapter_DbTable should be: 'UNHEX(SHA1(CONCAT(?, LOWER(HEX(salt)))))' So, we are converting the salt back to a lowercase hex string before concatenating with the password. HEX() returns your salt in uppercase so you can just omit the LOWER() call if your salt was originally uppercase before you stored it using UNHEX().

    0 讨论(0)
  • 2021-01-25 02:51

    Make sure you unicode 'utf-8' settings match what your MySQL Server is expecting.

    In other words, don't set the charset as 'utf-8' in your application.ini file if your server is not configured for that ( as is the default ). A...

    SET NAMES 'utf8'
    

    is sent to MySQL from ZF which causes the error.

    Removing the 'utf-8' charset in the application.ini solved this for me.

    0 讨论(0)
  • 2021-01-25 02:51

    I had the same error and found it to be misleading. In my case, it turned out that I was connect to the wrong database for reasons not worth explaining. What you want to do is get the previous exception that caused Zend_Auth_Adapter_DbTable to throw the exception you mentioned. Below is how I accomplished this:

        $adapter = $this->_getAuthAdapter();
        $adapter->setIdentity($values['username']);
        $adapter->setCredential($values['password']);
    
        $auth = \Zend_Auth::getInstance();
        try {
            $result = $auth->authenticate($adapter);
    
        } catch (\Zend_Auth_Adapter_Exception $ex) {
            die($ex->getPrevious()->getMessage());
        }
    

    So in the end, the answer isn't exactly:

        SET NAMES 'utf8'
    

    It could really be any number of issues. Best bet is to let MySQL tell you by getting the previous exception. Maybe the answer will be related to character encoding. In my case it wasn't.

    0 讨论(0)
提交回复
热议问题