I've been fighting this for a few hours now, but don't seem to be able to solve it.
I have a stored procedure that I want to run once a day, and I'd prefer to run it from an Artisan command, although I could run it from the MySQL scheduler, or just the cron tab also.
BUT... I'd prefer to run it from an Artisan command if possible. I can run this command from anywhere else in my Laravel app, and it runs successfully \DB::statement(DB::raw('CALL recalc_user_points')); AND the stored procedure does what it needs to do, and creates a record in a table so I know when it was run.
However, when I put the same code into an Artisan command it never executes, and I'm assuming it's because I don't actually have a DB object, although I don't see any errors...
My fire() procedure looks like this:
$this->info('Calling Stored Procedure recalc_user_points'); \DB::statement(DB::raw('CALL recalc_user_points')); $this->info('Finished Stored Procedure recalc_user_points');
I get the "Calling Stored Procedure recalc_user_points" message, and then an error message saying the "connection attempt failed"
So... what is the correct way to get my default mysql connection, and then run the statements above?
I've tried injecting the DB, adding use Illuminate\Database\DatabaseManager as DB; $db = \DB::connection('mysql'); $db->connect();and about 15 other ways to try to establish a database connection with no success.
I'm sure it's easy, but either I've got typos, or I'm just missing something.
Anyone care to save what little hair I have left?
FYI... why is there no Artisan category or Tags?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community