I'm making school web application which will be for testing users SQL knowledge and they have to enter SQL queries in form textarea and execute it on server mySQL. the problem that occurred to me is that I can't do prepared statements or binding or white-list on unknown dynamic queries(entered by user) and this makes the application SQL injection vulnerable.
How can I prevent SQL Injection on this type of queries(allowed will be SELECT, DELETE, INSERT, UPDATE) without affecting the final compare result?
Maybe I'm missing some PHP function which can do that? or I have to create a SQL parser which will check user queries for possible SQL injections? I'm not trying to do anything fancy, I just need basic protection for my application.
I use CodeIgniter as Framework, but I don't think this will change anything.
How can I use PDO, statements,whitelists and other techniques, when user can enter queries like
select * from user where some_column = some_value (this is just example)
or query like
select * from user LEFT JOIN ..... having something > 5 ORDER by some_column
I can't predict their input and all possible combinations can contain injection vulnerability.
I receive on my end $_POST['SQL_user_query']
which contains string of SQL query, I can't use on it prepared statement.
EDIT: what i want is that is to prevent the users to do destructive things with my database and gain information about the tables, because after they submit the query the web application also will show the result from the query under the input textarea and if they make injection that can show sensitive information.