laravel4 migration failed (pdo exception) - php

I just used artisan migrate to create some table, but I get an error of Type PDO:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
A php/mysql testscript could connect to the database just fine, but it was another virtualhost and it did not use PDO.
In Laravel4 edited app/config/local/database.php to set the password and database name.
edit in start.php
UPDATE
I hardcoded the password in the PDO connection array and now terminal says there is no database named "database". Clearly it is looking somewhere else for the config, but I have no other config file.
(Due to following a tutorial about making a "local" directory it was not working for me)As it stands, I have downloaded the stable version and everything is working great.
I am going to delete this post, to keep the forum clean.

Make sure you have set up your database connection correctly in app/config/database
Laravel Database Docs

Make sure you are setting up a 'local' environment in start.php
Otherwise Laravel will look for DB config in app/config/database.php

Kindly Check Your app/config/database.php file in local host.
1.)Make Sure local Host Data Base name is Correct
2.)Make sure local Host Data Base username is correct.
3.)Make sure local Host Data Base password is correct.

Related

Accessing a remote database is giving an error on Laravel

I'm trying to access a database (which exists on a different server) on my Laravel application. I keep getting the following error: SQLSTATE[HY000] [2002] Permission denied
My .env file is set up as follows (changed a bit to protect privacy):
DB_CONNECTION=mysql
DB_HOST= IP_ADDRESS
DB_PORT=3306
DB_DATABASE=DB_NAME
DB_USERNAME="laravel_user"
DB_PASSWORD="password"
I'm not sure if this is important or not but I can access the web server's database if I go to the link IP.ADDRESS/phpmyadmin
My web.php file is as follows:
Route::get('/test', function(){
return DB::select("select * from umts_list");
});
Additionally, I also went to IP_ADDRESS/phpmyadmin (where my database exists) and added a new user called laravel_user with the ability to SELECT all data and saved it with the 'password' as its password.
My attempt: I tried whatever I mentioned above and also cleared the cache since I made changes to the .env file by entering the following commands:
php artisan config: clear
php artisan cache: clear
Any help would be appreciated. Thank you.
Edit 1: On phpMyAdmin, I made sure to add the user as depicted by the following picture:
PhpMyAdmin User Account
Additionally, I also checked the port number on phpMyadmin and it is 3306 as depicted by the following image:
Port Number
just in case anyone else stumbles upon this post in the future, it turns out that I did not have to create an SSH tunnel or whitelist the IP. The problem was actually with SELinux. This post was the solution: Laravel permission denied on remote Mysql server (AWS aurora)
Specifically, I ran the command: sudo setsebool -P httpd_can_network_connect_db=1
This worked perfectly and it was actually blocking connection to remote databases.

MySQL+Laravel: SQLSTATE[HY000] [1045] Access denied for user 'so'#'localhost' but connection data is OK and config cache is cleared

I need help here, because it's driving me crazy. I'm trying to connect to the remote production DB but I'm unable. I have read tons of posts about this that are focusing on the credentials and also running the following commands to clean config that are stored in Laravel cache:
php artisan cache:clear
php artisan config:cache
php artisan config:clear
Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Any of these are working for me.
I have checked very well the credentials both in my .env file and my database.php. I'm able to connect to a local database by using the ip "127.0.0.1" but I'm unable with the production DB stored in Google Cloud. It's good to mention that my local IP is allowed to access that Database and I'm able to connect by using MySql Workbench.
Here is what I see when I perform "php artisan tinker" and then "DB::connection()->getPdo();" to check my connection from terminal:
The only thing that calls my attention is the message containing "so#localhost" when I'm not performing a connection to localhost but I don't know if that's related with the issue.
Any other suggestion? I have lost too much time trying to find out what could be happening.
EDIT 1: Laravel Framework 5.8.38
After two days fighting with this one, I readed tons of posts and a lot of unuseful solutions I have found my solution by looking at this video.
Basically, you must stop you XAMPP MySQL Server and open C:\xampp\mysql\bin\my.ini and edit by adding the following command "skip-grant-tables" after the [mysqld] attribute. The result in this file might look this way:
# The MySQL server
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
socket="C:/xampp/mysql/mysql.sock"
...
After that, I ran "php artisan tinker" and DB::connection()->getPdo(); and everything was connected again, but it's good if you first clean your cache and config.

