dorpbn1027 2012-08-08 21:38
浏览 22
已采纳

动态选择值

Example:

$user_input = $_POST['input'];
'SELECT '.$user_input.' FROM table_name'

So it's selecting a column in a database based on a secure (this example isn't secure obviously) value. Is this practical/allowable code?

  • 写回答

2条回答 默认 最新

  • doujiu6976 2012-08-08 21:44
    关注

    In SQL you simply send a string to the DBMS (like MySQL). Because of this you can build any string you want and submit it to the DBMS.

    You just have to make sure the resulting SQL query is valid. That means that e.g. the columns exist and that no invalid symbol appears.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?