PHP connections to mysql database explained

hookshy

Well-Known Member
Licensed User
Longtime User
I use in one of my projects a php file to connect to my sqldatabase , all users connect to the database from this phpfile with one mysql user.

Should I create multiple php files to separate tasks within the app ?
The php connects with relation to one user defined in mysql database ,is there enough to use one user for all connections or I should create more users for each php file ?


Thank you
 

sorex

Expert
Licensed User
Longtime User
It depends on the situation.

sometimes I use a read only user for front-end tasks and a modify account for the backend to edit content.

if you want to keep track of for example download counts and display it near the download link you need modify rights aswell to update the download count (unless you do it in a file).
so in most cases you still need r/w even for the front end. So you could add a r/w account to the download code page only or apply it to the general site db code include.
 

KMatle

Expert
Licensed User
Longtime User
Yes! I use at least 3 files. One as a portal to login the user/app. The "real" path to the mainscript is transmitted to my app if the login and other checks were successful and only kept in memory. The 3rd php is like sorex posted (include of the script which contains the db credentials). All scriptnames are non speaking (= not "login" but "eh4idh8e.php" or so).
 
Top