That is my local.php config:
'db' => array(
'driver' => 'pdo_mysql',
'dns' => 'mysql:dbname=xxxx;host=localhost;',
'username' => 'xxxx',
'password' => 'xxxx',
'port' => 3306,
'charset' => 'UTF8',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
)
)
And that is my authentication code:
$authAdapter = new AuthAdapter($sm->get('Zend\Db\Adapter\Adapter'));
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setCredentialTreatment("SHA2(CONCAT({$salt}, ?, salt), '512') AND active = 1");
$authAdapter->setIdentity($formData['username'])
->setCredential($formData['username']);
But when I try to submit login form, zend framework throw this errors:
File: /var/www/app/vendor/zendframework/zend-authentication/src/Adapter/DbTable/AbstractAdapter.php:331
Message: The supplied parameters to DbTable failed to produce a valid sql statement, please check table and column names for validity.File: /var/www/html/bookingSystemRewrite/vendor/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php:244
Message:Statement could not be executed (3D000 - 1046 - No database selected)File:/var/www/html/bookingSystemRewrite/vendor/zendframework/zend-db/src/Adapter/Driver/Pdo/Statement.php:239
Message:SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
When I debug Pdo Driver Adapter I found where is my problem.
The first problem was in that order:
'dns' => 'mysql:dbname=xxxx;host=localhost;'
it must be so :
'dsn' => 'mysql:dbname=xxxx;host=localhost;'
And the second problem was in that order:
->setCredentialTreatment("SHA2(CONCAT({$salt}, ?, salt), '512') AND active = 1");
it must be so:
->setCredentialTreatment("SHA2(CONCAT('{$salt}', ?, salt), '512') AND active = 1");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.