SQLSTATE[HY000] [1045] Access denied for user - OVH Eloquent - eloquent

For a project I use Slim 3 - Twig and Eloquent. On development mode, all works perfectly, but on production, hosted in the OVH shared server, I can't access to the database.
I'm hundred percent sure of credentials and the database was not created right now.
This is my code :
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config['db']);
$capsule->bootEloquent();
$capsule->setAsGlobal();
Where $config['db'] contains the informations required by Eloquent :
$config = [
'settings' => [
'debug' => true,
'displayErrorDetails' => true
],
'db' => [
'driver' => 'mysql',
'host' => '****.mysql.db',
'database' => '****',
'username' => '****',
'password' => '****',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]
]
What I have to do to make it work ?

Ok ... I get the solution.
... Suspense ...
I have to remove spaces around the big arrows in my beautiful formatted array.
Yes. I'm gonna cry.

Related

Magento 2.3 settings in Admin are grayed out

I want to disable Magento Review module and modify the etc/config.php
'Magento_Review' => 0,
the review module did disable, but now a lot of the settings in admin interface are grayed out
How to restore changes and put it back to be able to edit settings in admin?
Any help is appreciated.
I found that it's a configuration issue in either config.php or env.php
For myself, I found that I had a configuration issue in my env.php whereby I had 2 areas referencing different databases:
'db' => [
'connection' => [
'indexer' => [
'host' => 'mysql',
'dbname' => 'my_db_2',
'username' => 'user',
'password' => 'pass',
'active' => '1',
'persistent' => NULL,
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;'
],
'default' => [
'host' => 'mysql',
'dbname' => 'my_db_1',
'username' => 'user',
'password' => 'pass',
'active' => '1',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;'
]
],
'table_prefix' => ''
],
Had my_db_1 in 1 and my_db_2 in the other. Upon matching these I ran:
php bin/magento app:config:import && \
php bin/magento setup:upgrade && \
php bin/magento cache:flush
And the configuration was no longer greyed out / disabled / unchangeable.

TYPO3 v9: how to query additional external database (MSSQL)

I am trying to query an additional external database connection in one of my repositories. In LocalConfiguration.php I've defined two connections (Default, External).
[...]
'DB' => [
'Connections' => [
// Local MySQL database
'Default' => [
// ...
],
// External MSSQL database
'External' => [
'charset' => 'utf-8',
'dbname' => 'DBNAME',
'driver' => 'sqlsrv',
'host' => 'someExternalIP',
'password' => 'somePassword',
'port' => 1433,
'user' => 'someUser',
],
],
],
[...]
In my repository I want to query the external database (via Doctrine).
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('dbo.SomeTable');
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder
->select('*')
->from('dbo.SomeTable');
Do I have to explicitly tell the QueryBuilder to use that particular connection? Right now I am getting an Doctrine\DBAL\Exception\ConnectionException error, as the system tries to connect via the Default-Connection.
An exception occurred while executing 'SELECT * FROM `dbo`.`SomeTable`':
SELECT command denied to user 'myLocalUser'#'localhost' for table 'SomeTable'
Check out $GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'] where you can explicitly define what tables are located in which database. See also this for some more details https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Database/Configuration/Index.html
The other option is actually to use ask the Connection by name, and create a query builder out of that.
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionByName('External')->createQueryBuilder(...)
I personally would go with the latter, as it is more explicit within the actual callers code what is used.
To work with external DB, you have to :
configure the mapping with external database and table mapping in LocalConfiguration.php
define the TCA for external tables in myExt/Configuration/TCA/MyExternalTableName.php
configure the external tables/columns mapping in ext_typoscript_setup.txt
and then, the queries in repositories will work.
Sample LocalConfiguration.php :
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8',
'dbname' => 'LOCAL-DB',
'driver' => 'mysqli',
'host' => '127.0.0.1',
'password' => 'PWD',
'port' => 3306,
'user' => 'USER',
],
'externalDb' => [
'charset' => 'utf8',
'dbname' => 'EXTERNAL-DB',
'driver' => 'mysqli',
'host' => 'localhost',
'password' => 'PWD',
'port' => 3306,
'user' => 'USER',
],
],
'TableMapping' => [
'MyexternalTable1' => 'externalDb',
'MyexternalTable2' => 'externalDb',
...
]
]
Sample columns mapping in myExt/ext_typoscript_setup.txt :
plugin.tx_myext {
persistence {
classes {
Vendor\MyExt\Domain\Model\LocalModel {
mapping {
tableName = ExternalTableName
recordType = \Vendor\MyExt\Domain\Model\LocalModel
columns {
col1.mapOnProperty = uid
col2.mapOnProperty = name
...
}
}
}
}
}
}

URL-Manager will not route

