DB connection Yii Framework [duplicate] - mysql

This question already has answers here:
Database connection error in Yii
(2 answers)
Closed 9 years ago.
I've got a new domain & hosting but I can't connect to the new db.
What I tried:
'db'=>array(
'connectionString' => 'mysql:host=ascodcurro.com.mysql;dbname=ascodcurro_com',
'emulatePrepare' => true,
'username' => 'ascodcurro_com',
'password' => 'xxxx',
'charset' => 'utf8',
),
If I try localhost as always it works fine.
User info from host:
MySQL
server: ascodcurro.com.mysql
DB: ascodcurro_com
user: ascodcurro_com
pw: *****
PhpMyAdmin
PhpMyAdmin: https://dbadmin.one.com/
user: ascodcurro_com
pw: ******

During the initial startup and working with Yii, the first problem that I faced was connecting to the database.
I was getting a really weird error and I was not able to connect to my DB on my Mac OSX Mountain Lion on my XAMPP stack. After countless searches, I finally figured out a method that worked. This is the only way I am able to connect to my DB for Yii.
First check if you can connect to the database normally using the
default configuration by uncommenting the 'db' configuration in the
main.php file. Example :
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=ascodcurro_com',
'emulatePrepare' => true,
'username' => 'username',
'password' => 'pass',
'charset' => 'utf8',
'tablePrefix'=>'',
'enableProfiling'=>true,
'enableParamLogging'=>true,
),
However, if you are still not able to connect to the database even after this, as I wasn't able to connect to mine, try taking this approach :
Make a new php file and type :
<?php phpinfo() ?>
check that page out, find out where 'mysql' is located and find out the 'MYSQL_SOCKET' in it and note the location.
After noting the location down, try this as your 'db' connection string(for example, for me the location is "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock") :
'connectionString' => 'mysql:unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock;dbname=practice',
And the rest as the basic parameters that you use.
And then try connecting again.
Hopefully, that should connect you to your DB.
Regards,

'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=basename',
'emulatePrepare' => true,
'username' => 'username',
'password' => 'pass',
'charset' => 'utf8',
'tablePrefix'=>'',
'enableProfiling'=>true,
'enableParamLogging'=>true,
),
its my config. You get any errors?

Related

cakephp version 4 fresh install database not connecting

'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'root',
'password' => '000000',
'database' => 'cakephp',
'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'cacheMetadata' => true,
my database in phpmyadmin in xampp is ok.
But stil the cakephp homepage says
CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'my_app'#'localhost' (using password: YES)
I recently faced this issue and solved it by adding database configuration in config/app_local.php
As per Cakephp documentation:
The application skeleton features a config/app.php file which should
contain configuration that doesn’t vary across the various
environments your application is deployed in.
The config/app_local.php
file should contain the configuration data that varies between
environments and should be managed by configuration management, or
your deployment tooling
Reference:
CAKEPHP -> Configuration -> Configuring your Application

CDbConnection failed to open the DB connection Yii after moving to aws

I am new into yii. I was transferring a premade yii website to my aws server. After adding the updated database info into protected/config/main.php I am getting this error. None of the references worked. Please help.
Site Url : http://multilingualbabies.com
Possible Issue:
1) PDO driver maybe its not enabled
2) your dsn connection not truth, make sure your configuration somthing like this:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=dbName',
'username' => 'root',
'password' => 'yourPAssword',
'charset' => 'utf8',
];
Note: make sure mysql: is set in dsn.
3) make sure your mysql port is 3306, if other one try to change dsn by adding port like this 'dsn' => 'mysql:host=localhost;port=portNumber;dbname=dbName',.
Good Luck

Unable to connect to localhost database

This question has already been asked multiple times but none of the answers have helped me.
I am upgrading to Drupal 8 and to do so, I need to specify the login credentials for my Drupal 7 database.
SQLSTATE[HY000] [2002] No connection could be made because the target
machine actively refused it.
I can access the database perfectly fine to my SQL server is 100% running.
I have checked the credentials inside settings.php and it says the following:
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'karma-living.dev',
'username' => 'root',
'password' => '',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
So I copied above but I still get the error message above (yellow box).
See following image:
Does anyone have any suggestions? Thank you in advance.
The Acquia Desktop says your database name is "karma_dev", but you've entered "karma-living.dev" as the name for Drupal, so there is an inconsistency.

Laravel; "SQLSTATE[HY000] [2002] Connection refused"

I set up homestead 2.0 on OSX host and using Sequel Pro.
I can do migration and confirm that data are migrated in Sequel Pro, so it looks like no problem about DB connection.
But once I try to fetch data from Laravel 4.2 app, it fails to retrieve data and get following error.
PDOException (2002)
SQLSTATE[HY000] [2002] Connection refused
Here is my mysql configuration.
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '33060',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
Sequel pro setting is same above,
Name: 127.0.0.1
Host: 127.0.0.1
Username: homestead
Password: secret
Database:
Port: 33060
I tried change host name to 'localhost', homestead destroy and up, but No work.
Why?? Any suggestion helps.
I had exactly the same issue and I'm not sure why this happens.
However changing
'host' => '127.0.0.1',
to
'host' => 'localhost',
worked for me. Always simpler than what we expect!
For other devs there who are running Laravel on it's latest version (5.3) I just change these lines:
DB_HOST=127.0.0.1
DB_PORT=3306
Into this:
DB_HOST=localhost
DB_PORT=33060
Obviously, 33060 will be converted into 3306 but can't explain by now why localhost should work.
I solved the problem substituting the address 127.0.1.1 to localhost on the host parameter in the Laravel's .env file. I am working over GNU/Linux Debian 8, Laravel 5.6.3, PHP 7.1.8, Apache 2.4.27 and (Mysql) 10.1.26-MariaDB.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
Try this out it might work for you
I encountered the same problem for some reason neither of the above worked. For me I tried this in .env I changed DB_HOST to homestead.local. Homstead being the name of my site. This worked.
DB_HOST=homestead.local
I solved the problem by updating mariadb. I've checked what was outdated with 'brew outdated', then updated mariadb with 'brew upgrade mariadb' reload vagrant and issue was fixed. Hope this works for you.
Check your .env file for MYSQL_SSL=true.
We use SSL for MySQL in production not on dev after commenting the #MYSQL_SSL=true migration ran successfully.

CakePHP 2.1 doesn't work on localhost

I deployed my app on a remote host and everything works as expected. But when I try to test my code on localhost, it gives me the following error, without any change to the code working on the host:
Fatal error: Class 'AppHelper' not found in [path]
I am using CakePHP 2.1 and MySQL as my default datasource.
I connect to my local database just like to the remote one (with authentication changes):
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'database',
'prefix' => '',
'encoding' => 'utf8',
);
Why isn't this working on my localhost? Thank you
Two possible things:
either you didnt know about the AppHelper requirement for 2.1:
http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html
or you forget to declare the helper at the very top of your class:
App::uses('AppHelper', 'View/Helper');
Although the second one is highly unlikely if you are not running any unit tests.
So my bet is on the first one.