php artisan migrate erreur

Par Seokuymi, il y a 7 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Je suis un tutoriel pour une API sous Laravel.
J'utilise WAMP comme hébergeur localhost.
J'ai PHP 7.2.7 installé sur ma machine et 7.1.9 sous WAMP.
J'ai Laravel 5.6.
J'utilise le mysql de WAMP.
Ma base fmsp est créer.

Mon code est le suivant :

.env

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=fmsp DB_USERNAME=root DB_PASSWORD=

Ma migration :

<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->string('provider'); $table->string('provider_id'); $table->text('avatar'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('users'); } }

Ce que j'obtiens

Malheureusement j'ai cette erreur en exécutant 'php artisan migrate' :

Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = fmsp and table_name = migrations) at C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668|

Et si vous voulez les traces :

Exception trace: 1 PDOException::("could not find driver") C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:68 2 PDO::__construct("mysql:host=localhost;port=3306;dbname=fmsp", "root", "", []) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:68 3 Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:host=localhost;port=3306;dbname=fmsp", "root", "", []) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:44 4 Illuminate\Database\Connectors\Connector::createConnection("mysql:host=localhost;port=3306;dbname=fmsp", []) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connectors\MySqlConnector.php:24 5 Illuminate\Database\Connectors\MySqlConnector::connect() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php:183 6 Illuminate\Database\Connectors\ConnectionFactory::Illuminate\Database\Connectors\{closure}() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:915 7 call_user_func(Object(Closure)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:915 8 Illuminate\Database\Connection::getPdo() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:940 9 Illuminate\Database\Connection::getReadPdo() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:399 10 Illuminate\Database\Connection::getPdoForSelect() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:325 11 Illuminate\Database\Connection::Illuminate\Database\{closure}("select * from information_schema.tables where table_schema = ? and table_name = ?") C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:657 12 Illuminate\Database\Connection::runQueryCallback("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:624 13 Illuminate\Database\Connection::run("select * from information_schema.tables where table_schema = ? and table_name = ?", Object(Closure)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Connection.php:333 14 Illuminate\Database\Connection::select("select * from information_schema.tables where table_schema = ? and table_name = ?") C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php:18 15 Illuminate\Database\Schema\MySqlBuilder::hasTable("migrations") C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Migrations\DatabaseMigrationRepository.php:169 16 Illuminate\Database\Migrations\DatabaseMigrationRepository::repositoryExists() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:555 17 Illuminate\Database\Migrations\Migrator::repositoryExists() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php:97 18 Illuminate\Database\Console\Migrations\MigrateCommand::prepareDatabase() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php:63 19 Illuminate\Database\Console\Migrations\MigrateCommand::handle() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29 20 call_user_func_array([]) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29 21 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:87 22 Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:31 23 Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), []) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Container\Container.php:564 24 Illuminate\Container\Container::call() C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Console\Command.php:184 25 Illuminate\Console\Command::execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) C:\wamp64\www\API\vendor\symfony\console\Command\Command.php:251 26 Symfony\Component\Console\Command\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Console\Command.php:171 27 Illuminate\Console\Command::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\vendor\symfony\console\Application.php:886 28 Symfony\Component\Console\Application::doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\vendor\symfony\console\Application.php:262 29 Symfony\Component\Console\Application::doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\vendor\symfony\console\Application.php:145 30 Symfony\Component\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Console\Application.php:89 31 Illuminate\Console\Application::run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:122 32 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) C:\wamp64\www\API\artisan:37

J'ai visité quelques forums certain disait que c'était WAMP, d'autre localhost et d'autre encore que c'était Laravel en soit.
J'ai donc aussi tenté en utilisant postgreSQL qui est bien installé sur ma machine et fonctionne bien sous JAVA, j'ai la même erreur.
J'ai tenté de remplacer localhost par 127.0.0.1, même chose...

De plus cela m'a l'air correcte : PDO::__construct("mysql:host=localhost;port=3306;dbname=fmsp", "root", "", []) ?

Si vous avez déjà rencontré ce soucis ou si vous avez la solution je dis pas non :D

Merci d'avance pour l'aide !

Seokuymi.

15 réponses

Helixar, il y a 7 ans

as-tu installé l'extentions php pdo-mysql et est elle décomenté dans le php.ini?
pour régler un autre problème que tu auras dans le future, si tu veux un système d'authentication il faut un champ email dans ta table users sinon tu dois aller modifier la classe autenticable (de tête, je ne sais plus si c'est celle là)

Seokuymi, il y a 7 ans

Bonjour,

Oui tout est bien configuré sur le serveur.
En faisant le test avec juste un fichier PHP sans framework :

