tags:

views:

34

answers:

3

Before looking into my question, lets consider the fopen in C. There are multiple ways of opening a handle

fopen("abc.txt", "r");
fopen("abc.txt", "w");
fopen("abc.txt", "rw");

Similarly, will we be able to connect to a MySql database. To be more specific and clear, if i want to just read the database, all i need is select query. But is there a facility/feature/ api in php which when used can prevent mysql_query(Insert ** , link) from getting executed based on the privileges of the link. That is if the link is opened in the read mode, then no other query other than the read should be allowed. Is this possible??

If the answer to the above question is NO, then what is the purpose of the link? Is it just to connect to multiple databases?

A: 

NO.
Yes.

Mysql is a little more intelligent storage system than a filesystem.
It has it's own privileges system, far more flexible than just r-w-rw.
There is no sense in controlling it from the client side. One who can execute a query, can change access level as well.

Col. Shrapnel
A: 

Jamie in the comments nails this. The correct way to do this is to only GRANT capabilities to your MySQL users that the user needs. If you app only needs to do SELECTs, use a MySQL user who can only do SELECTs, and so on.

Jordan
+1  A: 

I'm not 100% sure what you are asking, so forgive me if this doesn't really answer your question.

I believe the access restrictions you are referring to should be handled at the database server layer by granting only the necessary permissions to the user that you are using to access the database.

The 'handle' is just to connect to the database.

wshato