[英]PHP PDO MySQL: Insert statement runs without error, no insert occurs
My code: 我的代码:
<?php
try {
$t = '040485c4-2eba-11e9-8e3c-0231844357e8';
if (array_key_exists('t', $_REQUEST)) {
$t = $_REQUEST["t"];
}
if (!isset($_COOKIE['writer'])) {
header("Location: xxx");
return 0;
}
$writer = $_COOKIE['writer'];
$dbhost = $_SERVER['RDS_HOSTNAME'];
$dbport = $_SERVER['RDS_PORT'];
$dbname = $_SERVER['RDS_DB_NAME'];
$charset = 'utf8' ;
$dsn = "mysql:host={$dbhost};port={$dbport};dbname={$dbname};charset={$charset}";
$username = $_SERVER['RDS_USERNAME'];
$password = $_SERVER['RDS_PASSWORD'];
$pdo = new PDO($dsn, $username, $password);
$stmt = $pdo->prepare("select writer from mydbtbl where writer=? and t=?");
$stmt->execute(array($writer, $t));
$num = $stmt->fetch(PDO::FETCH_NUM);
if ($num < 1) {
header("Location: login.php");
return 0;
}
$dbMsg = "Authorized";
$dbname = 'imgs';
$dsn = "mysql:host={$dbhost};port={$dbport};dbname={$dbname};charset={$charset}";
$pdo = new PDO($dsn, $username, $password);
if (isset($_FILES['filename'])) {
$name = $_FILES['filename']['name'];
// set path of uploaded file
$path = "./".basename($_FILES['filename']['name']);
// move file to current directory
move_uploaded_file($_FILES['filename']['tmp_name'], $path);
// get file contents
$data = file_get_contents($path, NULL, NULL, 0, 60000);
$stmt = $pdo->prepare("INSERT INTO file (contents, filename, t) values (?,?,?)");
$stmt->execute(array
($data,
$name,
$t)
);
$dbMsg = "Added the file to the repository";
// delete the file
unlink($path);
}
} catch (Exception $e) {
$dbMsg = "exception: " . $e->getMessage();
}
In the code you will see that the first part is for doing authentication. 在代码中,您将看到第一部分是进行身份验证。 Then I create a new PDO object on the img schema, and do my file insert query after that.
然后,在img模式上创建一个新的PDO对象,然后在该文件中执行查询。
Later, where I am printing out $dbMsg, it is saying "added file to the repository". 后来,在我打印$ dbMsg的地方,它说的是“已将文件添加到存储库”。 But when I query the database (MySQL on Amazon AWS using MySQL Workbench) nothing has been inserted.
但是,当我查询数据库(使用MySQL Workbench的Amazon AWS上的MySQL)时,没有插入任何内容。
I don't understand why if nothing is getting inserted I am not getting an error message. 我不明白为什么如果什么也没插入,却没有收到错误消息。 If it says "added file to the respository", doesn't that mean the insert was successful?
如果显示“已将文件添加到存储库”,这是否表示插入成功? The only thing I can think is that using a different schema for this is mucking things up.
我唯一能想到的就是为此使用不同的架构来处理问题。 All of my inserts to ebdb are going through fine
我对ebdb的所有插入操作都正常
--- EDIT --- -编辑-
This question was marked as a possible duplicate on my query about not getting an error message on my insert / execute code. 此问题被标记为有关我的插入/执行代码未收到错误消息的查询中可能重复的问题。 This was a useful link and definitely something I will be aware of and check in the future, but ultimately the answer is the one I have provided regarding the terms of service for my aws account
这是一个有用的链接,并且绝对是我将来会意识到并检查的内容,但最终答案是我为aws帐户提供的服务条款中的答案。
The answer is that the (free) amazon account policy I am working under only allows me to have 1 database / schema. 答案是我正在使用的(免费)亚马逊帐户策略仅允许我拥有1个数据库/架构。 When I switched the table over to ebdb it worked right away.
当我将表切换到ebdb时,它立即起作用。 I am answering my own question (rather than deleting) so hopefully others using AWS / MySQL can learn from my experience.
我正在回答自己的问题(而不是删除问题),因此希望其他使用AWS / MySQL的人可以从我的经验中学到东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.