gozari Posted July 29, 2011 Share Posted July 29, 2011 hi, I'm a newbe in php and mysql. I have a simple database on mysql and i wrote a php script to manipulate the database. But, when i run it on freehostingcloud i get this error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) I ran the same script on another host and it worked. may you please give me some advice to solve the problem? thanks Quote Link to comment Share on other sites More sharing options...
Tjoene Posted July 29, 2011 Share Posted July 29, 2011 Try this script to connect to your database on the other host, <?php $host = 'example.com'; $user = 'MySQL_user'; $password = 'MySQL_Password'; $link = mysql_connect($host, $user, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?> More info can be here. Quote Link to comment Share on other sites More sharing options...
mikenyc Posted August 1, 2011 Share Posted August 1, 2011 I`m not so sure that you are new to php, because.. using mysql sockets is not some newbe thing to do but that again, if you are new, the code "Tjoene" should works just fine.. you need to add this command in bold. $link = mysql_connect($host, $user, $password); mysql_select_db("name_of_your_database"); if (!$link) { and for newbies much better site for learning is http://www.w3schools.com/php/default.asp and when you get some experience with PHP you can go to http://www.php.net .. much more information but for non experienced programmer it can be a little confusing.. cheers Quote Link to comment Share on other sites More sharing options...
PenTester Posted August 1, 2011 Share Posted August 1, 2011 W3schools is best place for newbie. They have tutorial for php,asp,javascript,css,html....etc. Quote Link to comment 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.