当我尝试访问它时,cpanel mysql数据库抛出500(内部服务器错误)

时间:2018-06-16 23:20:27

标签: php mysql database cpanel

当我在本地进行此操作时,一切正常,但现在我在cpanel上设置了一个数据库,其中包含具有所有优先级的用户。每当我尝试添加到数据库时,它只会抛出500(内部服务器错误)

这是我得到的

的Ajax:

this.form.addEventListener('submit', function(e){
    e.preventDefault(); 
    var submissionInfo = {
        'entry': 'entry',
        'author': 'author',
    }
    var data = JSON.stringify(submissionInfo);      
    var params = 'submit=' + data;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'submit.php', true);
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xhr.send(params);
});

Submit.php

$submission = $_POST['submit'];
$decode = json_decode($submission, true);
$config = require 'config.php';
$query = require 'bootstrap.php';
$query->insert('submissions', $decode);
echo $submission;

bootstrap.php中

function connection($config){
    try {
        return new PDO(
            "mysql:" . $config['connection'] . ';dbname='.$config['name'],
            $config['username'], $config['password'], $config['options']
        );              
     } catch(PDOException $e){
        die('could not connect.');
    }
}   

class QueryBuilder {
    protected $pdo;
    public function __construct($pdo){
        $this->pdo = $pdo;
    }

    public function insert($table, $parameters){        
        $sql = sprintf(
            'insert into %s (%s) values (%s)',
            $table,
            implode(', ', array_keys($parameters)),
            ':' . implode(', :', array_keys($parameters))
        );
        try {
            $statement = $this->pdo->prepare($sql);
            $statement->execute($parameters);
        } catch (Exception $e) {
            die($e->getMessage());
        }
    }   
}

return new QueryBuilder( connection($config['database']) );

的config.php

<?php

return [
    'database' => [
        'name' => 'database_name',
        'username' => 'myUsername',
        'password' => 'myPassword',
        'connection' => 'localhost',
        'options' => [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ]
    ]
];

抱歉,我知道这是很多代码,但老实说我不知道​​问题是什么,所以我不知道如何缩小范围。有什么想法吗?

0 个答案:

没有答案