Swiching to go daddy as host need help with mySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesuper
    New Member
    • Mar 2010
    • 1

    Swiching to go daddy as host need help with mySQL

    I reciave this messege when i type in my domain name
    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/s/u/p/superwholesale/html/includes/functions/database.php on line 19
    Unable to connect to database server!
    the domain name of my site is <<snipped>> but i am using <<snipped>> to test if everything if is in correct order before i point <<snipped>> to my files at<<snipped>>

    This is the Database.php that i am editing i need help to make it work sins i dont know anything about this .

    Code:
     <?php
    
    /*
    
      $Id: database.php,v 1.17 2002/06/05 11:16:03 hpdl Exp $
    
      osCommerce, Open Source E-Commerce Solutions
    
      http://www.oscommerce.com
    
      Copyright (c) 2002 osCommerce
    
      Released under the GNU General Public License
    
    */
      
    
    This is line 19<     function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {               >This is line 19
    
        global $$link;
    
        if (USE_PCONNECT == 'true') {
    
          $$link = mysql_pconnect($server, $username, $password);
    
        } else {
    
          $$link = mysql_connect($server, $username, $password);
        }
    
        if ($$link) mysql_select_db($database);
    
        return $$link;
      }
      function tep_db_close($link = 'db_link') {
    
        global $$link;
    
        return mysql_close($$link);
      }
    
      function tep_db_error($query, $errno, $error) { 
    
        die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>');
    
      }
    
      function tep_db_query($query, $link = 'db_link') {
    
        global $$link;
    
        if (STORE_DB_TRANSACTIONS == 'true') {
    
           error_log("QUERY " . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    
        }
    
        $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
    
        if (STORE_DB_TRANSACTIONS == 'true') {
    
           $result_error = mysql_error();
    
           error_log("RESULT " . $result . " " . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
    
        }
        return $result;
      }
    
      function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
        reset($data);
        if ($action == 'insert') {
          $query = 'insert into ' . $table . ' (';
          while (list($columns, ) = each($data)) {
            $query .= $columns . ', ';
          }
          $query = substr($query, 0, -2) . ') values (';
          reset($data);
          while (list(, $value) = each($data)) {
            switch ((string)$value) {
              case 'now()':
                $query .= 'now(), ';
                break;
              case 'null':
                $query .= 'null, ';
               break;
              default:
                $query .= '\'' . tep_db_input($value) . '\', ';
                break;
            }
          }
          $query = substr($query, 0, -2) . ')';
    
        } elseif ($action == 'update') {
    
          $query = 'update ' . $table . ' set ';
    
          while (list($columns, $value) = each($data)) {
    
            switch ((string)$value) {
    
              case 'now()':
    
                $query .= $columns . ' = now(), ';
    
                break;
    
              case 'null':
    
                $query .= $columns .= ' = null, ';
    
                break;
    
              default:
    
                $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
    
                break;
            }
          }
          $query = substr($query, 0, -2) . ' where ' . $parameters;
        }
        return tep_db_query($query, $link);
      }
      function tep_db_fetch_array($db_query) {
    
        return mysql_fetch_array($db_query, MYSQL_ASSOC);
      }
      function tep_db_num_rows($db_query) {
    
        return mysql_num_rows($db_query);
      }
      function tep_db_data_seek($db_query, $row_number) {
    
        return mysql_data_seek($db_query, $row_number);
      }
      function tep_db_insert_id() {
    
        return mysql_insert_id();
      }
    
      function tep_db_free_result($db_query) {
    
        return mysql_free_result($db_query);
      }
      function tep_db_fetch_fields($db_query) {
        return mysql_fetch_field($db_query);
      }
      function tep_db_output($string) {
    
        return stripslashes($string);
      }
      function tep_db_input($string) {
    
        return addslashes($string);
      }
      function tep_db_prepare_input($string) {
    
        if (is_string($string)) {
    
          return trim(stripslashes($string));
    
        } elseif (is_array($string)) {
    
          reset($string);
    
          while (list($key, $value) = each($string)) {
    
            $string[$key] = tep_db_prepare_input($value);
          }
          return $string;
        } else {
          return $string;
        }
      }
    ?>



    Go daddy gave me these Guideline to go by


    Code:
    <?php
    //Sample Database Connection Syntax for PHP and MySQL.
    
    //Connect To Database
    
    $hostname="your_mysqlserver.example.net";
    $username="your_dbusername";
    $password="your_dbpassword";
    $dbname="your_dbusername";
    $usertable="your_tablename";
    $yourfield = "your_field";
    
    mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
    mysql_select_db($dbname);
    
    # Check If Record Exists
    
    $query = "SELECT * FROM $usertable";
    
    $result = mysql_query($query);
    
    if($result)
    {
    while($row = mysql_fetch_array($result))
    {
    $name = $row["$yourfield"];
    echo "Name: ".$name."<br>";
    }
    }
    ?>
    Last edited by Atli; Mar 17 '10, 10:48 AM. Reason: Added [code] tags and removed links to commercial sites. (They aren't relevant to this in any case)
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    This error is not a problem with your code, but rather with your server. It usually indicates that the MySQL server is either not running, or incorrectly configured.

    Basically, Linux boxes, rather than use typical TCP/IP connections, use sockets when connecting to a local MySQL server. - If MySQL is not running, or if the socket file is either not accessible or not located where it is supposed to be, then you get this error.

    You should contact your host and ask them about this. You will most likely need administrative access to your server to fix this.

    One thing I should mention, though.
    If you are indeed connecting to a local MySQL server, the value of "$hostname" in your guideline test code should be "localhost" . If it is not, this socket error makes even less sense, since it shouldn't be using a socket for remote connections.

    Comment

    Working...