PDO queries works locally, not on server

老子叫甜甜 提交于 2019-12-25 03:12:15

问题


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.


回答1:


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());
    }
    ...
    ?>


来源:https://stackoverflow.com/questions/51149100/pdo-queries-works-locally-not-on-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!