1

I am trying to connect the database with my Laravel 7 application but each time when I hit php artisan migrate I am getting the following errors.

I have connected my .env file as below:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=""

Illuminate\Database\QueryException

  could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +32 vendor frames 
  33  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

I have tried several ways including uncommenting an extension in the php.ini file but nothing changed!

Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38

1 Answers1

1

Are you on Linux? If yes you'll have to install the php-mysql package if you're on Ubuntu and php-mysqlnd package if you're on Fedora.

On Windows and macOS all these stuff come built into WAMP or MAMP or whatever one uses.

fhsinchy
  • 154
  • 5
  • Yes i am using ubuntu. Can you share the command to install php-mysql ? Thanks a lot – Shariful Sujon Jun 09 '21 at 06:20
  • When I hit `sudo apt-get install php-mysql`, it also shows an error. `The following packages have unmet dependencies: php-mysql : Depends: php7.0-mysql but it is not going to be installed E: Unable to correct problems, you have held broken packages.` – Shariful Sujon Jun 09 '21 at 06:24
  • Did you installed php from [Ondřej Surý](https://launchpad.net/~ondrej/+archive/ubuntu/php) repository? I would suggest you uninstall your currently installed php and reinstall by executing `sudo apt install php7.4-cli php7.4-json php7.4-xml php7.4-tokenizer php7.4-mysql php7.4-redis php7.4-bcmath php7.4-mbstring` command. This include almost all necessary dependencies for running a vanilla Laravel application. – fhsinchy Jun 09 '21 at 06:38
  • Also, if the broken package issue persists, try out the solutions in this [link](https://linuxhint.com/apt_get_fix_missing_broken_packages/). – fhsinchy Jun 09 '21 at 06:39
  • Thanks a lot for your help mate. I have tried all the things but still I couldn't solve the issue. I am sure something is wrong with my php or mysql. – Shariful Sujon Jun 09 '21 at 14:00