2013-10-12 56 views
0

我感动从旧体制到新的我的网页,我有现在的问题与到数据库的连接。版本是:Mysql 5.1.67和phpMyadmin 3.4.3.2。哪里有问题?无法连接到数据库服务器

警告:mysqli的:: mysqli的()[mysqli.mysqli]:(HY000/2002):

网站上

无法通过套接字连接到本地MySQL服务器“的/ var/lib中/ MySQL的在第13行 /home/do031500/www_root/lib/database.inc.php /mysql.sock”(2)无法连接到数据库服务器

database.inc.php:

class CDatabase { 

public $Connected = false; 
private $Mysqli; 
public $Result; 

// Connect to database server 
function Connect() { 
    global $DatabaseSupport; 
    if ($DatabaseSupport) { 
    $this->Mysqli = new mysqli(dbServer, dbUser, dbPassword, dbDatabase); 
    if (mysqli_connect_errno()) { 
     $this->Connected = false; 
     Terminate("Could not connect to database server"); 
     } else { 
     $this->Connected = true; 
     $this->Mysqli->autocommit(FALSE); 
     $this->Mysqli->set_charset("utf8"); 
    } 
    } 
} 

// Disconnect from server 
function Disconnect() { 
    if ($this->Connected) { 
     $this->Mysqli->close(); 
    } 
} 

// Execute query 
function Query($Query) { 
    $this->Result = false; 
    if ($this->Connected) { 
      $this->Result = $this->Mysqli->query($Query, MYSQLI_STORE_RESULT); 
     if (!$this->Result) 
     Terminate('Invalid query: '.$this->Mysqli->error); 
     } 
    return $this->Result; 
} 

// Close query query 
function Close($Datalink) { 
    if ($this->Connected) { 
    mysqli_free_result($Datalink); 
     } 
} 

// Commit 
function Commit() { 
    if ($this->Connected) 
    $this->Mysqli->Commit(); 
} 

// Rollback 
function Rollback() { 
    if ($this->Connected) 
    $this->Mysqli->Rollback(); 
} 

// GetRecordCount 
function RecordCount($DataLink) { 
    if ($this->Connected) 
      return $DataLink->num_rows; 
    else 
    return 0; 
} 

// Get last RecordID 
function GetLastRecordID() { 
    if ($this->Connected) 
      return $this->Mysqli->insert_id; 
    else 
    return false; 
} 

// Get next line from query 
function GetNextLine($Datalink = NULL) { 
    if ($this->Connected) { 
      if ($Datalink != NULL) 
      $this->Result = $Datalink; 
     return $this->Result->fetch_array(MYSQL_ASSOC); 
     } 
} 

// Execute query and return first line 
function QueryFirstLine($Query) { 
    if ($this->Connected) { 
      if ($this->Result = $this->Query($Query)) 
      return $this->Result->fetch_array(MYSQL_ASSOC); 
     } 
} 

// GetField list for current query 
function GetFieldList($Datalink = NULL) { 
    if ($this->Connected) { 
      if ($Datalink != NULL) 
      $this->Result = $Datalink; 
      //$FieldsCount = $this->Result->field_count; 
    $List = NULL; 
    while ($Finfo = $this->Result->fetch_field()) { 
      $List[] = $Finfo->name; 
    } 
     return $List; 
     } 
} 

// encode value 
function EncodeValue($Value) { 
    return $Value; 
} 

// move item 
function MoveItem($SQL, $RecordID, $Forward, $TableName) { 
    $Query = $this->Query($SQL); 
    while ($Line = $this->GetNextLine($Query)) { 
      $List[] .= $Line['RecordID']; 
    } 
    $HasMove = false; 
    for ($i = 0; $i < count($List); $i++) { 
    if ((!$HasMove) && ($List[$i] == $RecordID)) { 
     if ($Forward) { 
     if ($i < count($List)-1) { 
      $a = $List[$i+1]; 
      $List[$i+1] = $List[$i]; 
      $List[$i] = $a; 
      $i++; 
     } 
     } else { 
     if ($i > 0) { 
      $a = $List[$i-1]; 
      $List[$i-1] = $List[$i]; 
      $List[$i] = $a; 
     } 
     } 
     $HasMove = true; 
    } 

    } 

    $cnt = 1; 
     foreach ($List as $Key=>$Value) { 
     $this->Query("update $TableName set OrderNo='".$cnt."' where RecordID='$Value'"); 
    $cnt++; 
    } 
     $this->Commit(); 
} 


} 
+0

'dbServer'是不是一个有效的PHP变量。使用'$' – cgTag

+0

嘿,没有问题。问题是我有关于数据库服务器的更新信息,地址为dbserver,用户名,密码。现在它工作 – patrik87

回答

0

初始人们认为这是由于你的一个连接变量。你是否仔细检查了你的新服务器的所有信息都正确?服务器,端口,用户名,密码,数据库,表?

+0

我有服务器地址,用户名,数据库和表,但我需要更新那里吗?或者它是自动的? (旧的和新的DB之间的不同密码) – patrik87

+0

是的......如果你的mysql服务器的密码在服务器之间不同,你需要更新它们。我不知道在程序中设置这些变量的位置(dbServer,dbUser,dbPassword,dbDatabase),但是如果新服务器上的设置不同,它们将需要更改。 – kevindeleon

+0

谢谢。我没有做这个网站,所以它会很难。 – patrik87

相关问题