I'm working on a project (PHP Laravel 4.2) using SVN with team, After I checked out the repository on my disk (local), and tried to open the link localhost/mylaravel, I got this error
PDOException (1045) SQLSTATE[HY000] [1045] Access denied for user
'dbusername'#'xx.xxx.xx.xxx' (using password: YES)
Note: I changed the real username and host IP
the database not locally, It's remotely hosted online. but the project is on localhost.
config/database.php
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
/**
* remote database connection
*/
'mysql' => array(
'driver' => 'mysql',
'host' => 'hostIP:port',
'database' => 'mydatabasename',
'username' => 'mydbusername',
'password' => 'root123456',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),
)
Just run the following artisan commands in your terminal.
1. php artisan cache:clear
2. php artisan config:cache
Refresh your url now and the login will works perfectly.
$ php artisan cache:clear
Application cache cleared!
$ php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!
Run php artisan cache:clear then php artisan config:cache on your terminal in the respective path.
The above should be the results
I Faced Same Problem i did
php artisan cache:clear
php artisan config:cache
but Same problem found than i run this artisan command
php artisan view:clear
Hope it will helpful.
Note: my project was Laravel 5.*
Just only change .env file and DON'T change config/database.php file. Please make config/database.php file as default.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1 or IP address
DB_PORT=3306
DB_DATABASE='your database name'
DB_USERNAME='your username'
DB_PASSWORD='your password'
it works for me!
Please run the command line:
php artisan optimize
Related
I am trying to connect django.db.backends.postgresql with my lumen application. But when I run the query then following error occured
could not find driver
Even I change the driver type from mysql to pgsql
My database connection
'ml_db' => [
'driver' => 'django.db.backends.postgresql',
'host' => env('ML_DB_HOST'),
'port' => env('ML_DB_PORT'),
'database' => env('ML_DB_NAME'),
'username' => env('ML_DB_USER'),
'password' => env('ML_DB_PASS'),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_general_ci'),
'prefix' => '',
'timezone' => env('DB_TIMEZONE', '+00:00'),
'strict' => false,
],
Is there any way to connect this database with my lumen application because I am using multiple databases in application.
The obvious answer here is, that you haven't installed the corresponding driver for your used dbms. So just install it.
from your configuration posted in the question, I assume that it's your lumen configuration. There is no 'django.db.backends.postgresql' driver in lumen. What we have is pgsql driver unless you create such a custom driver yourself,(which I assume is not the case).
so change the driver parameter to the following?
'driver' => 'pgsql',
Lumen .env file:
DB_CONNECTION=pgsql
DB_HOST=your host
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=username
DB_PASSWORD=password
The link
I am getting this error while trying to save an object into DB.
SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: insert into cards (card_price, active, updated_at, created_at) values (0, 1, 2019-10-10 15:14:43, 2019-10-10 15:14:43))
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cardgame
DB_USERNAME=root
DB_PASSWORD=P#assword1!
Database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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_T_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'),
]) : [],
],
CardController.php
public function generateCards()
{
$card = new Card();
$card->card_price = 0;
$card->active = 1;
$card->save();
}
Web.php
Route::get('/generate-cards', 'CardController#generateCards');
Card.php
class Card extends Model
{
protected $guarded =[];
}
Migration file
public function up()
{
Schema::create('cards', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('card_price');
$table->integer('active');
$table->timestamps();
});
}
I've tried clearing cache and also have edited DB_PASSWORD To DB_T_PASSWORD as this corrected a similar issue earlier. Double checked the DB name, passwords etc & also other projects are already running also. I'm not able to figure it out.
Go to your localhost server and drop the database and recreate a new one named cardgame
Go to your laravel project in console and run php artisan config:cache command. That way all your env variables will be used.
Run php artisan:migrate to run your migrations for your database and create your tables.
If you do the above 3 steps in that order you should be fine.
You must clear the cache because your old configuration is in the cache file, just run this command in your terminal for clear cache:
php artisan config:cache
You can solve this problem by 2 simple step.
Step:1 php artisan config:cache
step:2 php artisan migrate
I had the same problem and I solved it following these steps:
1) Stop the server
2) Run php artisan config:clear .This command line will remove
bootstrap\cache\config.php file
3) Start the server and It should work fine now
create database in php admin then migrate your database again
php artisan migrate , it's work 100%
I was also experiencing the same error and implimented all the solutions mentioned above but the error kept reoccuring. But I edited the.env and env.example file where the database = "laravel" to the name of my project for instance transportsytem and it worked.The best solution to the problem is editing both .env and env.example files with the name of your database that you created .
I don't know why when I run a PHPUnit test, I get the following error:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
My testing environment database setting is:
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'clg_test',
'username' => 'root',
'password' => 'veryHardPass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]
],
'migrations' => 'migrations',
];
The reason why I am using MySQL as oppose to SQLite is because my migration files use dropColumn which is not supported by SQLite. I call the migration via Artisan::call('migrate') in the setup.
If I actually call migration manually in the terminal via php artisan migrate --env=testing then the migration IS successful and the databases are created.
Why am I then facing the above problem?
Try changing localhost to 127.0.0.1. The message you're getting is indicative of the script not being able to connect to MySQL through a socket, but using an ip should work.
My website works, its clearly accessing the database. I can log in and i can create records, etc...
Ive created a new migration, and I'm trying to insert it, but when i run
php artisan migrate
i get the error
[PDOException]
SQLSTATE[HY000] [2002] Connection Refused
My database config has the passwords hidden in the environment so my config looks like this
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOSTNAME'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
my environment variables are loading correctly. What am i missing?
I figured it out. Apparently the environment that artisan was seeing was different from the environment i wanted it to see, so it was using the wrong host
php artisan migrate --env=production
I am trying to set up migrations for the first time and when I run
php artisan migrate:install
from within the root folder of my project I get the following SQLSTATE error:
SQLSTATE[HY000] [2002] No such file or directory
I have tested running mysql to make sure it is working and referenced and I have ran php artisan help:commands to make sure artisan is working (it is).
The website itself is functioning and reading from the database fine.
This may be an issue with the sockets if you're using MAMP or XAMPP.
From http://forums.laravel.io/viewtopic.php?id=980...
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
'prefix' => '',
),
),
You can pass an optional "unix_socket" to the array and specify the MAMP socket instead of the default location.
Also, try and change 'host' => 'localhost', to 'host'=> '127.0.0.1', because unix does not recognise 'localhost'