我正在尝试执行PHP / MySQL查询以对单个记录执行以下操作:
之前我从未对数据库信息模式做过任何事情,所以任何帮助都会很棒!
像......一样的东西?
$sth = $dbh->prepare("DESCRIBE users
WHERE column_name LIKE '_abc'
AND id = $user_id");
$sth->execute();
答案 0 :(得分:1)
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'db_name'
AND table_name = 'users'
AND column_name like '%_abc';
然后在更新语句中使用返回的列名
update users
set col1_abc = null, col2_abc = NULL
where id = $user_id