cpanel mysql数据库时,它抛出500(内部服务器错误)

vaqhlq81  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(157)

当我在本地做的时候,一切都很好,但是现在我在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);
});

提交.php

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

引导.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']) );

配置.php

<?php

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

抱歉,我知道这是很多代码,但我真的不知道问题可能是什么,所以我不知道如何缩小它。有什么想法吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题