简体   繁体   中英

how to use mysql with laravel without any external database

我在 Java 中看到过像 H2Database 这样的 localhost 数据库,我想知道是否有任何方法可以将 mysql 数据库存储在我们的本地主机中,而且我们甚至不必使用外部数据库。

Yes you can use your local database like MySQL. You need to install MySQL and create the database. Then you can save the database credentials in ".env" file like this -

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=mydbname
DB_USERNAME=mydbuser
DB_PASSWORD=mydbpassword

You have to use DB in your controller like this

use DB;

and then you can use DB::table for your SQL queries. You can also use Laravel DB models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM