Explorar o código

实现insert返回主键AI的ID

实现插入数据成功后,返回主键自增的ID
coco543 %!s(int64=10) %!d(string=hai) anos
pai
achega
c212c76395
Modificáronse 1 ficheiros con 6 adicións e 1 borrados
  1. 6 1
      applications/Demo/Lib/DbConnection.php

+ 6 - 1
applications/Demo/Lib/DbConnection.php

@@ -1672,9 +1672,14 @@ class DbConnection
         if ($statement === 'select' || $statement === 'show') {
             return $this->sQuery->fetchAll($fetchmode);
         }
-        elseif ( $statement === 'insert' ||  $statement === 'update' || $statement === 'delete' ) {
+        elseif ( $statement === 'update' || $statement === 'delete' ) {
             return $this->sQuery->rowCount();
         }
+        elseif( $statement === 'insert' ){
+            if( $this->sQuery->rowCount() > 0 ){
+                return $this->lastInsertId();
+            }
+        }
         else {
             return NULL;
         }