如何使用PDO获取列的总和?

php says it can't convert into int:

Notice: Object of class PDOStatement could not be converted to int in C:\xampp\htdocs\elearning\pages\student\upload.php on line 76:

              $userLoggedIn = $_SESSION['username'];

              $stmt = $conn->prepare(  "SELECT s.grade_level, s.section 
                                        FROM tblusers as u 
                                        JOIN tblstudents as s 
                                        ON u.username = s.username 
                                        WHERE u.username = :username" );
                                        $stmt->execute(array( ':username' => $userLoggedIn ));

              $file = $_FILES['file']['name'];
              $filesize = $_FILES['file']['size'];
              $filepath = "../../assets/uploads/" . $file;

              $filelimit = $conn->prepare("SELECT SUM(f.filesize)
                                           FROM tblfiles AS f 
                                           JOIN tblstudents AS s
                                           ON f.uploader = s.username
                                           WHERE f.uploader = ':username'");
              $filelimit->execute(array(':username'=>$userLoggedIn));

this is line 76: if($filelimit > 1048576)

i guess you have problem getting the value from sum(f.filesize) .

try give it an alias like that

  SELECT SUM(f.filesize) as filesize

and then retrieve the sum by this filesize

$filelimit is a PDOStatement object. To get the result set you have to fetch the result set from the statement.

MrVimes has the complete answer.

$filelimit is a PDO object. Not an integer. You need to get the result of the query from the object using fetch()

$row = $filelimit->fetch();

$filelimitvalue = $row[0];

and then in your if statement on line 76...

if($filelimitvalue > 1048576)