Jump to content

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'


mrooks1984

Recommended Posts

hi all, i have a test server (newest xampp) and the code works fine, as soon as i upload to 1and1 (they use apachi, php and mysql) i get this message: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

i have double checked username and passwords, had a look on google, contacted there support with no luck yet.

i am wondering if its a mysql or php version problem, so hoping someone knows when the following code with classes etc was added or if someone knows how to fix it i be really greatful.

heres some of the code i am using

class cyberglide {

var $host;
var $username;
var $password;
var $db;

function connect() {
	$con = mysql_connect($this->host, $this->username, $this->password) or die (mysql_error());
	mysql_select_db($this->db, $con) or die(mysql_error());
}

function get_top() {

        if (isset($_GET['page']))
{
 		$page = $_GET['page'];
	// Display Page.
                $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';	
                    echo '<p>' . $row['body'] . '</p>';
		}			
	}		
        else
        {
                //Show Home Page
                $sql = "SELECT title,body FROM content WHERE page = 'home' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';
                    echo '<p>' . $row['body'] . '</p>';  
                }
	  }
}

	function get_left() {

        if (isset($_GET['page']))
{
 		$page = $_GET['page'];
	// Display Page.
                $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';	
                    echo '<p>' . $row['body'] . '</p>';
		}			
	}		
        else
        {
                //Show Home Page
                $sql = "SELECT title,body FROM content WHERE page = 'home' AND location = 'left' AND disabled = 'no' ORDER BY id";
                $res = mysql_query($sql) or die (mysql_error());
                while($row = mysql_fetch_assoc($res)){
				echo '<h1>' . $row['title'] . '</h1>';
                    echo '<p>' . $row['body'] . '</p>';  
                }
		}
}
}//Ends Our Class

db file

//Setup Our Connection Vars
$obj->host = 'localhost';
$obj->username = 'root';
$obj->password = '';
$obj->db = 'db361371865';

	//Connect To Our Database
$obj->connect();

many thanks all.

Link to comment
Share on other sites

This is unrelated to php.  If it's not an entirely different host that you need to specify, then the username of 'root' is a likely culprit, as you would probably not be connecting to mysql as the root user, but rather a user which has been given rights to whatever database has been configured on your host.  Often this is handled through some type of web interface and they usually have instructions there for what the strings need to be in the same location that lets you create databases and users.

Link to comment
Share on other sites

hello, thanks for your responce no the mysql server is not the localhost and no i am not connecting using root,

i am trying to learn php and was told this is a better way of creating a blog related site.

could you point me in the right direction of what i would need to do to the db file to make it work with remote mysql servers.

thanks again, mike

Link to comment
Share on other sites

hello, thats what i had done double checked the details and they are correct, but got the message, i left the database file like that as dident want to post my actual username password etc on a public forum.

i have to keep looking to try find out why its not working, thanks again

Link to comment
Share on other sites

localhost refers to the local machine. If you are trying to connect to a remote server obviously you wouldn't use 'localhost' by the hostname or ip address of that remote machine.

 

If you are trying to connect to a server on the local machine the error you are receiving can often be fixed by using the local ip address 127.0.0.1 instead of 'localhost'.

Link to comment
Share on other sites

the actual db file i am using on the 1and1 server is this i have changed username and password.

the one on my local xampp test server is the one at the top of the page with localhost

//Setup Our Connection Vars
$obj->host = 'db1222.oneandone.co.uk';
$obj->username = 'username';
$obj->password = 'password';
$obj->db = 'db361371865';

	//Connect To Our Database
$obj->connect();

hope this helps, thanks again.

Link to comment
Share on other sites

got to the bottom of it as soon as i moved the contents of the db file to the home.php and replaced the inc db code it works.

so know i need to figure out how i can get it to work using the databse file as i dont want username passwords db names etc on the home page. any ideas i be greatful, thanks all

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.