I cloned our repositorie and created excatly the same URL-rules like at my own project. Now, i will get error like this after having logged in:
Firefox:
Fehler: Umleitungsfehler
The website called is rerouting request,which never will come to an end.
This problem sometimes occures, if cookies are deactivated
Chrome:
ERR_TOO_MANY_REDIRECTS
I definetly accepted using cookies at both browser!!
Debugging shows me,that I have dozen of 302-Requests,so Yii breaks down!
I use Windows, not LINUX, so I don't care about any permissions.
Here are the rules:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => true,
'rules' => [
'/' => 'site/login',
'home' => 'site/index',
'logout' => 'site/logout',
'contact' => 'site/contact',
'signup' => 'site/signup',
'reset' => 'site/request-password-reset',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<action:(contact|captcha)>' => 'site/<action>'
],
Here is frontend configuration:
<?php
$config = [
// LZA 17-07-30
'sourceLanguage' => 'de-DE',
'language' => 'de-DE',
// LZA 17-07-30 siehe Funktionen in http://demos.krajee.com/grid#module
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '4lD2RxDNkC4ckpwxTmkDzOLIvk0JMs3F',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// LZA 17-07-30 CRUD
'generators' => [// customized CRUD generator
'crud' => [
// 'class' => 'app\myCrud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
'class' => '\common\wsl_dev\wsl_crud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
'templates' => [
'myCrud' => '/#common/wsl_dev/wsl_crud/crud/default', //LZA 17-07-20 Templatename und Templatepfad
]
]
],
// LZA 17-07-30 CRUD
];
}
return $config;
If I deacitvate URLManger,setting
'enablePrettyUrl' => false,
everything works fine.
If I put in manually Url like this:
http://localhost/yii2_perswitch/frontend/web/yiic.php/home
everything works fine,too
Any ideas,how to fix this?
I deleted all my cookies,without any effects!
Solution 1:
Enable debug mode from web/index.php (uncomment these two lines):
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
and you can see exactly what causes the problem.
Redirected too many times error was because the 777 permissions for
runtime and assets folder were not set.
Solution 2:
I think that the problem is related with the path or domain of the cookie. I believe that this info could be useful.
https://github.com/samdark/yii2-cookbook/blob/master/book/cookies.md

Error "Class 'Swift_EmbeddedFile' not found" when i try send email with yii2 advanced

I tried build application with auto send mail.
Before I build in yii2 advanced, I tried in yii2 basic and my code work.
But when i tried in yii2 advanced, I got error
Class 'Swift_EmbeddedFile' not found
Can somebody help me?
And this is my code :
code in /common/config/main-local.php
return [
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'mysmtp',
'username' => 'myusername',
'password' => 'mypassword',
'port' => 'myport',
],
],
],];
And my code in MyController :
Yii::$app->mailer->compose('layouts/index.php', [
'imageFileName' => Yii::getAlias('#app/mail/layouts/images/logo.png'),
'facebook' => Yii::getAlias('#app/mail/layouts/images/facebook.png'),
'twitter' => Yii::getAlias('#app/mail/layouts/images/twitter.png'),
'pinterest' => Yii::getAlias('#app/mail/layouts/images/pinterest.png')
]) // a view rendering result becomes the message body here
->setFrom('from#email.com')
->setTo($model->email)
->setSubject('Message Test 3')
->send();
Note : I have Swiftmailer extention.
Thanks in advance for your help guys.

Lumen connecting to multiple databases using DB_ connections in .env - Possible?

I can see how to have multiple connections using a configuration file in app/config/database.php and this is well documented.
Is this the only way or can you also define multiple connections using the .env file?
First, you'll need to configure your connections. You need to create a config directory in your project and add the file config/database.php. Like this:
<?php
return [
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'homestead',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'mysql2' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'homestead2',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
],
Once you've added your connection configurations, you can access them by getting the database manager object out of the container and calling ->connection('connection_name'). See below for a full example.
<?php
namespace App\Http\Controllers;
use Illuminate\Database\DatabaseManager;
class StatsController extends Controller
{
/**
* #return array
*/
public function getLatest()
{
// Resolve dependencies out of container
/** #var DatabaseManager $db */
$db = app('db');
$database1 = $db->connection('mysql');
$database2 = $db->connection('mysql2');
// Look up 3 newest users and 3 newest blog posts
$threeNewestUsers = $database1->select("SELECT * FROM users ORDER BY created_at DESC LIMIT 3");
$threeLatestPosts = $database2->select("SELECT * FROM blog_posts ORDER BY created_at DESC LIMIT 3");
return [
"new_users" => $threeNewestUsers,
"new_posts" => $threeLatestPosts,
];
}
}
http://andyfleming.com/configuring-multiple-database-connections-in-lumen-without-facades/