Page 1 of 1

Need help to connect to my MySQL database.

Posted: Thu Dec 18, 2008 12:27 am
by refais23
Hi,

I need some help to connect to my MySql database...i get the following error:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on...

I'm trying to connect to a host through a port.

If i try to connect to one of my other databases with the same code then i connect without any errors.

Code: Select all

 
<?php
 
$host = "some.where.com:3456";
$user = "user1";
$pass = "pass1@$";
$dbName = "myDb";
 
function connect()
{
     $db = mysql_connect($GLOBALS["host"],$GLOBALS["user "],$GLOBALS["pass "]);
     if ($db == false)
         die("Error while connecting...");
     mysql_select_db($GLOBALS['dbName"]), $db)
         or die("Error...");
     return $db;
}
 
?>
 
Is there any problem with this...

could someone please help?

Re: Need help to connect to my MySQL database.

Posted: Thu Dec 18, 2008 4:13 am
by burgessm
The code appears to be perfectly fine to connect to a MySQL database. However just to try a diagnostic i would change the code to:

Code: Select all

<?php
 
$host = "some.where.com:3456";
$user = "user1";
$pass = "pass1@$";
$dbName = "myDb";
 
function connect()
{
     $db = mysql_connect($host, $user, $pass);
     if ($db == false)
         die("Error while connecting...");
     mysql_select_db($dbName), $db)
         or die("Error...");
     return $db;
}
 
?>
It shouldn't make any difference but i have had this problem before where it connects to some database but not to others. I tried this and it solved the problem.

Happy Coding!
-Burgessm