0

Any idea why the following code is not working

mysql credentials are correct, have verified from command line.

The second connection fails i.e., $conn1 . I am clueless !!!

$conn = mysql_connect($hostname,
$username, $password) 
    or die("Connecting to MySQL failed" . mysql_error());

$conn1 = mysql_connect($hostname,
$username1, $password1) 
    or die("Connecting to MySQL failed" . mysql_error());
2
  • 8
    Don't you have an error message that gives more information that "connection fails", as output of mysql_error ? Commented Mar 11, 2010 at 17:42
  • There is nothing syntactically wrong with your code above. Commented Mar 11, 2010 at 19:04

3 Answers 3

5

Test it with hardcoded values first to be sure...

//Connect to database from here
$link = mysql_connect("localhost", "dbaadmin", "sqlpassword");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
Sign up to request clarification or add additional context in comments.

Comments

2

have verified from command line.

There's so many questions here that you have not answered.

The command line where the PHP script is running?

The same chroot environment where the PHP script is running?

The OS user (not database user) is the same as the webserver runs as?

The hostname you are connecting to is on a seperate machine from where the PHP script (and the CLI) is running? (localhost will use a unix domain socket rather than a network socket)

...and just what is the error message you get?

C.

Comments

1

It's a guess, but is the second connection supposed to be to $hostname, or perhaps $hostname1 instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.