title: SQLSTATE[42000]: Syntax error or access violation: 1172 Result consisted of more than one row
body: <p>When I try to insert multiple rows in one query I get this error:</p>
  
  <blockquote>
    <p>SQLSTATE[42000]: Syntax error or access violation: 1172 Result
    consisted of more than one row</p>
  </blockquote>
  
  <p>Here's the code I used :</p>
  
  <pre><code>  public function submitAnswers($q)
     {
      try
        {
          $sql = 'INSERT INTO `result_answers` (`resultID`, `questionID`, `answerID`, `isTrue`,`textAnswer`) VALUES ';
          foreach($q as $question =&gt; $answer){
          if($answer[0] == 0){
          for($i = 1;$i &lt; count($answer);$i++){
              $sql .= '((select max(id) from result r where r.studentID = :studentID), ' . $question . ', ' . $answer[$i] .', NULL, NULL),';}
          }elseif($answer[0] == 1){
            $sql .= '((select max(id) from result r where r.studentID = :studentID), ' . $question . ', NULL, ' . $answer[1] .', NULL),';
          }elseif($answer[0] == 2){
            $sql .= '((select max(id) from result r where r.studentID = :studentID), ' . $question . ', NULL, NULL, "' . $answer[1] .'"),';
          }
          }
            $query = rtrim($sql,',');
           $stmt = $this-&gt;connect()-&gt;prepare($query);
           $stmt-&gt;bindparam(":studentID",$_SESSION['student']-&gt;id);
  
           $stmt-&gt;execute();
  
           return true;
        }
      catch(PDOException $e)
        {
           echo $e-&gt;getMessage();
           return false;
        }
     }
  </code></pre>
  
  <p>When I execute the <code>$query</code> output directly in my database, rows are successfully inserted, so I think for some reason PDO is not allowing multi-rows insertion. </p>