我使用共享的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
被選擇的數據庫你試圖echo'n'的phpinfo();',以確保其工作開始與?我記得如果你選擇Linux託管,你會得到PHP,所以它應該在那裏。 –
在php中的其他一切工作在服務器上。 PHP的作品。 – Moshe
「不起作用」是什麼意思?你有任何一種錯誤(如果有必要,你應該嘗試啓用error_reporting)? –