Need help to connect to my MySQL database.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
refais23
Forum Newbie
Posts: 1
Joined: Thu Dec 18, 2008 12:14 am

Need help to connect to my MySQL database.

Post 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?
burgessm
Forum Newbie
Posts: 5
Joined: Thu Dec 18, 2008 4:09 am
Location: Andover, UK

Re: Need help to connect to my MySQL database.

Post 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
Post Reply