PDO 查询未插入且无错误

PDO query not inserting and no error

我试图执行这段代码,但我的代码死了,因为它无法插入到 table 中,因为给出的一些 reason.the 错误是 "there was an error in storing to table" 我查看了我的代码但是我的 PDO 插入查询和 php 错误日志都看不到任何问题。

try {
        $result = $s3->putObject([
                'Bucket' => $config['s3']['bucket'],
                'Key' => "uploads/{$name_of_uploaded_file}",
                'Body' => fopen($path_of_uploaded_file, 'rb'),
                'ACL' => 'public-read'
            ]);

            if (is_uploaded_file($_FILES['uploaded_file']['size'])){
                  //send items to pending database

                  //inserts in pending db
                  $sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)";
                  $stmt = $conn->prepare($sql); 
                  $stmt->bindParam(':title', $title);
                  $stmt->bindParam(':photo', $result);
                  $stmt->bindParam(':description', $story);
                  $stmt->bindParam(':name', $first_name);
                  $stmt->bindValue(':pLike', 0, PDO::PARAM_INT);
                  $stmt->bindValue(':pDislike', 0, PDO::PARAM_INT);
                  $stmt->execute();       
            }else {
                die("there was an error in storing to table");        
            }

        //remove the file
            unlink($path_of_uploaded_file);
    } catch(S3Exception $e){
        die("there was an error");
    }

它已经在 manual 中说:

Returns TRUE if the file named by filename was uploaded via HTTP POST.

For proper working, the function is_uploaded_file() needs an argument like

$_FILES['userfile']['tmp_name'],

the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work.

现在,您正指向 size 索引:

is_uploaded_file($_FILES['uploaded_file']['size']
                                        // ^

应该是:

if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
try{
                  $sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)";
                  $stmt = $conn->prepare($sql); 
                  $stmt->bindParam(':title', $title);
                  $stmt->bindParam(':photo', $result);
                  $stmt->bindParam(':description', $story);
                  $stmt->bindParam(':name', $first_name);
                  $stmt->bindValue(':pLike', 0, PDO::PARAM_INT);
                  $stmt->bindValue(':pDislike', 0, PDO::PARAM_INT);
                  $stmt->execute();     
}
catch(PDOException $e){
echo 'error in query:  '.$e->getMessage();
}  

在您的 if 语句的第一部分将回显您查询中的错误(如果有)