Jump to content

PHP to MYSQL connection problem


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...