Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow only "Select" statement for queries executed through PHP

Tags:

sql

php

select

I have made a form that accepts query and executes it through php. I would like to apply a check on the input that only select statement is allowed for queries. How can i achieve that ?

like image 293
Ashish Saxena Avatar asked Dec 02 '25 05:12

Ashish Saxena


1 Answers

Best way is if you have access to your database server and can create a new user, create a user with only a SELECT privilege, then assign that user to your php web application.

http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-privileges

Regex is fine, but it's a bit of a risky method to filter it out that way, you'll never know how creative your user can be :)

like image 109
Andreas Wong Avatar answered Dec 03 '25 20:12

Andreas Wong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!