PHP:无法加载资源

时间:2017-08-08 10:23:20

标签: php server

当使用localhost(使用php内置服务器)时,我的php文件正确加载并显示所有内容但是当我将其上传到实际服务器并尝试访问它时,我收到以下错误:

  

获取http://shunterweb/ 500(内部服务器错误)

这是PHP代码

<?php
require_once(__DIR__.'/../config.php');

// Get the DB connection settings
$dbHost = $config["db"]["server"]["host"];
$dbUser = $config["db"]["server"]["username"];
$dbPass = $config["db"]["server"]["password"];
$dbName = $config["db"]["server"]["dbname"];

$connectionInfo = array( "Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPass);
$conn = sqlsrv_connect( $dbHost, $connectionInfo);
if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));
}

//declare the SQL statement that will query the database
$query = "SELECT YardId,Yard FROM YWBYard"; 
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

//execute the SQL query and return records
$result = sqlsrv_query($conn, $query);

if( $result === false){
    if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
            echo "code: ".$error[ 'code']."<br />";
            echo "message: ".$error[ 'message']."<br />";
        }
    }
}
else {
    $numRows = sqlsrv_num_rows($result); 
    //echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 

    //display the results 
    while($row = sqlsrv_fetch_array($result))
    {
        if($row['YardId']===1){
          echo "<li>"."<a href="."http://localhost:8080/".">".$row['Yard'],"</a></li>";
        }
        elseif($row['YardId']===2){
          echo "<li>"."<a href="."http://localhost:8080/bicker.php".">".$row['Yard'],"</a></li>";
        }
        else{
          echo "<li>"."<a href="."http://localhost:8080/crick.php".">".$row['Yard'],"</a></li>";
        }      
    }
}
//close the connection
sqlsrv_close($conn);
?>

它是我的代码还是服务器端?

1 个答案:

答案 0 :(得分:-4)

您可能会收到警告或致命错误。要显示服务器上的所有错误,

您需要在页面标题上写下这一行

public class InitialData implements Realm.Transaction {
    @Override
    public void execute(Realm realm) {
        List<MyColleagueModel> colleague = new ArrayList<>();
        MyColleagueModel model = new MyColleagueModel();
        model.setId(1 + System.currentTimeMillis());
        model.setName("Name1");
        model.setCompany("Comapny1");
        model.setTitle("Title1");
        colleague.add(model);

        model = new MyColleagueModel();
        model.setId(2 + System.currentTimeMillis());
        model.setName("Name2");
        model.setCompany("Company2");
        model.setTitle("Title2");
        colleague.add(model);

        model = new MyColleagueModel();
        model.setId(3 + System.currentTimeMillis());
        model.setName("Name3");
        model.setCompany("Comapny3");
        model.setTitle("Title3");
        colleague.add(model);


        for (MyColleagueModel realmModel : colleague) {
            realm.insertOrUpdate(realmModel);
        }
    }

    @Override
    public boolean equals(Object obj) {
        return obj != null && obj instanceof InitialData;
    }

    @Override
    public int hashCode() {
        return InitialData.class.hashCode();
    }
}

public class CustomApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this);
        Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
                      .deleteIfMigrationNeeded()
                      .initialData(new InitialData())
                      .build());
    }
}

error_reporting(E_ALL);

它将显示php的所有错误