why my laravel project connected with old database - laravel

My laravel project keeps connecting with the old database. I already changed .env's database name but still, my project connects with the old database. I have no idea why is this happening.
I ran all these commands
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan route:clear
php artisan route:cache
also, restart my server, update my composer but nothing works...
This is the error shown in the terminal :
SQLSTATE[HY000] Unknown database 'users'
Here is my .env
DB_DATABASE=user_manager
DB_USERNAME=root
DB_PASSWORD=

There must be still issue with your ENV file. can you please take a double check in this? also please check that is there database exists in phpMyAdmin?
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=root
DB_PASSWORD=
in config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
'options' => [
\PDO::ATTR_PERSISTENT => true
]
],
for more info,
link to laravel official site

Error resolved.
The error was occurring because of the config.php file. My old database name is stored there. I deleted that config.php file and everything is working perfectly fine.

Your should stop your artisan serve(ctrl+c) and then reserve project
php artisan serve

Aren't you missing DB_HOST in your env File? Looks like you have the DB_HOST hardcoded to your database host or your php-fpm.conf.

I faced the same problem and solved by using the following command:
composer dump-autoload
PHP artisan config:cache
PHP artisan config:clear

Related

larvel 9 PDOException::("could not find driver") on Windows

I wanted to connect a MySQL database to my Laravel application.
I created one using PHPMyAdmin administration tool of MySQL, then I added it in the .env as whereas the database.php application files.
I ran the terminal command: php artisan migrate which gave me the following error:
could not find driver (SQL: select * from information_schema.tables where table_schema = pl_project and table_name = migrations and table_type = 'BASE TABLE')
at C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
1 C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
Here is the .env excerpt that I edited:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pl_project
DB_USERNAME=root
DB_PASSWORD=
Here is the database.php excerpt that I edited:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'pl_project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('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 => env('MYSQL_ATTR_SSL_CA'),
]) : [],
]
Here is the output of the command: php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
A couple of notes:
I did add PHP to my env variables as well as MySQL.
I did uncomment extension=pdo_mysql in php.ini.
But none of it changed anything and I still get the same error.
There is no need in editing database.php file as it is using .env for database info. In case this is new project that did not have .env file, try running php artisan config:clear
Have you tried restarting PC after enabling extension? If you are running your project with artisan serve it will not reflect after you change ini file
I also had few similar issues on couple of machines with database, it got solved with commenting 'url' => env('DATABASE_URL'), line in mysql
Hope some of this helps
Comment:
I checked all the php.ini files there were 2 so I edited the second
one. restarted the server then tried to migrate again only to get the
same error.. – OP - https://stackoverflow.com/posts/comments/131493101?noredirect=1
From what I can recall, the default XAMPP installation lucks a php.ini file in the path xampp/php/.
It however has php.ini-development and php.ini-production configuration files in that path. You would normally have to create a duplicate copy of either of those two files depending on your use case and rename the 'duplicate copy' to php.ini This renamed file would then be considered as the 'active/default PHP configuration file'.
You would then open this new renamed php.ini file, uncomment any necessary extension libraries, save and restart your XAMPP web server (Apache).
Addendum
You may need to enable/uncomment the extension libraries below for your case.
mysqli
pdo_mysql
pdo_sqlite
Addendum 2
A. Enable/uncomment the line below. Change the path to your XAMPP installation path. I.e:
extension_dir="C:\xampp\php\ext"

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required in Laravel with Mailtrap.io

I looked through the answers on SO but nothing seems to work. The weird thing is that I have the exact same .env variables and config/mail.php in another local project, and in that project everything works as expected.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=my_mailtrap_username
MAIL_PASSWORD= my_mailtrap_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=test#example.com
MAIL_FROM_NAME=Example
In config/mail.php I have
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
I know that MAIL_HOST has a different fallback vs the host that I have specified in my .env, but the second value is the fallback and it should just be using that from my .env file. Again, this works fine in an other local project.
I ran:
php artisan config:clear
php artisan config:cache
php artisan queue:restart
All the facepalm memes in the world can not describe how I feel right now.
I had all the MAIL variables in the .env file declared AGAIN further down in the file, so they got overwritten... I also still had my .env.example file but I don't think that caused the issue.

Laravel: queue:listen PDOException: could not find driver

OS Ubuntu.
Site working!
But if i run
queue:listen
I getting an error
PDOException: could not find driver
Configuration:
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
sync:
'sync' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
Firstly run in terminal:
php artisan queue:table
php artisan migrate
.env:
QUEUE_CONNECTION=database
Then run in terminal:
php artisan queue:work
But I strongly recommend using Supervisor.
You should also read the documentation: https://laravel.com/docs/5.8/queues

Redis Connection refuse [tcp://127.0.0.1:6379]

I just setup GeneaLabs/laravel-model-caching packages. When running serve i got redis class missing. Then i run
composer required predis/predis
After that
I got this error
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]
and i got this error. Still working but I have not made any progress yet.
Any idea?
PS: i am working localhost with mysql. Not homestead.
Install Redis.
https://redis.io/download or if the os is windows then https://github.com/MicrosoftArchive/redis/releases
Run Redis.
$ src/redis-server or in windows then run redis-server.exe
Set the .env variables
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Add redist code to database.php
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
install latest version of redis from This link is in GateHub
then go to the .env file and change the CACHE_DRIVER to redis
CACHE_DRIVER=redis
then go to the path config/database.php and change the REDIS_CLIENT from phpredis to predis
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
],
and clear config with this command : php artisan config:clear

Laravel Database connection not working as it should

I am currently setting up a Laravel installation and running through a tutorial to familiarize myself with this new framework.
I have managed to install composer and the Laravel base installation fine, but when i attempt to create a new database and seed it using artisan, nothing actually happens. Artisan tells me that is has seeded it fine but nothing seems to change in MYSQL.
My WAMP server is running on a local machine with Apache and PHPMyadmin and is setup correctly and has no issues (been using it for many projects before.)
Here are my database config settings:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'celebrity_v1',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I had to set the database up manually as even though the Artisan migrate command said it was working, it wouldn't actually create a new table, same with the seed.
My commands are as follows:
php artisan migrate:make create_comments_table --create=comments
php artisan migrate
And to seed:
php artisan db:seed
Can anyone see any problems with anything I am attempting to do here or suggest why I am having these issues? I don't have a lot of experience with Laravel.
Thanks
You should set the values in /app/config/local/database.php instead of app/config/database.php

Resources