Upload Local Laravel Project to Server

I've created a Laravel 5.3 project on my local apache server(XAMPP) and it works fine with login and registration.
However, when I upload(via FTP) to my server(the server is 000webhosting) and try to do login it returns an error saying:
PDOException in Connector.php line 119:
SQLSTATE[HY000] [2002] Connection refused
I've already changed the .env to match the server DB's info, and just in case I also changed the config/database.php to also match. But it still appears like that?
Do you know exactly everything I have to change in my project so it can work on the server?
May be Your database password changed in live. update .env file

Sylius Database Credentials Not Updating

I'm new to Sylius, and am configuring a site for the first time on MAMP Pro. I've installed Sylius via Composer, but realized that the database credentials I provided during install were not correct. After this, I went into app/config/parameters.yml as per the documentation, and updated the following credentials:
database_driver: pdo_mysql
database_host: localhost
database_port: null
database_name: mydb
database_user: root
database_password: root
What's happening is every time I try to access the site, it throws a 500 error. Upon checking my log, each time I try to access it, I get an error about access being denied to the DB:
[15-Aug-2016 13:49:34 America/New_York] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) in vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
The strange thing is the error log also shows this:
vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php(41): Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=127....', 'root', 'secret', Array)
These are the old credentials (notice the password 'secret' instead of 'root', and the host '127.0.0.1' instead of 'localhost'. It appears that despite updating my parameters.yml with the correct credentials, Sylius won't stop trying to connect with the original credentials I used during setup. Is there another file that this could be stored in that's not mentioned in the documentation? Could it be caching the old credentials, and in need of some clearing? I'm at a loss for what's happening here.
EDIT:
I've also tried updating app/config/parameters.yml.dist with the proper credentials, to no effect.
EDIT 2:
I've done an entire search of the project for the name of my old database, and have updated each instance to the new database name. There are no files that reference the old DB name. Then I try and run:
php app/console cache:clear --env=dev --no-debug
and it throws errors:
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[08006] [7] FATAL: database "old_database_name" does not exist
despite old_database_name not being referenced in any file. Then if I do a search for old_database_name AFTER running the cache clear, it overwrites my new database name in app/cache/de_/ap_DevProjectContainer.php with the old name again, every time. I can't even figure out where it's getting the old database name from, after I overwrite every instance of it. What's happening here??
The default Sylius configuration uses a different database for production and development. In your case, this would be sylius from prod and for the dev environment _dev is appended to the datbase name. This is expected behavior and not a bug.
You can find the configuration at the end of app/config/config_dev.yml. If you remove the following lines, both environments use the same database.
doctrine:
dbal:
dbname: %sylius.database.name%_dev
https://github.com/Sylius/Sylius/issues/2362
In this case, old_database_name was the same as my new database name, only it contained the suffix '_dev'. I've now realized that this is because I'm in the dev environment. There doesn't seem to be any easy way I've found to remove this suffix, so I'm just going to roll with it. Would still like an answer on how to remove this, but for now I've answered my own question.

Laravel 5.1 migrate database to hosted mysql

How would I go about doing this (the title is the question), I've changed all my ENV files to my hosted mysql details. When i run php artisan migrate from composer I get the
"denied username#localhost using password yes error".
I've changed the port and everything but I'm not sure what to do anymore and I'm 99% sure that the details are correct I've tried them multiple times
You need check somethings:
are credentials valid (username, password and host)?
the database host is accessible by your application server?
.env file is correctly configured or have some config hard coded in app/config/database.php?
To validade connection, you can try this: http://www.w3schools.com/php/php_mysql_connect.asp
About configuration and enviroments : https://laravel.com/docs/5.2/configuration

Categories