Jump to content

Mysql connect question


Gruzin

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
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.