0

I have the same issues described here: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

but, I am certain my credentials are in correctly.

I am using a hosting company and ( tsohosts.co.uk ) and assume that MySql starts automatically.

I'm not sure what to check next. Is there any way to get more details about the "or die" phrase.

Here is my code:

$dbc = mysqli_connect("localhost","CorrectUser","CorrectPass",CorrectDB") 
or die ('No can do');

$query = "INSERT INTO users(firstName,lastName,username,password,email,dateJoin,school,level) " 
." VALUES ('value','value','value','value','value', NOW(),'value','Not yet set')";

mysqli_query($dbc, $query) or die ("I couldn't get it in!"); 

mysqli_close($dbc);
?>

and the error is

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in ../testdb.php on line 16
No can do

Do I have to do something else start MySQL within the PHP script?

Community
  • 1
  • 1
Russell
  • 655
  • 2
  • 9
  • 21
  • 3
    If you are using a hosting company, then it's unlikely the server address will be localhost, check with them for the correct address. – The Blue Dog Mar 23 '14 at 21:45
  • Thanks for reading - yes this is what it turned out to be. Fixed. – Russell Mar 23 '14 at 21:47
  • The Blue Dog is correct. With tsohost, the mysql server is on a different address and this will most likely vary account to account, you should be able to check the support article. – nixblu Mar 23 '14 at 21:48

1 Answers1

0

You missed a double quote in $dbc try this

$dbc = mysqli_connect("localhost","CorrectUser","CorrectPass","CorrectDB") 
or die ('No can do');

You put a double quote and a fullstop at the wrong place in $query it should be like this

$query = "INSERT INTO users(firstName,lastName,username,password,email,dateJoin,school,level)
 VALUES ('value','value','value','value','value', NOW(),'value','Not yet set')";

Also remove $dbc from the mysqli_query() function and also escape the single quote in the die() function like so:

mysqli_query($query) or die ("I couldn't get it in!");
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Tabby
  • 388
  • 1
  • 11
  • 3
    `mysqli_error()` and not `mysql_error()` --- `mysqli_*` and `mysql_*` fucntion do not mix; ***ever.*** Plus, no need to escape single quotes inside double quotes. Change `"I couldn\'t get it in!"` to `"I couldn't get it in!"` – Funk Forty Niner Mar 23 '14 at 22:11