Exemple #1
0
 public static function insert($product)
 {
     $newId = 0;
     if (empty($product)) {
         Tool::logger(__METHOD__, __LINE__, "没有数据需插入", _LOG_DEBUG);
         return $newId;
     }
     try {
         $sql = sprintf("insert into product(product_no, product_name, sort_id, order_no, m_image, ali_url, is_recommend, is_showhome) values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", $product->productNo, $product->productName, $product->productType, $product->orderNo, $product->mImage, $product->aliUrl, $product->isRecommend, $product->isShowHome);
         Tool::logger(__METHOD__, __LINE__, sprintf("插入产品SQL:%s", $sql), _LOG_DEBUG);
         $conn = DBHelp::getConnection();
         $conn->query($sql);
         $sql = "select max(product_id) as product_id from product;";
         $data = $conn->query($sql);
         if (!empty($data) && $data->num_rows > 0) {
             while ($row = $data->fetch_assoc()) {
                 $newId = $row["product_id"];
                 break;
             }
         }
         DBHelp::free($data);
         DBHelp::close($conn);
         Tool::logger(__METHOD__, __LINE__, "数据插入成功", _LOG_DEBUG);
     } catch (Exception $e) {
         Tool::logger(__METHOD__, __LINE__, sprintf("数据插入失败:%s", $e->getMessage()), _LOG_ERROR);
         throw new Exception(sprintf("数据插入失败:%s", $e->getMessage()));
     }
     return $newId;
 }
Exemple #2
0
 public static function rcount($query)
 {
     try {
         $rcount = _NONE;
         $sql = "select count(1) as rcount from doc_file where 1=1";
         if (is_numeric($query->fileId) && $query->fileId > 0) {
             $sql = $sql . sprintf(" and file_id=%u", $query->fileId);
         }
         if (strlen($query->inModule) > 0) {
             $sql = $sql . sprintf(" and in_module='%s'", $query->inModule);
         }
         if (strlen($query->fileKey) > 0) {
             $sql = $sql . sprintf(" and file_key='%s'", $query->fileKey);
         }
         if (strlen($query->savedPath) > 0) {
             $sql = $sql . sprintf(" and saved_path='%s'", $query->fileKey);
         }
         Tool::logger(__METHOD__, __LINE__, sprintf("查询图片总数SQL: %s", $sql), _LOG_DEBUG);
         $conn = DBHelp::getConnection();
         $data = $conn->query($sql);
         if (!empty($data) && $data->num_rows > 0) {
             while ($row = $data->fetch_assoc()) {
                 $rcount = $row["rcount"];
                 break;
             }
         }
         DBHelp::free($data);
         DBHelp::close($conn);
         Tool::logger(__METHOD__, __LINE__, sprintf("文件共%u条记录.", $rcount), _LOG_DEBUG);
         return $rcount;
     } catch (Exception $e) {
         Tool::logger(__METHOD__, __LINE__, "查询数据失败:" . $e->getMessage());
         throw $e;
     }
     return _NONE;
 }
Exemple #3
0
 public static function rcount($query)
 {
     try {
         $rcount = _NONE;
         $sql = "select count(1) as rcount from content where 1=1";
         if (is_numeric($query->contentId) && $query->contentId > 0) {
             $sql = $sql . sprintf(" and content_id=%u", $query->contentId);
         }
         if (strlen($query->contentKey) > 0) {
             $sql = $sql . sprintf(" and content_key='%s'", $query->contentKey);
         }
         if (strlen($query->contentType) > 0) {
             $sql = $sql . sprintf(" and content_type='%s'", $query->contentType);
         }
         Tool::logger(__METHOD__, __LINE__, sprintf("查询文本内容总数SQL: %s", $sql), _LOG_DEBUG);
         $conn = DBHelp::getConnection();
         $data = $conn->query($sql);
         if (!empty($data) && $data->num_rows > 0) {
             while ($row = $data->fetch_assoc()) {
                 $rcount = $row["rcount"];
                 break;
             }
         }
         DBHelp::free($data);
         DBHelp::close($conn);
         Tool::logger(__METHOD__, __LINE__, sprintf("查询文本内容总%u.", $rcount), _LOG_DEBUG);
         return $rcount;
     } catch (Exception $e) {
         Tool::logger(__METHOD__, __LINE__, "查询数据失败:" . $e->getMessage());
         throw new Exception("查询数据失败:" . $e->getMessage());
     }
     return _NONE;
 }