簡體   English   中英

以下php代碼使用mysql返回http錯誤500?

[英]The following php code returns a http error 500 using mysql?

這是我收到錯誤的示例代碼,當嘗試在遠程服務器上運行代碼返回錯誤時,它在localhost中運行良好,建議我還有其他方法可以在代碼中實現相同的功能。

<?php
if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' . mysql_error());
}
if (!mysql_select_db(sample)) {
die('An error occurred while connecting to the database!<br><br>' . mysql_error());
}
$sql = array(
'DROP TABLE IF EXISTS content;',
'CREATE TABLE content SELECT * FROM sample2.content'
);
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());
}
}
}

mysql_close($con);

?>

對於初學者,如果可以的話,請不要使用任何mysql_*函數,因為它們已從PHP 5.5.x開始不推薦使用,並且已在PHP 7中完全刪除。

除了錯誤的做法外,您的代碼沒有任何其他錯誤,而500是通用錯誤代碼。 這可能是由於許多原因,例如:

  1. PHP無法正確設置。
  2. Apache / Nginx / etc設置不正確。
  3. ...

找到特定的錯誤后,您將收到一個新的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM