Jump to content

Recommended Posts

Hi guys,

I want to connect to my mysql db from another server, but I get this error:

[code]I cannot connect to the database because: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)[/code]

Here it the code:
[code]<?php
$dbh = mysql_connect ("host", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_name");
?>[/code]

Thanks for any help,
George
Link to comment
https://forums.phpfreaks.com/topic/33578-mysql-connect-question/
Share on other sites

Thanks Ted,

I've tryed everything but result is the same... :(

<?php
$dbh = mysql_connect ("10.10.10.100:19663", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_name");
?>

19663 - this is a REMOTE_PORT I've found in phpinfo of the server i want to connect
you welcome George, most hosts provide their users a user panel, most user panels will have some file manager of their sort as well as a mysql manager of their sort. If you are not sure about where it is, you can always email your support for it.
Ted
Don't bother with the port just yet.  I connect to a remote server with this code:

[code]<?php
$user="my_username";
$pass="my_password";
$host="xxx.xxx.xxx.xxx"; // I just use the server IP address here, no port as it's the standard one (3306)
$dbname="gallery";

$connection = mysql_connect($host, $user, $pass);
if (!$connection){
  echo "Could not connect to database: " .mysql_error();
}
$founddb = mysql_select_db($dbname, $connection);
if (!$founddb){
  echo "Could not find DB: " .mysql_error();
}
?>[/code]

Regards
Huggie
Thanks Huggie, but I get this error:
[code]Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/n/y/c/nycstore/html/n/index.php on line 3[/code]

Do I have to change something in php.ini?
I think i'm having a similar problem to this. I'm currently in the process of moving all the sites I host from an old server to a new one. The problem is that the new server has PHP 5.1.6 installed, whereas the old one used PHP 4.4.4.

When I have transferred all the dbs and all web files I am getting errors with every site that uses php/mysql. I am aware of the register_globals change in the latest version of php and I have now managed to get this turned on so that can't be the problem.

Here's an example problem, bearing in mind I have merely copied the web pages and database from one server to another it 'should' work the same, i.e. successfully! Here's an error:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/vhost/DOMAIN.co.uk/html/database.php on line 7
Could not connect to database: Lost connection to MySQL server during query
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/vhost/DOMAIN.co.uk/html/database.php on line 11
Could not find DB: Lost connection to MySQL server during query

It appears to be struggling to connect to the database despite me using the same code to connect!

Not sure what to do to resolve this.
Cheers Rich, i'll take a look at that and see if I can get round it. If I can all my problems are solved! My host company gave me access to SSH so that I could login and change the PHP settings to more or less match those on our old server so hopefully i'll be alright (otherwise I have some late nights ahead of me doing some serious re-coding!)

Happy New Year - have you had any emails from me? Sent you a couple I think.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.