Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在本地主机上运行但不在服务器上运行的PHP后端代码_Php_Jquery_Json - Fatal编程技术网

在本地主机上运行但不在服务器上运行的PHP后端代码

在本地主机上运行但不在服务器上运行的PHP后端代码,php,jquery,json,Php,Jquery,Json,我正在尝试创建一个网站的后端。我成功地创建了它。它在本地主机上运行得非常好。现在,当我将代码移动到服务器上时,php就不能工作了。它显示一个空的白色屏幕 它接受输入并返回JSON输出。有什么问题吗? 我使用的是AmazonEC2服务器 以下是我的php代码: <?php require_once('common/common_database.php'); class user { public $id; public $fNam

我正在尝试创建一个网站的后端。我成功地创建了它。它在本地主机上运行得非常好。现在,当我将代码移动到服务器上时,php就不能工作了。它显示一个空的白色屏幕

它接受输入并返回JSON输出。有什么问题吗? 我使用的是AmazonEC2服务器

以下是我的php代码:

<?php

    require_once('common/common_database.php');

    class user
    {
        public $id;
        public $fName;
        public $lName;
        public $sex;
        public $image;
        public $birthday;
        public $location;

        public function __construct($userId)
        {
            $this->id = htmlspecialchars ( $userId );
        }

        public function getDetails()
        {
            global $dbh;

            //getting user's first and last name
            $query = "SELECT * FROM `user` WHERE `id` = :id;";
            $s = $dbh->prepare ( $query );
            $s->bindParam ( ":id" , $this->id );
            $s->execute (  );
            $r  =  $s->fetch (  );
            $this->fName  = htmlspecialchars( $r['firstName'] );
            $this->lName = htmlspecialchars ( $r['lastName'] );
            $this->location = htmlspecialchars (  $r['location'] );
            $this->image = htmlspecialchars ( $r['image'] );
            $this->birthday = htmlspecialchars ( $r['birthday'] );
            $this->sex = htmlspecialchars ( $r['sex'] );

        }
    }

    if ( isset($_GET['id']) )
    {
        $newUser = new user( $_GET['id'] ); 
        $newUser->getDetails();
    }
    else
    {
        $newUser = 0;
    }

    $output = json_encode ( $newUser );
    header('content-type: application/json');
    echo $output;
    exit;
?>

我首先打开错误报告:

ini_set('display_errors', '1');
error_reporting(E_ALL);

你需要做两件事:

  • 使用代码在页面顶部启用错误报告:

    ini_集('display_errors','1'); 错误报告(E_全部)

  • 检查您的PHPINI设置。可能需要从php设置(php.ini)启用pdo_mysql


我建议从比较phpinfo()输出开始。听起来好像是配置上的差异。请添加您得到的错误消息,或者查看PHP错误日志,从那里我可以获得PHP错误日志?当我只看到白色屏幕时(通常在有wierd限制的网络酒店上),我会对所有代码进行注释,然后只运行一些代码并回显“DoThisShow?”找到它变白的地方。我确实设置了错误。但是什么也抓不到。除此之外,pro_mysql被激活。我猜这个错误是因为上课。我们需要单独激活php中的类吗?