Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Konfiguracja połączenia bazy danych w Laravel, Jak skonfigurować połączenie bazy danych w Laravelu
xsalok
post 14.07.2016, 10:52:06
Post #1





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 18.01.2016

Ostrzeżenie: (0%)
-----


Czy dysponuje ktoś doświadczeniem w konfigurowaniu połączenia Laravela z bazą danych?
Wiem, że odpowiada za to plik database.php, zapewne fragment "Database Connections". Jednak bazę utworzyłem lokalnie poprzez phpmyadmin i nie bardzo wiem jak skonfigurować połączenie w Laravelu.

Załączam plik konfiguracyjny:
  1. <?php
  2.  
  3. return [
  4.  
  5. /*
  6.   |--------------------------------------------------------------------------
  7.   | PDO Fetch Style
  8.   |--------------------------------------------------------------------------
  9.   |
  10.   | By default, database results will be returned as instances of the PHP
  11.   | stdClass object; however, you may desire to retrieve records in an
  12.   | array format for simplicity. Here you can tweak the fetch style.
  13.   |
  14.   */
  15.  
  16. 'fetch' => PDO::FETCH_CLASS,
  17.  
  18. /*
  19.   |--------------------------------------------------------------------------
  20.   | Default Database Connection Name
  21.   |--------------------------------------------------------------------------
  22.   |
  23.   | Here you may specify which of the database connections below you wish
  24.   | to use as your default connection for all database work. Of course
  25.   | you may use many connections at once using the Database library.
  26.   |
  27.   */
  28.  
  29. 'default' => env('DB_CONNECTION', 'mysql'),
  30.  
  31. /*
  32.   |--------------------------------------------------------------------------
  33.   | Database Connections
  34.   |--------------------------------------------------------------------------
  35.   |
  36.   | Here are each of the database connections setup for your application.
  37.   | Of course, examples of configuring each database platform that is
  38.   | supported by Laravel is shown below to make development simple.
  39.   |
  40.   |
  41.   | All database work in Laravel is done through the PHP PDO facilities
  42.   | so make sure you have the driver for your particular database of
  43.   | choice installed on your machine before you begin development.
  44.   |
  45.   */
  46.  
  47. 'connections' => [
  48.  
  49. 'sqlite' => [
  50. 'driver' => 'sqlite',
  51. 'database' => env('DB_DATABASE', database_path('database.sqlite')),
  52. 'prefix' => '',
  53. ],
  54.  
  55. 'mysql' => [
  56. 'driver' => 'mysql',
  57. 'host' => env('DB_HOST', 'localhost'),
  58. 'port' => env('DB_PORT', '3306'),
  59. 'database' => env('DB_DATABASE', 'test_abc'),
  60. 'username' => env('DB_USERNAME', 'admin'),
  61. 'password' => env('DB_PASSWORD', 'admin'),
  62. 'charset' => 'utf8',
  63. 'collation' => 'utf8_unicode_ci',
  64. 'prefix' => '',
  65. 'strict' => false,
  66. 'engine' => null,
  67. ],
  68.  
  69. 'pgsql' => [
  70. 'driver' => 'pgsql',
  71. 'host' => env('DB_HOST', 'localhost'),
  72. 'port' => env('DB_PORT', '5432'),
  73. 'database' => env('DB_DATABASE', 'forge'),
  74. 'username' => env('DB_USERNAME', 'forge'),
  75. 'password' => env('DB_PASSWORD', ''),
  76. 'charset' => 'utf8',
  77. 'prefix' => '',
  78. 'schema' => 'public',
  79. ],
  80.  
  81. ],
  82.  
  83. /*
  84.   |--------------------------------------------------------------------------
  85.   | Migration Repository Table
  86.   |--------------------------------------------------------------------------
  87.   |
  88.   | This table keeps track of all the migrations that have already run for
  89.   | your application. Using this information, we can determine which of
  90.   | the migrations on disk haven't actually been run in the database.
  91.   |
  92.   */
  93.  
  94. 'migrations' => 'migrations',
  95.  
  96. /*
  97.   |--------------------------------------------------------------------------
  98.   | Redis Databases
  99.   |--------------------------------------------------------------------------
  100.   |
  101.   | Redis is an open source, fast, and advanced key-value store that also
  102.   | provides a richer set of commands than a typical key-value systems
  103.   | such as APC or Memcached. Laravel makes it easy to dig right in.
  104.   |
  105.   */
  106.  
  107. 'redis' => [
  108.  
  109. 'cluster' => false,
  110.  
  111. 'default' => [
  112. 'host' => env('REDIS_HOST', 'localhost'),
  113. 'password' => env('REDIS_PASSWORD', null),
  114. 'port' => env('REDIS_PORT', 6379),
  115. 'database' => 0,
  116. ],
  117.  
  118. ],
  119.  
  120. ];
Go to the top of the page
+Quote Post
rad11
post 14.07.2016, 12:49:17
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Musisz uzupełnić jeszcze plik .env:


  1. APP_ENV=local
  2. APP_KEY=SomeRandomString
  3. APP_DEBUG=true
  4. APP_LOG_LEVEL=debug
  5. APP_URL=http://localhost
  6.  
  7. DB_CONNECTION=mysql
  8. DB_HOST=127.0.0.1
  9. DB_PORT=3306
  10. DB_DATABASE=homestead
  11. DB_USERNAME=homestead
  12. DB_PASSWORD=secret
  13.  
  14. CACHE_DRIVER=file
  15. SESSION_DRIVER=file
  16. QUEUE_DRIVER=sync
  17.  
  18. REDIS_HOST=127.0.0.1
  19. REDIS_PASSWORD=null
  20. REDIS_PORT=6379
  21.  
  22. MAIL_DRIVER=smtp
  23. MAIL_HOST=mailtrap.io
  24. MAIL_PORT=2525
  25. MAIL_USERNAME=null
  26. MAIL_PASSWORD=null
  27. MAIL_ENCRYPTION=null


Ten post edytował rad11 14.07.2016, 12:49:26
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 23.04.2024 - 19:45