ページの作成

ページの作成

親となるページを選択してください。

ページは必ず何かしらの親ページに紐づきます。
親ページに紐づくページを子ページといいます。
例: 親=スポーツ, 子1=サッカー, 子2=野球

子ページを親ページとして更に子ページを作成することも可能です。
例: 親=サッカー, 子=サッカーのルール

親ページはいつでも変更することが可能なのでとりあえず作ってみましょう!
テンプレートを更新

3. 複数のデータベースに接続する方法

本稿ではLaravelにて複数データベースに接続する方法に関して記述します。

 

ポイントは「/config/database.php」ファイルとなるので開きましょう。

もうひとつDBの設定を追加する場合は以下のように記述します。(黄色い文字が追記した部分)

    'default' => env('DB_CONNECTION', 'mysql'),

    'connections' => [

        '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' => true,
            'engine' => null,
        ],

      'mysql2' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST_2', '127.0.0.1'),
            'port' => env('DB_PORT_2', '3306'),
            'database' => env('DB_DATABASE_2', 'forge'),
            'username' => env('DB_USERNAME_2', 'forge'),
            'password' => env('DB_PASSWORD_2', ''),
            'unix_socket' => env('DB_SOCKET_2', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],   

],

 

.envファイルには「DB_HOST_2」など新しいDBの接続設定を記述しておいて下さい。

実際に2つ目のSQLを実行する際には以下のように記述します。

DB::connection('mysql2')->select('select * from members');

 

なお、1つめのDBに接続する際は今までどおり明示的な「connection」を記述する必要はありません。

理由は「/config/database.php」の「default」に設定されているのが1つめのDBだからです。

以下、もう少し複雑なSQLの実行例。

$results = DB::connection('mysql2')
                ->table('ret_t_tweet')
                ->join('ret_m_user', 'ret_t_tweet.user_id', '=', 'ret_m_user.id')
                ->where('ret_m_user.delete_flag', 0)
                ->where('ret_t_tweet.created_at_shaped', ">=", $today)
                ->select('ret_t_tweet.tweet_url as tweet_url'
                        , 'ret_t_tweet.text as text'
                        , 'ret_t_tweet.created_at_shaped as created_at_shaped'
                        , 'ret_m_user.id as user_id'
                        , 'ret_m_user.name as user_name'
                        )
                ->paginate(10);

 

モデル (Eloquent) に設定する場合。

class Sample extends Model
{

    protected $connection = 'mysql2';

}

 

子ページ
子ページはありません
同階層のページ
  1. config/database.phpファイル
  2. .env
  3. 複数のデータベースに接続する方法
  4. DBトランザクション
  5. DBの悲観ロック

最近の質問

