PHP connections to mysql database explained

Discussion in 'Forum Discussion' started by hookshy, Feb 13, 2018.

  1. hookshy

    hookshy Well-Known Member Licensed 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
  2. sorex

    sorex Expert Licensed 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.
  3. hookshy

    hookshy Well-Known Member Licensed User

    ok thanks
  4. KMatle

    KMatle Expert Licensed 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).
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice