Forum Moderators: coopster

Message Too Old, No Replies

How to write php code to take "localhost"adn

localhost_name user_name password

         

backpacker

3:39 am on Nov 24, 2005 (gmt 0)

10+ Year Member



How to write a piece of php code to take the "localhost","username","password".I am newer to php.Thanks.

backpacker

3:42 am on Nov 24, 2005 (gmt 0)

10+ Year Member



I really meant that 'mysql_host', 'mysql_user', 'mysql_password'.

Anyango

5:42 am on Nov 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If i understood the question correctly, this should be it.


$sHostName="localhost";
$sUserName="username";
$sPassword="password";

mysql_connect($sHostName,$sUserName,$sPassword) or die (mysql_error());

backpacker

6:40 am on Nov 24, 2005 (gmt 0)

10+ Year Member



Thank you very much for helping.
I mean that I happened to do not know my MySQL server's mysql_host,mysql_user and mysql_password,now I want extract the message from the connecting to MySQL server.

I coded it as:
<?php
$sHostName="localhost";
$sUserName="username";
$sPassword="password";

mysql_connect($sHostName,$sUserName,$sPassword) or die (mysql_error());
?>

I tested it and got browser message:
"Warning: mysql_connect(): Access denied for user 'username'@'localhost' (using password: YES) in /var/www/html/test2.php on line 6
Access denied for user 'username'@'localhost' (using password: YES)"

Anyango

7:32 am on Nov 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes , this is because your mysql server does not have an account "username" with password = "password".

you'll have to provide a valid mysql user details to get connected to mysql server, if its a new installation try username = "root" and password = "" (blank).

or use phpMyAdmin etc to create another username for yourself and then provide that username and password in your code

;)