Could PDO open a read-only connection? Ie any mysql write requests will give an error, and for reading everything is ok.
1 answer
Alternatively, this problem can be solved not at the PDO-driver level, but at the level of mysql-user access rights. You can allow the user to perform only SELECT queries to the dbname database using the following GRANT TABLE statement
GRANT SELECT ON dbname.* TO 'read'@'localhost' IDENTIFIED BY 'password'; - Somehow safer at the PDO level. - Denis Kotlyarov
- A user, not an option, in parallel, this user is used by other people who are allowed to write. - Denis Kotlyarov
- @DenisKotlyarov, not a fact, protect one application, and others do not - they can access the same database in general not through PDO and not through your application layer. If you act through the readonly user, whatever driver you use, the server simply will not allow the application to run. Why not make multiple connections at the application level with different users? readonly, write ... or is it some kind of permissions system? - cheops
- This is php :) Although your idea about several users is interesting. Thanks for the tip. - Denis Kotlyarov
|