以下是获取单行所有列的查询
$STH = $DBH->db->prepare("SELECT * FROM Settings");
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
$str = '';
while ($row = $STH->fetch())
{
foreach($row as $key => $value)
{
$str .= '<div>'.$key.' => '.$value.'</div>';
}
}
这个是获取列的扩展信息(包括comment
)
$STH = $DBH->db->prepare("SHOW FULL COLUMNS FROM Settings");
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
\* the same php code *\
我可以将这两个SQL查询结合起来以同时获取以下数据
`FieldName`, `FieldValue`, `CommentValueOfColumn`
” “ “
设置表的示例
Columns -> | PrintImage | SettMinus | HasChat . . .
--------------------------------------------
Values -> 0 1 1 . . .
并且该列还有其他数据Comment
。
所以我想选择数据:
PrintImage, 0 , Comment of PrintImage;
SettMinus, 1 , Comment of SettMinus;
HasChat, 1 , Comment of HasChat;
.....................................
and so on.
答案 0 :(得分:0)
这将为您提供列名,列值和注释。但是,您可以使用php来获取值 的 VALUEARRAY [ORDINAL_POSITION] 强> 您还需要在concat_ws之后复制/粘贴其余列名。
同样,我无法在mysql中做所有事情,因此需要PHPcodes的帮助才能从数组中获取确切的值。
SELECT s.COLUMN_NAME,
s.ORDINAL_POSITION,
t.valuearray,
s.COLUMN_COMMENT
from INFORMATION_SCHEMA.columns s
cross join (select concat_ws(",", PrintImage,
SettMinus,HasChat) as valuearray from settings) t
where s.TABLE_NAME='Settings';
sample result :
COLUMN_NAME ORDINAL_POSITION valuearray COLUMN_COMMENT
PrintImage 1 0,1,1 commenttest
SettMinus 2 0,1,1 comments too
HasChat 3 0,1,1 3rd comment