mysql passwords Connecting to MySQL with PHP

后端 未结 3 540
旧时难觅i
旧时难觅i 2021-01-25 05:34

In tutrorials for Connecting to MySQL with PHP you see something similar to the below.

$pdo = new PDO(\'mysql:host=localhost;dbname=mydb\', \'myuser\',\'mypassw         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 05:40

    An end user will never be able to see the text inside a PHP script. They only see what is output by the code. You can put passwords like that in, as long as you never do something like:

    $mySecretPassIs='TheBoogeyManCometh';
    
    echo $mySecretPassIs;
    

    Having said that, it is often easier to put your connection details in a script, include it as you need from the various pages and off you go. The benefit is that if you change passwords or the like, you only have to change it in one place, and you can keep these included files in one safe place.

提交回复
热议问题