<?php $dbh = new PDO("mysql:host=localhost;port=3306;dbname=fmsp", "root", ""); foreach($dbh->query('SELECT * from latabletoto') as $row) { print_r($row); }

Cela fonctionne nickel et j'ai le retour qu'il me faut :

Array ( [id] => 1 [0] => 1 ) Array ( [id] => 2 [0] => 2 ) Array ( [id] => 3 [0] => 3 )

C'est pour ça que je ne comprend pas trop pourquoi ça ne marche pas ahah :)

Helixar, il y a 7 ans

Tu le lance avec Wamp ou le serveur interne de php ou même la commande php artisan serve?

Seokuymi, il y a 7 ans

Je le lance avec Wamp du coup, j'ai un dossier API dans mon www.
Je me place donc dans C:\wamp64\www\API et je fais php artisan migrate

Balsakup, il y a 7 ans

je fais php artisan serve

Donc tu le lances pas avec wamp ^^ mais avec le serveur interne

Que retourne la commande php --version, la commande php -m et la commande php --ini

Seokuymi, il y a 7 ans

Ah j'ai miss c/c :D
Je fais php artisan migrate *

Rebonjour,
Pour la réponse des commandes :

php --version :

PHP 7.2.7 (cli) (built: Jun 19 2018 23:14:45) ( ZTS MSVC15 (Visual C++ 2017) x64 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

php -m :

[PHP Modules] bcmath calendar Core ctype date dom filter hash iconv json libxml mbstring mysqlnd openssl pcre PDO Phar readline Reflection session SimpleXML SPL standard tokenizer wddx xml xmlreader xmlwriter zip zlib [Zend Modules]

php --ini :

Configuration File (php.ini) Path: C:\WINDOWS Loaded Configuration File: C:\wamp64\bin\php\php7.2.7\php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none)
Balsakup, il y a 7 ans

pdo_mysql n'est pas activé, décommente la ligne extension=pdo_mysql dans ton php.ini C:\wamp64\bin\php\php7.2.7\php.ini

Helixar, il y a 7 ans

vérifier ce qu'on demande dans un forum pour résoudre un problème c'est toujours utile, cf la première réponse :)
ps : voici un appercu de ce qu'il manque :

Seokuymi, il y a 7 ans

Ah, pourtant quand je vais dans le logo wamp => php.ini c'est décommanter, je vais aller voir directement dans le dossier, peut-être que ça ne m'ouvre pas le bon ?

Je fais un retour dès que j'ai testé,
En tout cas merci des réponses !!! :)

PS : ça fonctionne ! Du coup je sais pas trop pourquoi W -> PHP -> php.ini n'ouvre pas le bon, mais merci du coup

Helixar, il y a 7 ans

Mettre le sujet en résolu a la personne qui a juste répété ma première réponse..

edit : merci bien :)

tONIO PY, il y a 7 ans

Bonjour,

Je relance le sujet car j'ai a peu près le même problème qu'est ce que tu as modifié dans ton fichier php.ini ?
Je suis sur Mamp serveur sous mac os.

Helixar, il y a 7 ans

il faut décommenter pdo_mysql

adonis2, il y a 6 ans

Bonjour, je relance le sujet, j'ai également une erreur semblable ...

J'ai tenté de faire ce qui a été dis, j'ai bien pdo_mysql qui s'affiche quand je fais php -m, j'ai quand même ouvert mon fichier php.ini et il y a la ligne : ";extension=pdo_mysql" donc j'imagine que le ";" devant signifie que c'est du commentaire, j'ai donc essayé de le retirer, mais quand je le fais je ne peux pas enregistrer le fichier...

Sinon mon erreur est la suivante : quand je fais php artisan migrate :

Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = db_EA and table_name = migrations and table_type = 'BASE TABLE')

at /home/ecole/Desktop/Dev/testphp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {

664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|

Exception trace:

1 PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)")
/home/ecole/Desktop/Dev/testphp/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=db_EA", "root", "", [])
/home/ecole/Desktop/Dev/testphp/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

Please use the argument -v to see more details.

adonis2, il y a 6 ans

Je précise que je suis sur Laravel et que j'ai modifié les paramètres du fichier .env :

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_EA
DB_USERNAME=root
DB_PASSWORD=

Mehdi Slaoui, il y a 6 ans

Salut adonis2, je viens de régler le problème qui te sera peut-être utile, j'utilisais sans m'en rendre compte le mauvais fichier .env (d'un autre projet d'ailleurs) et donc les modifications ne s'effectuaient pas, je t'invite à vérifier le path de ton .env et si tu ne vois pas directement le contenu du fichier, utilise le terminal ;)