Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I connect to mysql from php?
    text
    copied!<p>I'm working through examples from a book on php/mysql development. I'm working on a linux/apache environment.</p> <p>I've set up a database and a user. I attempt to connect with this line of code:</p> <pre><code>$db_server = mysql_connect($db_hostname, $db_username, $db_password); </code></pre> <p>I get this error:</p> <blockquote> <p>Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'www-data'@'localhost' (using password: YES) in /var/www/hosts/dj/connect.php on line 3 unable to connect to database: Access denied for user 'www-data'@'localhost' (using password: YES)</p> </blockquote> <p>I can only guess what is happening here: I think www-data is a username for apache. Upon the database connection, the credentials being passed in to mysql are not those of my database user, but rather apache's own credentials. Is that what is happening here?</p> <p>How do I pass in the credentials I've defined for my user ?</p> <p>edit: By the way - I do have credentials in the variables $db_hostname, $db_username, $db_password. </p> <p>they are passed in by another file using require_once. If that file can't be found, then I get an error. So, I know that my username and password are being used by my script.</p> <p>Both my scripts can be seen here: <a href="http://pastebin.com/MUneLEib" rel="nofollow noreferrer">http://pastebin.com/MUneLEib</a></p> # <p>Solved:</p> <p>Thanks guys.</p> <p>A couple of you pointed out that I had coded carelessy.</p> <p>Also, I was particularly pleased by Neo's answer: he told me why the username of the owner of the apache process was being used.</p> <p>:)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload