I am a beginner in PHP and SQL. Maybe this is a silly question, but I really want to hear from the professionals since I am planning on getting into website industry too.
When we try to do an sql query on the website, through PHP for example, we need to make a connection with the database before we doing so:
$mysqli = new mysqli("localhost", "root", "password", "my_db");
But doing this kind of bugged me because It does not look safe to me. I have to pass a password through the script which has a chance to be exposed to web users.
Is there a safer way of passing the password to the SQL command? How would people in the professional industry deal with this issue?
This is the proper way.
Usually the password is in a variable/constant and that variable is passed to this command.
If serving this file from a PHP server users on the web will not be able to see the source of this file. Therefore they will never see the password.