mrooks1984 Posted March 30, 2011 Share Posted March 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/ Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194197 Share on other sites More sharing options...
mrooks1984 Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194198 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 Mike, There is not much more to it than providing the write, host, user, password and database. Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194203 Share on other sites More sharing options...
mrooks1984 Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194217 Share on other sites More sharing options...
trq Posted March 30, 2011 Share Posted March 30, 2011 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'. Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194219 Share on other sites More sharing options...
gizmola Posted March 30, 2011 Share Posted March 30, 2011 http://faq.1and1.com/applications/mysql_administration/2.html Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194222 Share on other sites More sharing options...
mrooks1984 Posted March 30, 2011 Author Share Posted March 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194223 Share on other sites More sharing options...
mrooks1984 Posted March 30, 2011 Author Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232152-cant-connect-to-local-mysql-server-through-socket-varrunmysqldmysqldsock/#findComment-1194236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.