2

everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla

  • uploaded all the files to the server side public html and tried to run the file in browser by using: my_school_link/my_username/

and I have this error

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on line 3 and this is my connect.php file.

<?php

mysql_connect('host_name', 'user_name', 'password');

mysql_select_db('my_database_name');

?>

I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*

and I have tried the following

  • view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
  • have entered the correct hostname, username and password
  • run as admin
  • checked if mysql is running ( it is so is Apache)
  • MySQL socket specified in php.ini was never edited so it is in default mode
  • cant locate mysql config file, or my.cnf, or etc folder

What could the problem be? Please if anyone could help me, please tell me what's wrong.

Please provide a step-by-step guide. and file extensions if need to save files....

Is there any additional things i can add to help anyone understand my problem better? if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.

user2944454
  • 31
  • 1
  • 3
  • Is MySQL server running? – Hanky Panky Nov 01 '13 at 10:39
  • Hi friend check this link to get answer:- http://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38 – vikas mishra Nov 01 '13 at 10:45
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Nov 01 '13 at 10:53
  • 1
    You say you've checked that MySQL is running, but you mention both XAMPP and a server you connect to with FTP. Have you checked that MySQL is running on the same machine as the one running the webserver you are requesting the files from? – Quentin Nov 01 '13 at 11:08
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Nov 01 '13 at 11:14
  • thank you to all!! :D my problem has been solved... :) yup thank you Hanky 웃 Panky! thank you vikas mishra! i didnt check the mysql thank you quentin! thank you h2ooooooo – user2944454 Nov 01 '13 at 13:11
  • you should use netbeans to develop php content – Hydroid Mar 07 '14 at 18:23

1 Answers1

0

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on line 3 and this is my connect.php file.

This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)

If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock

Another reason may be that you are using the wrong host name while connect.

Don't use mysql_connect it is deprecated and instead you should use MySqli

TheBosti
  • 1,354
  • 13
  • 19