2

When I run the script below with the added line,

$count = 1;

I get a value of 1 on the screen, but when I take that line out I don't get get anything at all. tried moving it above the $count=mysql_num_rows($result); and I still didn't get a value.

$sql="SELECT EMAIL FROM CUSTOMER WHERE email='$myemail' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

$count = 1;
echo $count;

What am I doing wrong here? I have never used PHP until now. The error is:

Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)
4
  • 1
    Change the second line to $result=mysql_query($sql) or die( mysql_error() ); so you'll see any SQL error messages. Commented Apr 29, 2012 at 14:51
  • Seems like your connection is failing Commented Apr 29, 2012 at 14:54
  • Thanks, I used die( mysql_error() ); and it reported this error. I am using the same connection on a different page and it works fine. Commented Apr 29, 2012 at 14:56
  • Please stop writing new code with the ancient mysql_* functions. They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial. Commented Apr 29, 2012 at 15:01

3 Answers 3

1

This means that your MySQL server socket (/var/run/mysqld/mysqld.sock) is either missing or corrupt.

It could also mean that MySQL service is not working right, try restarting in SSH using:

$ service mysqld restart

If it says the service is missing, then say:

$ service mysql restart
Sign up to request clarification or add additional context in comments.

1 Comment

I have another page that works fine on the database, I am in the process of redoing the current page based on the working one.. hopefully it solves the problem.
0

I would guess at an a error with your SQL query (var_dump($count); would return false in this case).

To check this, I would do 2 things:

  • After your query do if(!$result) echo mysql_error( ); - this will show you any errors that happen while talking to the database
  • To check your SQL is being formed correctly, create it in a variable (e.g. $sql = "SELECT email ...";) and echo it out.

EDIT: Ahh just seen the update - it's a connection issue. Check that your mysql_connect( ) has the right host, username & password. Otherwise it could be a problem on your system (e.g. firewall or similar)

EDIT 2: As has been rightly pointed out, mysql_connect details would cause a different connection error to the one you're seeing. I've had a quick Google for it, and this cropped up http://lists.mysql.com/mysql/204035. Not sure it'll be any use as I've not read it through, but it does describe some steps for the solving this problem on someone else's system.

2 Comments

If the mysql_connect function had invalid information, it would not return a socket error.
Right y'are, I'll get rid of that bit!
0

When you can't connect successfully to the database, return value from mysql_query function ($result) would not be a valid value. so when you give it to mysql_num_rows function, it fails & returns FALSE value, which has no visual effect on output screen!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.