Laravel 5でSQLを直接実行する

print_r(\DB::select(\DB::raw('SHOW VARIABLES LIKE "%char%"')));

今回はテストなのでCLIから実行。

[root@43c787b378a6 app]# php artisan hoge:test
Array
(
[0] => stdClass Object
(
[Variable_name] => character_set_client
[Value] => utf8mb4
)
[1] => stdClass Object
(
[Variable_name] => character_set_connection
[Value] => utf8mb4
)
[2] => stdClass Object
(
[Variable_name] => character_set_database
[Value] => utf8mb4
)
[3] => stdClass Object
(
[Variable_name] => character_set_filesystem
[Value] => binary
)
[4] => stdClass Object
(
[Variable_name] => character_set_results
[Value] => utf8mb4
)
[5] => stdClass Object
(
[Variable_name] => character_set_server
[Value] => latin1
)
[6] => stdClass Object
(
[Variable_name] => character_set_system
[Value] => utf8
)
[7] => stdClass Object
(
[Variable_name] => character_sets_dir
[Value] => /usr/share/mysql/charsets/
)
)

参考
http://stackoverflow.com/questions/32594181/laravel-5-execute-sql-statement-in-string

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA