我的代碼:<?phptry {$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();}在代碼中,您將看到第一部分是用于進行身份驗證的。然后,在img模式上創(chuàng)建一個新的PDO對象,然后在該文件中執(zhí)行查詢。稍后,在我打印$ dbMsg的地方,它說的是“已將文件添加到存儲庫”。但是,當我查詢數(shù)據(jù)庫(使用MySQL Workbench的Amazon AWS上的MySQL)時,沒有插入任何內(nèi)容。我不明白為什么如果什么也沒插入,卻沒有收到錯誤消息。如果顯示“已將文件添加到存儲庫”,這是否表示插入成功?我唯一能想到的是為此使用不同的架構(gòu)來處理問題。我對ebdb的所有插入操作都正常
- 0 回答
- 0 關(guān)注
- 326 瀏覽
添加回答
舉報
0/150
提交
取消