can't connect to mysql

#1
Hi i'm trying to create a simple comment feature to and have an index.html

<html>
<head><title>Test Page</title></head>
<body>
<h2>Data Collection</h2><p>
<form action="comments.php" method="post">
Your Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Location: <input type="text" name = "location"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

and a comment.php

<?
$name=$_POST['name'];
$email=$_POST['email'];
$location=$_POST['location'];
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
Print "Your information has been successfully added to the database.";
?>

I get the error "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)"
I went in my.conf and the socket is pointed to /var/lib/mysql/mysql.sock and i tried copying the sock to /tmp but i still get this error. Is this a litespeed error or a php error?
 

webizen

Well-Known Member
#2
that means /tmp/mysql.sock is defined as default socket (either defined in php.ini or built-in mysql defaults) in your php config. Verify in phpinfo() page. Not an issue with litespeed.

when copy the socket (not a regular file), you should do ln instead cp. make sure /var/lib/msyql/mysql.sock exists (server started)
Code:
ln /var/lib/mysql/mysql.sock /tmp
another work around is to define connection socket in your code as follows:
Code:
mysql_connect('localhost:/var/lib/mysql/mysql.sock', "root", "password") or die(mysql_error());
 
Last edited:
Top