I wanted to connect a MySQL database to my Laravel application.
I created one using PHPMyAdmin administration tool of MySQL, then I added it in the .env as whereas the database.php application files.
I ran the terminal command: php artisan migrate which gave me the following error:
could not find driver (SQL: select * from information_schema.tables where table_schema = pl_project and table_name = migrations and table_type = 'BASE TABLE')
at C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
1 C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2 C:\Users\u\Documents\pl_project_test\pl_project_test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct()
Here is the .env excerpt that I edited:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pl_project
DB_USERNAME=root
DB_PASSWORD=
Here is the database.php excerpt that I edited:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'pl_project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
]
Here is the output of the command: php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
A couple of notes:
I did add PHP to my env variables as well as MySQL.
I did uncomment extension=pdo_mysql in php.ini.
But none of it changed anything and I still get the same error.
There is no need in editing database.php file as it is using .env for database info. In case this is new project that did not have .env file, try running php artisan config:clear
Have you tried restarting PC after enabling extension? If you are running your project with artisan serve it will not reflect after you change ini file
I also had few similar issues on couple of machines with database, it got solved with commenting 'url' => env('DATABASE_URL'), line in mysql
Hope some of this helps
Comment:
I checked all the php.ini files there were 2 so I edited the second
one. restarted the server then tried to migrate again only to get the
same error.. – OP - https://stackoverflow.com/posts/comments/131493101?noredirect=1
From what I can recall, the default XAMPP installation lucks a php.ini file in the path xampp/php/.
It however has php.ini-development and php.ini-production configuration files in that path. You would normally have to create a duplicate copy of either of those two files depending on your use case and rename the 'duplicate copy' to php.ini This renamed file would then be considered as the 'active/default PHP configuration file'.
You would then open this new renamed php.ini file, uncomment any necessary extension libraries, save and restart your XAMPP web server (Apache).
Addendum
You may need to enable/uncomment the extension libraries below for your case.
mysqli
pdo_mysql
pdo_sqlite
Addendum 2
A. Enable/uncomment the line below. Change the path to your XAMPP installation path. I.e:
extension_dir="C:\xampp\php\ext"
Related
My laravel project keeps connecting with the old database. I already changed .env's database name but still, my project connects with the old database. I have no idea why is this happening.
I ran all these commands
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan route:clear
php artisan route:cache
also, restart my server, update my composer but nothing works...
This is the error shown in the terminal :
SQLSTATE[HY000] Unknown database 'users'
Here is my .env
DB_DATABASE=user_manager
DB_USERNAME=root
DB_PASSWORD=
There must be still issue with your ENV file. can you please take a double check in this? also please check that is there database exists in phpMyAdmin?
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=root
DB_PASSWORD=
in config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
'options' => [
\PDO::ATTR_PERSISTENT => true
]
],
for more info,
link to laravel official site
Error resolved.
The error was occurring because of the config.php file. My old database name is stored there. I deleted that config.php file and everything is working perfectly fine.
Your should stop your artisan serve(ctrl+c) and then reserve project
php artisan serve
Aren't you missing DB_HOST in your env File? Looks like you have the DB_HOST hardcoded to your database host or your php-fpm.conf.
I faced the same problem and solved by using the following command:
composer dump-autoload
PHP artisan config:cache
PHP artisan config:clear
I just setup GeneaLabs/laravel-model-caching packages. When running serve i got redis class missing. Then i run
composer required predis/predis
After that
I got this error
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]
and i got this error. Still working but I have not made any progress yet.
Any idea?
PS: i am working localhost with mysql. Not homestead.
Install Redis.
https://redis.io/download or if the os is windows then https://github.com/MicrosoftArchive/redis/releases
Run Redis.
$ src/redis-server or in windows then run redis-server.exe
Set the .env variables
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Add redist code to database.php
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
install latest version of redis from This link is in GateHub
then go to the .env file and change the CACHE_DRIVER to redis
CACHE_DRIVER=redis
then go to the path config/database.php and change the REDIS_CLIENT from phpredis to predis
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
],
and clear config with this command : php artisan config:clear
Im trying to use the command php artisan migrate, however i keep getting the error:
PDOException
SQLSTATE[HY000] [1049] Unknown database 'forge'
at first i got the:
access denied for user 'homestead'#'localhost'
but that was fixed when I changed the database.php and .env files to:
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
.env
DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=''
I read somewhere that I had to create the database in the mySQL database. If i do need to do this why is that, is there an alternative more effecient way from the command line. My development environment is Windows 7.
UPDATE
I have solved this error by going to localhost/phpmyadmin and creating a database with the same name and collation. But i still dont understand why i have to use phpmyadmin to create it, how would i be able to do this from the command line.
Also, inside this database i have tables for users, if i get more info from the users, do i create another database or just use a table with the values ?
Usually you have all of your data contained in one database and have the user only have access to that table. The method you're trying to go through is not secure as you have to give laravel (or the app) permission to create any tables, delete any tables (to undo the tables created), and read any tables, which can get hairy in a environment that share a database with other applications.
It also goes to say that if the application doesn't adhere to a prefix naming of dbs it could make them at will and collide with another application since namespacing doesn't exist.
If however you really do need this functionality you can follow the guide written by Koster (http://laravel.io/forum/09-13-2014-create-new-database-and-tables-on-the-fly).
I am trying to deploy a Laravel 4.2 application on RedHat OpenShift.
I have successfully transferred the code from GitHub but I am stuck at the database integration.
How do I run the migrations?
I have created a new mysql_openshift database connection with
OpenShift credentials and updated the same.
I have a migration file in the migrations folder.
But on running the php artisan migrate i get the following error:
http://i.stack.imgur.com/nQbam.png
Please help!
The Laravel 4.2 QuickStart was updated 2 days ago. The QuickStart now automatically runs php artisan migrate when you deploy changes to OpenShift. I definitely recommend switching over to using the QuickStart or updating to the latest version.
Anyways, the short answer to the problem you're seeing: your database is not configured properly in Laravel. See lines 60-70 of app/config/database.php in the Laravel 4.2 QuickStart for a reference on configuring the host/port connection info.
Your openshift db parameters are not set correctly.
Look at your config/database.php you will see how the setting in .env are used. Like before we try to get environmental variables from Openshift. The function env('DB_HOST', 'default') will take either DB_HOST from .env or use the default value in the second parameter. Since .env is excluded from version control, Laravel will take the Openshift-specific settings instead.
So put the following code in your config/app.php :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST')),
'database' => env('DB_DATABASE', getenv('OPENSHIFT_APP_NAME')),
'username' => env('DB_USERNAME', getenv('OPENSHIFT_MYSQL_DB_USERNAME')),
'password' => env('DB_PASSWORD', getenv('OPENSHIFT_MYSQL_DB_PASSWORD')),
'port' => env('DB_PORT', getenv('OPENSHIFT_MYSQL_DB_PORT')),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,],
I am currently setting up a Laravel installation and running through a tutorial to familiarize myself with this new framework.
I have managed to install composer and the Laravel base installation fine, but when i attempt to create a new database and seed it using artisan, nothing actually happens. Artisan tells me that is has seeded it fine but nothing seems to change in MYSQL.
My WAMP server is running on a local machine with Apache and PHPMyadmin and is setup correctly and has no issues (been using it for many projects before.)
Here are my database config settings:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'celebrity_v1',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I had to set the database up manually as even though the Artisan migrate command said it was working, it wouldn't actually create a new table, same with the seed.
My commands are as follows:
php artisan migrate:make create_comments_table --create=comments
php artisan migrate
And to seed:
php artisan db:seed
Can anyone see any problems with anything I am attempting to do here or suggest why I am having these issues? I don't have a lot of experience with Laravel.
Thanks
You should set the values in /app/config/local/database.php instead of app/config/database.php