OSDN Git Service

FIX:クエリエラー時にエラーとなったクエリが画面に表示されない不具合の修正
[nucleus-jp/nucleus-next.git] / nucleus / libs / sql / DB.php
index 17d96c1..bc0dd90 100644 (file)
@@ -175,7 +175,7 @@ class DB
        {\r
                if ( self::$dbh == null ) return FALSE;\r
                self::$execCount++;\r
-               $result = self::showErrorDisplay(self::$dbh->query($statement));\r
+               $result = self::callQuery($statement);\r
                if ( $row = $result->fetch(PDO::FETCH_NUM) )\r
                {\r
                        return $row[0];\r
@@ -193,7 +193,7 @@ class DB
        {\r
                if ( self::$dbh == null ) return FALSE;\r
                self::$execCount++;\r
-               $result = self::showErrorDisplay(self::$dbh->query($statement));\r
+               $result = self::callQuery($statement);\r
                return $result->fetch(PDO::FETCH_BOTH);\r
        }\r
 \r
@@ -207,40 +207,68 @@ class DB
        {\r
                if ( self::$dbh == null ) return FALSE;\r
                self::$execCount++;\r
-               return self::showErrorDisplay(self::$dbh->query($statement));\r
+               return self::callQuery($statement);\r
        }\r
 \r
        /**\r
         * DB::execute()\r
         * Execute an SQL statement and return the number of affected rows.\r
         * @param string $statement SQL Statement\r
-        * @return int number of rows that were modified or deleted by the SQL statement you issued.\r
+        * @return int number of rows that were modified or deleted by the SQL statement you issued. If the call fails, it will return FALSE.\r
         */\r
        public static function execute($statement)\r
        {\r
                if ( self::$dbh == null ) return FALSE;\r
                self::$execCount++;\r
-               return self::showErrorDisplay(self::$dbh->exec($statement));\r
+               return self::callExec($statement);\r
        }\r
 \r
        /**\r
+        * DB::callQuery()\r
+        * Run the query to retrieve the result set.\r
+        * @param string $statement query to be executed\r
+        * @return PDOStatement Result set object. If the call fails, it will return FALSE.\r
+        */\r
+       private static function callQuery($statement)\r
+       {\r
+               $result = self::$dbh->query($statement);\r
+               if ( $result === FALSE )\r
+               {\r
+                       self::showErrorDisplay($statement);\r
+               }\r
+               return $result;\r
+       }\r
+       \r
+       /**\r
+        * DB::callExec()\r
+        * Run the query and returns the number of rows affected.\r
+        * @param string $statement query to be executed\r
+        * @return int number of rows that were modified or deleted by the SQL statement you issued. If the call fails, it will return FALSE.\r
+        */\r
+       private static function callExec($statement)\r
+       {\r
+               $result = self::$dbh->exec($statement);\r
+               if ( $result === FALSE )\r
+               {\r
+                       self::showErrorDisplay($statement);\r
+               }\r
+               return $result;\r
+       }\r
+       \r
+       /**\r
         * DB::showErrorDisplay()\r
-        * On the display query execution result query has an error in the case of FALSE.\r
-        * @param mixed $result Query execution result\r
-        * @return mixes Query execution result\r
+        * The error message is output to the screen of the query.\r
+        * @param string $statement query output to the screen\r
         */\r
-       private static function showErrorDisplay($result)\r
+       private static function showErrorDisplay($statement)\r
        {\r
                global $CONF;\r
                if ( array_key_exists('debug', $CONF) && $CONF['debug'] )\r
                {\r
-                       if ( $result === FALSE )\r
-                       {\r
-                               $err = self::getError();\r
-                               print('mySQL error with query $query: ' . $err[2]);\r
-                       }\r
+                       $err = self::getError();\r
+                       print("mySQL error with query '{$statement}' : " . $err[2]);\r
                }\r
-               return $result;\r
+               return;\r
        }\r
        \r
        /**\r