问题描述
我正在执行对MySQL数据库的插入查询,并且查询在XAMPP本地上可以很好地工作,但是当我在服务器上尝试完全相同的代码时却不能.
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.
这是代码:
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";
}
插入功能:
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();
}
由于某种原因,它总是转到else部分,并在执行代码时显示错误".
For some reason, it always goes to the else part and displays 'Error' when code is executed.
我在$this->pdo->errorInfo();
上使用了var_dump,输出为:
I used var_dump on $this->pdo->errorInfo();
and the output is:
数据库模式类似于我从XAMPP导出并将其直接上传到服务器.这可能是什么问题?谢谢!
The database schema is similar as I exported from XAMPP and uploaded it straight to the server. What could be the issue here? Thanks!
我忘了添加一些重要信息,相同的插入查询可在不同的表上使用,但不适用于此票证"表.
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.
推荐答案
如果确实如此令人困惑,那为什么不尝试阅读错误消息呢?
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());
}
...
?>
这篇关于PDO查询在本地工作,不在服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!