laravel 执行原生sql
http://www.xiaosongit.com/index/detail/id/769.html
laravel 获取表字段的方法
http://www.xiaosongit.com/index/detail/id/710.html
use Illuminate\Support\Facades\Schema;
use DB;
public function getDatabaseColumns() {
$tables = DB::select('show tables');
$tables = array_column($tables, 'Tables_in_new_bcc_web');
$columns = ['email', 'user_name', 'nick_name', 'first_name', 'last_name'];
// dd(Schema::getConnection());
foreach ($tables as $key => $value) {
foreach ($columns as $k => $v) {
if (Schema::hasColumn($value, $v)) {
$table[] = $value;
};
}
// $columns[] = Schema::getColumnListing('users');
}
$table = array_unique($table);
dd($table);
}use Illuminate\Support\Facades\Schema;
Schema::getColumnListing('user');
Schema::hasColumn($table, $column_name)public function getDatabaseColumns() {
$tables = array_map('reset', \DB::select('SHOW TABLES'));
$columns = ['email', 'user_name', 'nick_name', 'first_name', 'last_name'];
foreach ($tables as $key => $value) {
foreach ($columns as $k => $v) {
if (Schema::hasColumn($value, $v)) {
$table[] = $value;
};
}
}
$table = array_unique($table);
dd($table);
}获取所有表
//获取表
Schema::connection('mysql')
Illuminate\Database\Schema\MySqlBuilder
Schema::connection('mysql')->getAllTables();
Schema::connection('mysql')->getColumnListing() //获取表的字段
getColumnListing() //获取表的字段
hasTable() //是否包含表
dropAllTables //删除所有的表 慎用
getAllViews //获取所有的视图
dropIfExists() 如果表存在就删除
$tables = Schema::getColumnListing($tableName); //返回表字段信息