Laravel 动态读取mysql表数据(包含列、值 。难点,出现对象数组且列不确定
1、字段列取出
2、数据取出
3、页面遍历列
4、对象->列 取出 表中值
Model层
<pre style="background-color:#272822;color:#f8f8f2;font-family:'Source Code Pro';font-size:13.5pt;">$results <span style="color:#f92672;">= </span>DB<span style="color:#f92672;">::</span><span style="color:#a6e22e;">select</span>(<span style="color:#e6db74;">"select COLUMN_NAME from information_schema.COLUMNS where table_name = '</span><span style="color:#fd971f;font-style:italic;">$tableName</span><span style="color:#e6db74;">' and table_schema='dmp_line2';"</span>);
$results = DB::select("select COLUMN_NAME from information_schema.COLUMNS where table_name = '$tableName' and table_schema='dmp_line2';");public function getTableC() //得到表所有列名 { $results = DB::select("select COLUMN_NAME from information_schema.COLUMNS where table_name = &