PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] Why password argument read as username in exec()

 September 15, 2022     exec, laravel, mysql, php, ubuntu     No comments   

Issue

I tried to seed using sql file using exec() function in Laravel Seeder, shown below:

exec("mysql -u ". env('DB_USERNAME') ." -p". env('DB_PASSWORD') ." ". env('DB_DATABASE') ." < " . database_path() . '/seeds/table.sql');

But when executed php artisan db:seed --class MySeeder, I got this output

ERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)

It was always like that, no matter password argument I used (-p and --password).

But in other side, using windows with this line of code below, it works well.

exec("C:/xampp/mysql/bin/mysql -u " . env('DB_USERNAME') . " --password=" . env('DB_PASSWORD') . " " . env('DB_DATABASE') . " < " . database_path() . '/seeds/table.sql');

The reason I did this is because the mysql file is huge, I cannot convert or type it manual to proper seeder each rows. Can someone help me? Should I use different methods? Thank you

Details:

  • Ubuntu subsystem on Windows 10
  • Ubuntu 18.04 on DigitalOcean
  • Laravel 7
  • PHP 7.3
  • MySQL (php7.3-mysql + mysql_server)

Solution

I'm so dumb, I found my solution by accident. I executed:

composer dumpautoload

php artisan config:clear

php artisan cache:clear

But I guess composer dumpautoload was the answer. And I don't know why. If someone have perfect reason why composer dumpautoload solved my problem, feel free to comment :)



Answered By - Wiguna R
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing