Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

php - How to connect to mysql with laravel?

This is such a simple basic question I don't think there is much people asking this but simply how do I connect to mySql through localhost phpmyadmin with laravel (I've searched, there is some stuff, but I need to ask because I am a noob and I'd like to ask, the stuff I saw I don't quite get 100% or I tried and it didn't help)?

I am working with backbone.js and am brand new to laravel, I installed laravel inside C:wampwwwlaravel-project

I tried

c:wampwwwlaravel-project> php artisan migrate:make create_tasks_table --table tasks --create

And

c:wampwwwlaravel-project> php artisan migrate

I expect to have to define the database information, I checked C:wampwwwlaravel-projectappconfigdatabase.php and it looks correct, mySQL is set on the defaults root being the user name, and '' empty being the password.

The error in the command line I get after running php artisan migrate is

[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'database'    

I am using windows 8, and wamp for my localhost server, it of course includes phpmyadmin and mySql. So I am sure there are tons of ways to use mySql but I don't think I am setting up laravel and phpmyadmin properly.

So any insight would be amazing, easy points.

EDIT:

Actually thinking this through maybe I need to create a database named database let me try that. be back soon. Okay I'll answer my question or someone can, just in case someone searches this topic... it is KEY to make sure the database defined in C:wampwwwlaravel-projectappconfigdatabase.php matches a database that exists inside your phpmyadmin. No brainer!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Laravel 5, there is a .env file,

It looks like

APP_ENV=local
APP_DEBUG=true
APP_KEY=YOUR_API_KEY

DB_HOST=YOUR_HOST
DB_DATABASE=YOUR_DATABASE
DB_USERNAME=YOUR_USERNAME
DB_PASSWORD=YOUR_PASSWORD

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

Edit that .env There is .env.sample is there , try to create from that if no such .env file found.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...