From 26f1c0f10afe4a469a137aa4aadb48e8582e9289 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 22 May 2014 15:20:25 -0500
Subject: [PATCH] orm: Handle error executing prepared statement

---
 include/class.orm.php | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/class.orm.php b/include/class.orm.php
index 0e8b30654..b403617b2 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -485,7 +485,7 @@ class FlatArrayIterator extends ModelInstanceIterator {
     function fillTo($index) {
         while ($this->resource && $index >= count($this->cache)) {
             if ($row = $this->resource->getRow()) {
-                $this->cache += $row;
+                $this->cache[] = $row;
             } else {
                 $this->resource->close();
                 $this->resource = null;
@@ -988,7 +988,10 @@ class MysqlExecutor {
                 .' '.$this->sql);
         if (count($this->params))
             $this->_bind($this->params);
-        return $this->stmt->execute();
+        if (!$this->stmt->execute()) {
+            throw new OrmException('Unable to execute query: ' . $this->stmt->error);
+        }
+        return true;
     }
 
     function _bind($params) {
@@ -1028,7 +1031,7 @@ class MysqlExecutor {
     function next() {
         $status = $this->stmt->fetch();
         if ($status === false)
-            throw new Exception($this->stmt->error_list . db_error());
+            throw new OrmException($this->stmt->error);
         elseif ($status === null) {
             $this->close();
             return false;
-- 
GitLab