コメント一覧

    No.46 | guest | 2022-01-26 06:01:12

    admission essay <a href=https://essaysitesreviews.com>essay outline high school</a> persuasive essay ideas

    No.45 | guest | 2022-01-25 07:32:34

    illustration essay <a href=https://essayscratch.com>descriptive essay topics</a> essay cover page example

    No.44 | guest | 2022-01-24 08:58:32

    lab aseptic technique critical thinking #4 <a href=https://criticalthinkinginstitute.com>critical thinking pictures</a> critical thinking for students

    No.43 | guest | 2022-01-23 11:07:24

    critical thinking in the classroom <a href=https://criticalthinkingbasics.com>critical thinking is the process of</a> critical and creative thinking

    No.42 | guest | 2022-01-22 12:45:07

    decision making and critical thinking <a href=https://criticalthinking2020.net>critical thinking theory</a> ati critical thinking

    No.41 | guest | 2022-01-21 14:52:56

    windows 10 vpn <a href=https://choosevpn.net>express vpn free</a> private vpn

    No.40 | guest | 2022-01-20 15:29:15

    gay chat random x4 <a href=https://bjsgaychatroom.info>best free gay chat</a> random gay webcam chat

    No.39 | guest | 2022-01-19 15:54:37

    college essay guy <a href=https://anenglishessay.com>free essay generator</a> write an argumentative essay

    No.38 | guest | 2022-01-18 19:04:44

    best vpn wirecutter <a href=https://addonsvpn.com>trustzone vpn</a> free vpn server list

    No.37 | guest | 2022-01-01 21:28:31

    apa essay example <a href=https://essaytodo.com/?>essays on writing</a> essay writing website

    No.36 | guest | 2021-12-30 18:42:24

    i hate writing essays <a href=https://dollaressays.com/?>good college essay samples</a> how to write a profile essay

    No.35 | guest | 2021-12-28 16:54:29

    my dream essay <a href=https://essayprepworkshop.com/?>compare and contrast essay</a> what to write in a college essay

    No.34 | guest | 2021-12-27 14:14:15

    writing an evaluation essay <a href=https://checkyouressay.com/?>what is an expository essay</a> typing essay in verdana

    No.33 | guest | 2021-12-23 13:03:02

    what to write about in college essay <a href=https://casinogamesmachines.com/?>analysis essay writing</a> writing college essays

    No.32 | guest | 2021-12-22 14:49:32

    write my college essay <a href=https://casinoonlinek.com/?>essays to write</a> i need help writing an essay

    No.31 | guest | 2021-12-21 14:01:36

    best custom essay writing services <a href=https://onlinecasinoad.com/?>writing analysis essay</a> write my essay for cheap

    No.30 | guest | 2021-12-20 16:56:32

    writing essays for money <a href=https://casinoonlinet.com/?>write essays online</a> help writing an essay

    No.29 | guest | 2021-12-19 18:14:20

    cheapest essay writing service <a href=https://multiessay.com/?>essays to write</a> write and essay

    No.28 | guest | 2021-12-17 21:52:38

    writes essay for you <a href=https://student-essay.com/?>write analysis essay</a> analysis essay writing

    No.27 | guest | 2021-12-16 15:20:00

    the best essay writing service <a href=https://buy1essay.com/?>writing a reflection essay</a> custom writing essay

    No.26 | guest | 2021-12-15 14:00:37

    asian sex games <a href=https://sexygamess.com/?>sex games no credit card</a> couples plays strip poker and sex games

    No.25 | guest | 2021-12-14 16:53:37

    sex games on play store <a href=https://sexgameszone.com/?>sex games video</a> pool sex games

    No.24 | guest | 2021-12-13 19:28:11

    steam for sex games <a href=https://sex4games.com/?>diy sex games</a> 3d sex games porn

    No.23 | guest | 2021-12-12 09:36:03

    brandi belle sex games <a href=https://winsexgames.com/?>adult sex games for android</a> best sex games on the internet for free

    No.22 | guest | 2021-12-11 10:44:33

    the best sex games <a href=https://sexygamess.com/?>gay sex games</a> card games nude adult sex games

    No.21 | guest | 2021-12-06 13:07:44

    keto diet list <a href=https://ketogenicdietinfo.com/?>shark tank keto diet</a> keto friendly wine

    No.20 | guest | 2021-12-05 15:23:44

    keto apple crisp <a href=https://ketogenicdietinfo.com/?>keto foods list</a> keto diet\

    No.19 | guest | 2021-12-04 13:56:00

    wwe sex games <a href=https://sexgamesx.net/?>wonder woman sex games</a> sex pc games

    No.18 | guest | 2021-11-30 07:24:01

    xxx sex games <a href=https://sex4games.com/?>sex games better than 3dsexvilla 2</a> sex games vegas the bet

    No.17 | guest | 2021-11-29 11:41:38

    interactive 3d sex games <a href=https://sex4games.com/?>3d interactive sex games</a> extreme sex games

    No.16 | guest | 2021-11-26 10:41:27

    attack on titan sex games <a href=https://sexgameszone.com/?>my free sex games</a> roblox sex games

    No.15 | guest | 2021-11-09 06:58:59

    opinion essay example <a href=https://essaytodo.com/?>how to write a comparative essay</a> write an essay introduction

    No.14 | guest | 2021-11-05 05:16:26

    help writing essays <a href=https://essaytodo.com/?>custom essays writing</a> paid to write essays

    No.13 | guest | 2021-10-15 00:44:48

    website for resume <a href=https://essaysnet.com/?>scholarship essay writing service</a>

    No.12 | guest | 2021-10-10 20:40:29

    essays for money <a href=https://essayghostwriter.com/?>fantasy writers</a>

    No.11 | guest | 2021-09-15 22:56:49

    gay dating site australia gay herpes dating <a href=http://gaydatingcanada.com/?>gay dating phone sites</a>

    No.10 | guest | 2021-09-13 01:00:03

    gay latino dating dating a guy you think is gay <a href=http://datinggayservices.com/?>gay mobile dating sites</a>

    No.9 | guest | 2021-09-08 03:09:34

    international gay dating gay-dating <a href=gayedating.com?>top 10 gay dating websites</a>

    No.8 | guest | 2021-09-06 06:18:09

    christian dating site gay dating gay cowboys <a href=http://gaychatgay.com?>gay chat dating site</a>

    No.7 | guest | 2021-09-03 04:31:20

    gay sites for dating how to delete dating sites gay <a href=http://gaychatgay.com?>fre gay dating</a>

    No.6 | guest | 2021-08-17 23:43:02

    gay dating sim for android limerick gay dating <a href=http://gaychatrooms.org?>gay poly dating</a>

    No.5 | guest | 2021-08-15 01:52:33

    gay dating pakistan best gay dating side for free <a href=http://gaychatrooms.org?>iowa gay dating site</a>

    No.4 | guest | 2021-08-12 03:40:06

    christian gay dating site online dating for gay men <a href=http://freegaychatnew.com?>black gay men dating site</a>

    No.3 | guest | 2021-08-08 00:34:25

    famous gay dating sites mature gay men dating site <a href=http://gaychatus.com?>adult gay dating</a>

    No.2 | guest | 2021-07-30 19:09:47

    dating websites new <a href=http://onlinedatingtwo.com/?>nina dobrev dating</a>

    No.1 | guest | 2021-07-29 15:40:36

    chat adult <a href=http://onlinedatinglook.com/?>free dating websites</a>