QLSTATE[HY000] [2002] Can't connect to local MySQL server through socket

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AngelinaB
    New Member
    • Jan 2010
    • 9

    QLSTATE[HY000] [2002] Can't connect to local MySQL server through socket

    It's my first time learn hosting for my final assignment
    i got this error

    Code:
    Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' in /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/library/Zend/Db/Adapter/Pdo/Abstract.php:143 Stack trace: #0 /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/library/Zend/Db/Adapter/Abstract.php(414): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/library/Zend/Db/Adapter/Pdo/Abstract.php(220): Zend_Db_Adapter_Abstract->query('select sum(JumD...', Array) #2 /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/library/Zend/Db/Adapter/Abstract.php(660): Zend_Db_Adapter_Pdo_Abstract->query('select sum(JumD...', Array) #3 /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/application/models/DataCart.php(30): Zend_Db_Adapter_Abstract->fetchRow('select sum(JumD...') #4 /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/application/contro in /home/vol13/000space.com/space_4876282/htdocs/CakeShopOnline/library/Zend/Db/Adapter/Pdo/Abstract.php on line 143
    I have no idea what should i do
    I get no error when i'm on local..
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    It might be that you don't have the database connection credentials set correctly for the hosting site.

    You probably have settings like: localhost on your home system and the external host might need to point to an external MySQL machine. If MySQL is on an external box, you can't specify using UNIX sockets - you have to use TCP/IP.

    As you might imagine, you'll have to do some digging and this is the nature of the beast that you've elected to get involved with.
    [Computers can be a REAL PAIN! ;-)]

    It also might be that mysqld.sock is in a different location on the hosting server or it's named something else.

    If you have SSH access (and you know how to use it) try this command:
    find / -iname "mysql*.soc k".

    Or you can try this to see how MySQL is actually connected.
    netstat -ln | grep mysql

    I'm running a CentOS box locally and it's located in: /var/lib/mysql/mysql.sock. Many times it's in the /tmp/ directory.

    You can also ask the hosting company's tech support - they may have an answer because this is a common problem.

    There are a number links you can find by Googling that address this issue.
    One of possible interest is: http://lenss.nl/2009/06/zend_db-conn...-mysql-socket/

    Finally, Zend's adapter has had known issues in the past, but I assume you're setup is up to date.

    Comment

    • AngelinaB
      New Member
      • Jan 2010
      • 9

      #3
      uhm,
      i'll try now >.<
      thank you so much ^^


      but my web use database to show catalog too
      and the catalog can shows normally just like in local
      i'm really confuse x__x

      Comment

      • dgreenhouse
        Recognized Expert Contributor
        • May 2008
        • 250

        #4
        Originally posted by AngelinaB
        uhm,
        i'll try now >.<
        thank you so much ^^


        but my web use database to show catalog too
        and the catalog can shows normally just like in local
        i'm really confuse x__x
        I'm unclear on what you're asking in the above...

        Comment

        • Niheel
          Recognized Expert Moderator Top Contributor
          • Jul 2005
          • 2432

          #5
          Angelina please write in complete sentences with proper punctuation so that other members can understand what you are trying to say.
          niheel @ bytes

          Comment

          • AngelinaB
            New Member
            • Jan 2010
            • 9

            #6
            sorry for my bad english
            I was sick so could not think clearly.

            I'm trying to say that my website using sql query to display the items in the catalog and I did not get an error like the login process ( error above)

            once again sorry for my bad english.

            Comment

            • dgreenhouse
              Recognized Expert Contributor
              • May 2008
              • 250

              #7
              AngelinaB,

              I don't know the particulars of your application; especially that which is related to the 'catalog', so it's impossible to advice you without more information.

              Can you explain a little about your course, what your trying to accomplish at this juncture in the class, what the requirements are, etc.?

              Best,

              Comment

              • AngelinaB
                New Member
                • Jan 2010
                • 9

                #8
                hi2..

                oc. i'll try to explain but i'm really sorry for my bad english..

                my final assignment is make an ecommerce website (study case)
                on my main page there are sections to login and recommended items.
                on recommended items I did the calculation of the database by looking for the best-selling items (and I do not get an error) but if I try to login I get an error as above.
                that's make me so confuse..

                btw thank you very much for your replies..
                I'm sorry I forgot to say thank you earlier

                Comment

                • dgreenhouse
                  Recognized Expert Contributor
                  • May 2008
                  • 250

                  #9
                  You obviously can connect to the database for doing the calculation, so... it might be that you're using a different connection modality to connect to the database when attempting the login...

                  Why don't you post some of the code; sans username and password?

                  Aren't you using he Zend abstraction layer?

                  As a matter of fact, post the code you use when connecting to do the calculation along with the code for logging in...

                  Try an online beautifier for the code and of course embed that in a [ code ] ... [ /code ] pair.

                  Beautifier - one of many:

                  Comment

                  • AngelinaB
                    New Member
                    • Jan 2010
                    • 9

                    #10
                    hi..

                    yes sir, i'll do..
                    this is my code for calculation
                    Code:
                    //controller
                    $sj= new DataTrans();
                    $jml = $sj->getjmlmostbuy();
                    $this->view->dmostbuy=$sj->getmostbuy2($jml);
                    
                    //model
                    function getjmlmostbuy() {
                    	$DB = new Zend_Db_Adapter_Pdo_Mysql($this->__construct());
                    	$sql="select max(A.cnt) as jml  ";
                    	$sql=$sql."from( Select sum(dt.JumDItemDTrans) as cnt  ";
                    	$sql=$sql."from DTrans dt, DItem di  ";
                    	$sql=$sql."where  dt.IdDItemDTrans = di.IdDItem ";
                    	$sql=$sql."group by (di.IdDItem)) as A ";
                    	$data=$DB->fetchRow($sql);
                    	return $data['jml'];
                    }
                    function getmostbuy($jml)
                    {
                    	$DB = new Zend_Db_Adapter_Pdo_Mysql($this->__construct());
                    	$sql="select di.IdDItem as iditem, di.NamaDITem as namaitem, di.UkuranDItem as ukuranitem, ";
                    	$sql=$sql."di.HargaDItem as hargaitem, sum(dt.JumDItemDTrans)as jumlahitem ";
                    	$sql=$sql."from DTrans dt, DItem di ";
                    	$sql=$sql."where di.IdDItem = dt.IdDItemDTrans ";
                    	$sql=$sql."and sum(dt.JumDItemDTrans) = '".$jml."'";
                    	$sql=$sql."group by di.IdDItem ";
                    	return $DB->fetchAll($sql);
                    }
                    and this is my code to loggin
                    Code:
                    //controller
                    if ($this->_request->isPost())
                    {
                    	Zend_Loader::loadClass('Zend_Filter_StripTags');
                    	$f = new Zend_Filter_StripTags();
                    	$user = $f->filter($this->_request->getPost('user'));
                    	$pass = $f->filter($this->_request->getPost('pass'));
                    	if (empty($user))
                    	{
                    		$this->view->message = 'Insert UserName.';
                    	} else
                    	{
                    		//check admin dlu
                    		Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
                    		$db = Zend_Registry::get('db');
                    		$authAdapter = new Zend_Auth_Adapter_DbTable($db);
                    		$authAdapter->setTableName('Admin');
                    		$authAdapter->setIdentityColumn('NamaAdmin');
                    		$authAdapter->setCredentialColumn('PassAdmin');
                    		// Set the input credential values to authenticate against
                    		$authAdapter->setIdentity($user);
                    		$authAdapter->setCredential($pass);
                    		// do the authentication
                    		$auth = Zend_Auth::getInstance();
                    		$result = $auth->authenticate($authAdapter);
                    		if ($result->isValid())
                    		{
                    			// success: admin
                    			$data = $authAdapter->getResultRowObject(null,'password');
                    			$auth->getStorage()->write($data);
                    			$identity = $auth->getIdentity();
                    			$_SESSION['nmuser']=$user;
                    			$_SESSION['username']=$user;
                    			$_SESSION['userid']=$id;
                    			$_SESSION['userlvl']=1;
                    			$this->view->link='logout';
                    			$this->view->links='Log Out';
                    			$this->view->index='1';
                    			$this->_redirect('/admin/admin');
                    		} else
                    		{
                    			//check user
                    			Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
                    			$db = Zend_Registry::get('db');
                    			$authAdapter = new Zend_Auth_Adapter_DbTable($db);
                    			$authAdapter->setTableName('User');
                    			$authAdapter->setIdentityColumn('EmailUser');
                    			$authAdapter->setCredentialColumn('PassUser');
                    			// Set the input credential values to authenticate against
                    			$authAdapter->setIdentity($user);
                    			$authAdapter->setCredential($pass);
                    			// do the authentication
                    			$auth = Zend_Auth::getInstance();
                    			$result = $auth->authenticate($authAdapter);
                    			if ($result->isValid())
                    			{
                    				$data = $authAdapter->getResultRowObject(null,'password');
                    				$auth->getStorage()->write($data);
                    				$identity = $auth->getIdentity();
                    				$id= $identity->IdUser;
                    				$DataUser = new DataUser ();
                    				$nmuser = $DataUser->searchnmuser($id);
                    				$_SESSION['username']=$user;
                    				$_SESSION['userid']=$id;
                    				$_SESSION['nmuser']=$nmuser;
                    				$_SESSION['userlvl']=2;
                    				$_SESSION['status']='login';
                    				if(isset($_POST['remember'])){
                    					setcookie("username", $_SESSION['username'], time()+60*60*24*60, "/");
                    					setcookie("userid", $_SESSION['userid'], time()+60*60*24*60, "/");
                    					setcookie("nmuser", $_SESSION['nmuser'], time()+60*60*24*60, "/");
                    					setcookie("userlvl", $_SESSION['userlvl'], time()+60*60*24*60, "/");
                    				}
                    
                    				//tampilkan bnyak item dari dtcart sesuai user d menu
                    				if ($_SESSION['userid'] != '') {
                    					$DataCart = new DataCart();
                    					$this->view->jumcart = $DataCart->getjumitemcart($_SESSION['userid']);
                    				}
                    				$this->view->link='logout';
                    				$this->view->links='Log Out';
                    				$this->view->index='1';
                    			} else
                    			{
                    				// failure: clear database row from session
                    				$this->view->message = 'Login Failed';
                    				$this->view->index='0';
                    			}
                    		}
                    	}
                    }
                    thank you for helping and sorry to bother you ..

                    how embarrassing me U__U
                    yes sir, have a lot of good rest

                    once again thank you for helping ..

                    Comment

                    • dgreenhouse
                      Recognized Expert Contributor
                      • May 2008
                      • 250

                      #11
                      A...

                      By the way... The [ code ] ... [ / code ] are without spaces...

                      I just showed it that way because it wouldn't show on the screen otherwise...

                      At least you're listening! :-)

                      I'm probably about to fade and will be back up in a few hours... I've been up for about 20 hours.

                      ----

                      At which line in the code are you getting error?

                      Comment

                      • AngelinaB
                        New Member
                        • Jan 2010
                        • 9

                        #12
                        i've edited it >.<

                        have a good rest sir..

                        Comment

                        • dgreenhouse
                          Recognized Expert Contributor
                          • May 2008
                          • 250

                          #13
                          Did you get it to work?

                          I'll be up for another 30 minutes...

                          By the way... It's cool you're learning MVC and Patterns...

                          If you like this work, you'll definitely find a good place in the field.

                          I know a bunch of great female geeks (Gerds) that are doing great stuff in the field.

                          Check this out: http://girldeveloper.com/ - Sara's really cool and funny ta boot!

                          Comment

                          • AngelinaB
                            New Member
                            • Jan 2010
                            • 9

                            #14
                            hmm my reply doesnt entered x__x'

                            no sir.. it's still error and the error on the above always bold in this code
                            Code:
                            /home/vol13/000space.com/space_4876282/htdocs/CakeSh
                            opOnline/library/Zend/Db/Adapter/Pdo/Abstract.php 
                            on line 143
                            I really don't know where is the wrong section and tomorrow is my final assignment trial, it's seems I had to demostrate through virtual host >__<

                            but I will keep trying to find out where my mistake because I was really curious so please help me again sir, it's alright?

                            yes sir, i do like php programming and it seems I still have to learn a lot..
                            so please guidance me :D

                            woghhhh that was a cool web.
                            if sara real sir? sara looks great >__<

                            Comment

                            • dgreenhouse
                              Recognized Expert Contributor
                              • May 2008
                              • 250

                              #15
                              Originally posted by AngelinaB
                              woghhhh that was a cool web.
                              if sara real sir? sara looks great >__<
                              Yep... Sara's the real McCoy

                              Comment

                              Working...