php - PDO 查询未插入且无错误

标签 php mysql pdo

我试图执行这段代码,但我的代码死了,因为它由于某种原因无法插入到表中。给出的错误是“存储到表时出错”我查看了我的代码但看不到我的 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'])){

关于php - PDO 查询未插入且无错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30095121/

相关文章:

php - 需要一天中的最长和最短时间

php - 在 excel 中打开 CSV 文件会更改我的格式

java - 使用java在sql server中插入大量行的更好方法?

php - 在变量中使用破折号 (-) 时出现 PDO 错误

php - 如何修复通知 : Object of class PDOStatement could not be converted to int

php - 重复调用 .load() 而不会导致重复的脚本

php - 同步本地数据库和现场数据库

php - 从两列的 MySQL 表中查找相同的值

sql - 避免在一个查询中多次使用同一个子查询

php - SQLSRV 从 MySQL 转换数据表时参数无效