在MySQL中获取表列名吗?有办法获取MySQL中表的列名吗?使用php
3 回答
慕森王
TA贡献1777条经验 获得超3个赞
public function getColumnNames($table){
$sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table";
try {
$core = Core::getInstance();
$stmt = $core->dbh->prepare($sql);
$stmt->bindValue(':table', $table, PDO::PARAM_STR);
$stmt->execute();
$output = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$output[] = $row['COLUMN_NAME'];
}
return $output;
}
catch(PDOException $pe) {
trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR);
}}Array ([0] => id[1] => name[2] => email[3] => shoe_size[4] => likes... )
添加回答
举报
0/150
提交
取消
