How do I connect to mysql from php ?

Posted by roberto on Stack Overflow See other posts from Stack Overflow or by roberto
Published on 2010-04-05T03:13:22Z Indexed on 2010/04/05 3:23 UTC
Read the original article Hit count: 414

Filed under:
|
|
|
|

Hi guys. I'm working through examples from a book on php/mysql development. I'm working on a linux/apache environment.

I've set up a database and a user. I attempt to connect with this line of code:

$db_server = mysql_connect($db_hostname, $db_username, $db_password);

I get this error:

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)

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?

How do I pass in the credentials I've defined for my user ?

© Stack Overflow or respective owner

Related posts about php

Related posts about apache