PHP从5.2升级到5.6,以下代码停止工作:
运行后,抛出错误:无法加载资源:服务器以状态500(内部服务器错误)响应。 我不确定javascript或PHP本身是否存在导致此问题的问题。前端正在加载,但未在回调中获取数据。
任何帮助将不胜感激。如果这是某些错误或帖子的重复,请指出必要的答案。如果我在写问题时犯了任何错误,请写评论,为什么要这样做,而不是公然给我打分。
JavaScript代码段:
jQuery(document).ready(function() {
// Get data from Outlast Server
var url="https://xxxxx/xxxx/q_data.php?callback=?";
jQuery.getJSON(url, function(rts_data) {
var deck_count = 0, shiplap_count = 0, bnb_b_count = 0, bnb_c_count = 0;
for(var i=0; i<rts_data.length; i++) {
if (rts_data[i].type == "Deck") {
data[0][deck_count] = new Object();
data[0][deck_count].productName = rts_data[i].productName;
data[0][deck_count].coverage = rts_data[i].coverage;
data[0][deck_count].screws = rts_data[i].screws;
data[0][deck_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_d').append(jQuery('<option>', { value : deck_count }).text(rts_data[i].productName));
deck_count++;
}
else if (rts_data[i].type == "Shiplap") {
data[1][shiplap_count] = new Object();
data[1][shiplap_count].productName = rts_data[i].productName;
data[1][shiplap_count].coverage = rts_data[i].coverage;
data[1][shiplap_count].screws = rts_data[i].screws;
data[1][shiplap_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_s').append(jQuery('<option>', { value : shiplap_count }).text(rts_data[i].productName));
shiplap_count++;
}
else if (rts_data[i].type == "Board and Batton - Cap") {
data[2][bnb_c_count] = new Object();
data[2][bnb_c_count].productName = rts_data[i].productName;
data[2][bnb_c_count].coverage = rts_data[i].coverage;
data[2][bnb_c_count].screws = rts_data[i].screws;
data[2][bnb_c_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_bnb_c').append(jQuery('<option>', { value : bnb_c_count }).text(rts_data[i].productName));
bnb_c_count++;
}
else if (rts_data[i].type == "Board and Batton - Base") {
data[3][bnb_b_count] = new Object();
data[3][bnb_b_count].productName = rts_data[i].productName;
data[3][bnb_b_count].coverage = rts_data[i].coverage;
data[3][bnb_b_count].screws = rts_data[i].screws;
data[3][bnb_b_count].gaps = rts_data[i].gaps;
// Insert the data into the Select Box
jQuery('#opt_bnb_b').append(jQuery('<option>', { value : bnb_b_count }).text(rts_data[i].productName));
bnb_b_count++;
}
}
PHP:
<?php
// Connection data
$host = "xxxxxxx";
$username = "xxxxx";
$database = "xxxxx";
$password = "xxxxx";
// Opens a connection to a mySQL server
$connection = mysql_connect ($host, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Set the where clause
$where = "";
switch(@$_GET['type']) {
case 'shiplap':
$where = "WHERE type = 'Shiplap'";
break;
case 'deck':
$where = "WHERE type = 'Deck'";
break;
case 'bnb_base':
$where = "WHERE type = 'Board and Batton - Base'";
break;
case 'bnb_cap':
$where = "WHERE type = 'Board and Batton - Cap'";
break;
default:
$where = "";
break;
}
// Run the query
$query = "SELECT * FROM `site_products` {$where} ORDER BY productID ASC";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Declare Variables
$data_shiplap = array();
$shiplap_i = 0;
// Get the data and divide
while ($row = @mysql_fetch_assoc($result)) {
$data_shiplap[$shiplap_i]['productName'] = $row['productName'];
$data_shiplap[$shiplap_i]['coverage'] = $row['coverage'];
$data_shiplap[$shiplap_i]['screws'] = $row['screws'];
$data_shiplap[$shiplap_i]['gaps'] = $row['gaps'];
$data_shiplap[$shiplap_i]['type'] = $row['type'];
$shiplap_i++;
}
echo $_GET['callback']. '('. json_encode($data_shiplap) . ')';
?>
答案 0 :(得分:0)
在PHP 5.6。*之后,所有std::transform
函数均已弃用。我认为这就是为什么您得到{
std::string str( "HelLo" );
std::cout << str << '\n';
std::transform( str.begin(), str.end(), str.begin(), ::toupper );
std::cout << str << '\n';
std::transform( str.begin(), str.end(), str.begin(), ::tolower );
std::cout << str << '\n';
}
的原因。将所有mysql_*
函数替换为Internal server error
,然后查看错误是否持续存在。