I am following along a youtube tutorial for yii2 and have created a database named yii2crashcoursenew and a table named user with the properties id, username, password, auth_key, access_token and primary key id. I have added one row to the table with the values admin, admin, key1, token1. The code in the config -> db is:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2crashcoursenew',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8'
]
When I type admin, admin in the loginform I get the following error
Database Exception – yii\db\Exception
SQLSTATE[HY000] [2002] No such file or directory
↵
Caused by: PDOException
SQLSTATE[HY000] [2002] No such file or directory
in /Users/webdevelopment/basic/vendor/yiisoft/yii2/db/Connection.php at line 705
Can someone tell me what is wrong and how to solve the issue? Thankyou.
Related
I need a little help connecting an external MySQL database to Laravel Vapor. The database is located on a Hetzner Server and it seems like there is a failure using a tls encrypted connection:
==> Executing Function...
Status Code: 1
Output:
In Connection.php line 712:
SQLSTATE[HY000] [2002] (SQL: SELECT * FROM KURSE_planung )
In Exception.php line 18:
SQLSTATE[HY000] [2002]
In PDOConnection.php line 40:
SQLSTATE[HY000] [2002]
In PDOConnection.php line 40:
PDO::__construct(): SSL operation failed with code 1. OpenSSL Error message
s:
error:1416F086:SSL routines:tls_process_server_certificate:certificate veri
fy failed
I already tried to disable SSL by using the following params in the database URL without any luck:
MYSQL_DATABASE_URL=mysql://username:password#sql168.your-server.de/databasename?charset=utf8mb4&sslmode=disabled&ssl-mode=disabled&useSSL=false
Does anyone know how to disable TLS when connecting to the database or what else I can do about it?
Edit:
I managed to connect to the database. My Hoster Hetzner provides a certificate which needs to be provided to the connection configuration in database.php:
'mysql' => [
'driver' => 'mysql',
'url' => env('MYSQL_DATABASE_URL'),
'host' => env('MYSQL_DB_HOST', '127.0.0.1'),
'port' => env('MYSQL_DB_PORT', '3306'),
'database' => env('MYSQL_DB_DATABASE', 'forge'),
'username' => env('MYSQL_DB_USERNAME', 'forge'),
'password' => env('MYSQL_DB_PASSWORD', ''),
'unix_socket' => env('MYSQL_DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => base_path(env('MYSQL_ATTR_SSL_CA')),
]) : [],
],
Then in the .env file one needs to set the correct path to the certificate using MYSQL_ATTR_SSL_CA.
One question remains: does anyone know how to disable SSL for MySQL on Vapor?
Best regards
Clemens
I don't know if this might help. But In my case Laravel Vapor was hosted with RedHatOS, then I defined the env with the following:
MYSQL_ATTR_SSL_CA=/etc/pki/tls/certs/ca-bundle.crt
In my case, the database is hosted on planetscale this configration a specified on the documentation
'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
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.
I am trying to setup my database config as demonstrated here: http://kowsercse.com/2011/09/04/kohana-tutorial-beginners/
I have cut and pasted the database.php with my mysql credentials. I then get an error which I fixed by renaming the file to Database.php. the next issue is that my credentials don't change no matter what I put in.
The error shows:
Database_Exception [ 2 ]: mysql_connect() [function.mysql-connect]: Access denied for user 'ivanh'#'localhost' (using password: NO)
MODPATH/database/classes/Kohana/Database/MySQL.php [ 67 ]
62 catch (Exception $e)
63 {
64 // No connection exists
65 $this->_connection = NULL;
66
67 throw new Database_Exception(':error',
68 array(':error' => $e->getMessage()),
69 $e->getCode());
70 }
71
72 // \xFF is a better delimiter, but the PHP driver uses underscore
So no matter what I insert, username, host and password values do not change.
My code in Database.php is then copied from: http://kohanaframework.org/3.3/guide/database/config
firstly with my own database values then after as is. With no luck.
Other info: I'm creating this on a shared unix host.
Kohana 3.1.4: Database_Exception [ 2 ]: mysql_connect(): Access denied seems like a similar issue without a resolution.
Any help would be great, thanks.
Try These Steps:
Step 1:
Go to bootstrap.php
path- kohana\application\bootstrap.php
Un-comment the below line for database access
'database' => MODPATH.'database', // Database access
Step 2:
Go to Your config folder,
create the database.php file if not created, with below codes by giving your MySql credential
Path: kohana\application\config\database.php
Notes: First create a database in your Mysql
If the problem is not solved check your MySql settings too..there may be a error
<?php defined('SYSPATH') OR die('No direct access allowed.');
return array
(
'default' =>
array
(
'type' => 'MySQL',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
* array variables system variables as "key => value" pairs
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => 'localhost',
'database' => 'CHANGE YOUR DATABASE NAME HERE',
'username' => 'CHANGE YOUR USER NAME HERE',
'password' => 'CHANGE YOUR PASSWORD HERE',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
),
'remote' => array(
'type' => 'MySQL',
'connection' => array(
/**
* The following options are available for PDO:
*
* string dsn Data Source Name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*/
'dsn' => 'mysql:host=localhost;dbname=CHANGE YOUR DATABASE NAME HERE',
'username' => 'CHANGE YOUR USER NAME HERE',
'password' => 'CHANGE YOUR PASSWORD HERE',
'persistent' => FALSE,
),
/**
* The following extra options are available for PDO:
*
* string identifier set the escaping identifier
*/
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
),
);
I am going to make the following assumptions:
You are consequently writing "Database.php" because the file in APPPATH/config containing the code you copied does indeed start with a capital letter.
You haven't changed the config reader.
Database::instance() will request a config array from the Kohana::$config if none is supplied. Config_File::load() will then loop through all found /config/database.php's found in APPPATH, enabled modules and SYSPATH.
Unix filesystems are case sensitive, notice the lowercase 'd' Kohana is looking for versus your uppercase 'D'.
If you did name it 'database.php' and not 'Database.php', click on 'Environment' and then 'Included files' on the error page and make sure it is included. If it's not, do some backtracking and try to find out when things stop behaving as they should, followed by why.
Edit: I don't know how I missed the "renamed it to Database.php" part, but that did not fix anything.
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?