phpmysqllaravellaravel-artisanliveserver

How to run CREATE DATABASE command on LIVE Laravel site through get request


Background:

I know this isn't ideal, but it's what I want to do. How can I make this command work please?

Method I added:

public function store()
{
    $datestr = date("Y_H_i_s");
    DB::statement("CREATE DATABASE xxxx_". $datestr);
    return redirect()->to('/setupfinished');
}

Edit: Here's the error message - so how do I enable permissions for this user?

[previous exception] [object] (PDOException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'xxxx'@'localhost' to database 'xxxx_2024_19_14_10' at /var/www/summer/vendor/laravel/framework/src/Illuminate/Database/Connection.php:580)
[stacktrace]

Treat me as if I know nothing about Laravel but I do know some PHP.

Thanks!


Solution

  • Thanks for help - I fixed with mysql command:

    grant all privileges on *.* to '<user>'@'localhost';