2010-01-08 54 views
2

我使用共享的Linux主機和我寫的一些PHP只會在我的數據庫服務器上無法正常工作。MySQL和PHP在本地工作,而不是在GoDaddy

編輯:

我解決了這個問題。我不小心從配置文件中刪除了「數據庫」連接變量。哇。這真是愚蠢的我。

編輯:

由於不工作,我的意思是我無法讀取數據庫。我已經搞混了,知道數據庫正在運行,並且當我修改密碼變量時,我得到了「拒絕訪問」。此外,在本地主機上,密碼是不同的,它的工作原理。編輯2: 我現在正在處理一個示例腳本。它現在顯示一個空白頁面。至少沒有錯誤...我將密碼更改爲字母數字。我不使用'localhost'。

編輯3:使用正確的密碼和服務器信息,我使用mysql_error()得到以下錯誤。我沒有在數據庫網址中使用前導http://。

無法通過套接字 '/var/lib/mysql/mysql.sock'(2)

編輯4連接到本地MySQL服務器:

這裏是我的連接code.Please注意nl()report()是分別迴應換行符和診斷消息的預定義函數。連接變量位於上面包含的外部文件中。我已經檢查過 - 這些內容工作得很好。

////////////////////////////// 
// Connect to the database ///////////////////////////////////////// 
////////////////////////////// 

//report - Attemting to establish connection ... 
report(4); 

//// 
//Step 1) Set connection in variable 
//// 

$conn = mysql_connect($server, $user, $pass); 

//// 
// Step 2) Verify the connection 
//// 

if(!$conn){ 
    //report - failed, see next line... 
    report(5); 
    //report - FATAL ERROR: Check database name, username and password. 
    report(9);  
}else{ 
    //report - done! 
    report(7); 
} 

//report - Selecting database ... 
report(6); 

//// 
// Step 3) Select the database 
//// 

$db_select = mysql_select_db($database); 

//// 
// Step 4) Verify successful selection 
//// 

if(!$db_select){ 
    //report - failed, see next line... 
    report(5); 
    //report - FATAL ERROR: Could not select database. 
    report(8); 
}else{ 
    //report - done! 
    report(7); 
} 

//report - Running query ... 
report(10); 

//// 
// Step 5) Create the original the query 
//// 

$selector = " * "; 
$target = "`properties`"; 
$condition = "1"; 

$sql = "SELECT " . $selector . " FROM " . $target . " WHERE " . $condition; 

//// 
// Step 6) Check for a $_GET[] parameter 
//// 

if($_GET['listing'] && !is_null($_GET['listing'])){     //if a listing number was supplied 
    $listingNum = htmlentities($_GET['listing']);     //safety first - clean it from code injections      
    $pattern = '/\b[0-9]{1,6}\b/';         //define a range of valid, sercheable listings 
    if(preg_match($pattern,$listingNum) == 1){      //if the listing id is a valid one 
     $sql .= " AND `listing_id` =" .$listingNum . "";   //search for it in the database 
    }elseif($exp == 0){            //if the listing number is out of range   
     if($listingNum != "all"){         //check if the "all" keyword was ommitted - if it was not supplied. 
      //report - failure ... see below 
      report(5); 
      //report - Invalid listing ID 
      report(12); 
      // 
      // Invalid Listing ID... 
      // 
     }  
    } 
}else if(!$_GET['listing']){ 
    //report - failure ... see below 
    report(5); 
    //report - Invalid listing ID 
    report(12); 
    // 
    //No listing ID 
    // 
} 


if(!$sql){ 
    //report - failed, see next line... 
    report(5); 
    //report - FATAL ERROR: Could not run query. 
    report(11); 
    // 
    // For some reason the query doesn't exist here. I really do wonder why. 
    // 
}else{ 
    //report - done! 
    report(7); 
    nl(); 
} 

$result = mysql_query($sql); //perform the actual query 

if(!$result){ 
    echo("There's been some sort of error with the search lookup. Here are the details: \n" . mysql_error()); 
} 

mysql_close($conn);   //close the connection to the SQL server 
+0

被選擇的數據庫你試圖echo'n'的phpinfo();',以確保其工作開始與?我記得如果你選擇Linux託管,你會得到PHP,所以它應該在那裏。 –

+0

在php中的其他一切工作在服務器上。 PHP的作品。 – Moshe

+1

「不起作用」是什麼意思?你有任何一種錯誤(如果有必要,你應該嘗試啓用error_reporting)? –

回答

3

你在mysql連接中使用「localhost」嗎?

大多數主機服務主機mysql在不同的機器上,通常localhost不起作用,需要把你的服務器提供的確切的URL。

並且密碼中的字符「#」不應該是問題,但是您的密碼應該在123「123」之類的引號內,我不確定123#123是否可以使用。

+0

+1關於pwd的位。 – Moshe

0

您曾經訪問過數據庫嗎?你有沒有安裝phpMyAdmin?並且散列不應該成爲問題。如果它允許您將其設置爲密碼,那麼您可以確定登錄。你會發布你正在使用的代碼,所以我們可以檢查出來嗎?

+0

我以前訪問過GoDaddy上的其他數據庫,而不是這個。我認爲事實是,中間的一個#因爲它是PHP的評論字符而與事物混淆。 (除了/ ** /和//)也許GoDaddy/PHPMyAdmin有一些解析它的方法。 – Moshe

+1

散列是註釋,只要它在字符串外。它與它無關。 – metrobalderas

0

我已經使用過GoDaddy一次或兩次(可怕的服務btw),只要我記得,mysql主機,這是98%localhost,應該被設置爲另一個主機,但我不確定。也許你應該開始在那裏檢查。

2

對於GoDaddy,您必須使用而不是使用localhost作爲數據庫服務器。在託管經理的數據庫 - > MySQL下有示例PHP代碼可以提供幫助。

+0

我**不**使用本地主機作爲服務器。 – Moshe

0

自我提醒:

下一次這樣的事情發生,確認您在MySQL

相關問題