Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...