开发者

PHP, Mysql only update columns that exist in database?

I know this is a terrible way to write code but based on the clients situation, I'm wondering if there is a way to update columns in a database that exist and just do nothing with the other ones.

We have a query that's being generated and some of the columns are legit and will update just fine however so开发者_开发知识库me of the columns don't exist so when it tries to update it it fails. Is there anyway to update the records that do exist and throw away the other ones?

I really can't think of a simple way of doing this =/


You can query information_schema.COLUMNS table to get all columns for a given table. Then, you can modify your algorithm that generates update query to exclude all non-existing columns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