PDO queries works locally, not on server

2019-08-20 05:20发布

I'm executing an insert query to a MySQL database and the queries work perfectly fine on XAMPP locally, but not when I try the exact same code on the server.

Here is the code:

if($app['database']->insert('tickets', [
    'error' => $error,
    'productid' => $productid,
    'counterblack' => $counterblack,
    'countercolor' => $countercolor,
    'time' => $time,
    'date' => $date,
    'active' => 1
]))
{
    header("Location: ../Tasks.php");
}
else
{
    echo "Error";
}

Insert function:

public function insert($table, $parameters)
{
    $query = sprintf('insert into %s (%s) VALUES (%s)', $table, implode(', ', array_keys($parameters)), ':' . implode(', :', array_keys($parameters)));
    $statement = $this->pdo->prepare($query);
    $statement->execute($parameters);
    return $this->pdo->lastInsertId();
}

For some reason, it always goes to the else part and displays 'Error' when code is executed.

I used var_dump on $this->pdo->errorInfo(); and the output is:

array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }

The database schema is similar as I exported from XAMPP and uploaded it straight to the server. What could be the issue here? Thanks!

EDIT: I forgot to add some important information, the same insert query works on the different table, but it's not working on this 'tickets' table.

Not a duplicate since I tried changing the keywords to different column names, still issue persists.

标签: php mysql pdo
1条回答
贼婆χ
2楼-- · 2019-08-20 05:21

If it really so confusing then why not to try to read an error message?

<?php
    ...
    $statement = $this->pdo->prepare($query);
    /* insert this */
    if (!$statement) {
        echo "\PDO::errorInfo():\n";
        print_r($this->pdo->errorInfo());
    }
    ...
    ?>
查看更多
登录 后发表回答