title: PHP and MySQL - how to avoid password in source code?
body: <p>I have a small PHP application storing data in a <a href="http://en.wikipedia.org/wiki/MySQL" rel="noreferrer">MySQL</a> database. Currently username / password are hard-coded in the PHP code. A situation I do not really like, for example, since the code is also available in a repository.</p>
  
  <p>The best idea I have is to move the data from the code to a configuration file (excluded from the repository), and somehow encode it, so is not directly readable (obfuscation). Is there any better and easy to use way to solve the issue?</p>
  
  <pre><code>$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  if (!$link) { 
      die('Could not connect: ' . mysql_error());
  }
  mysql_select_db('mydb');
  </code></pre>
  
  <p>Scope: I want to established a robust, but also easy-to-use solution. I want reasonable security, but I am not dealing with highly confidential data here.</p>
  
  <p>Remark: It is no longer recommended to use the <code>mysql_connect</code> functions, see Stack Overflow question <em><a href="https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php">Why shouldn't I use mysql_</em> functions in PHP?</a>*. I could have changed the code example, but since some comments refer to this, I did not. However, the original nature of the question remains valid.</p>