Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Possibly duplicate with <a href="https://stackoverflow.com/questions/9720587/create-db-and-user-mysql-and-set-privileges-php">create db and user mysql and set privileges php</a></p> <p>Let's suppose we have a mysql database:</p> <pre><code>mysql_connect('localhost','user',password); mysql_query("CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';"); mysql_query("GRANT ALL ON db1.* TO 'username'@'localhost'"); mysql_query("CREATE DATABASE newdatabase"); mysql_close(); </code></pre> <p>Read more about access granting on mysql databases at <a href="http://dev.mysql.com/doc/refman/5.1/en/grant.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.1/en/grant.html</a> and creating database users at <a href="http://dev.mysql.com/doc/refman/5.1/en/create-user.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.1/en/create-user.html</a></p> <p><strong>Later edit</strong>: </p> <pre><code>$user_priviledges = array( '__SELECT__' =&gt; array("select_user","password"), '__SELECT_DELETE__' =&gt; array("select_delete_user","password") ); // first you use just __SELECT__ user for getting the current user access information mysql_connect('localhost', $user_priviledges['__SELECT__'][0], $user_priviledges['__SELECT__'][1]); mysql_select_db('my_db'); $sql = mysql_query("SELECT user_access FROM access WHERE user_id='$my_loged_user_id'"); $row = mysql_fetch_array($sql); if ($row['user_access'] != '__SELECT__') { mysql_close(); // after you close the above mysql connection we can connect again with the real user access mysql_connect('localhost', $user_priviledges[$row['user_access']][0], $user_priviledges[$row['user_access']][1]); mysql_select_db('my_db'); } // my rest of code mysql_close(); </code></pre> <p>You have to take care about the user of the system and the user access and for that I think you have to implement some classes which will open/close mysql connections depending on what is the system (or the user) trying to do</p> <p>Note that I recommend you to use MySQLi instead of old mysql functions in PHP</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload