コード例 #1
0
ファイル: MBFileHeader.php プロジェクト: sinri/MeinBlog
 function create($title, $main_editor_id, $content, $category_id = 0, $abstract = '')
 {
     if (empty($title) || empty($main_editor_id) || empty($content)) {
         return false;
     }
     $this->pdo->beginTransaction();
     try {
         $title = $this->pdo->quote($title);
         $main_editor_id = $this->pdo->quote($main_editor_id, PDO::PARAM_INT);
         $abstract = $this->pdo->quote($abstract);
         $sql = "INSERT INTO `mb_file_header` (\n\t\t\t\t\t`file_id`,\n\t\t\t\t\t`title`,\n\t\t\t\t\t`abstract`,\n\t\t\t\t\t`main_editor_id`,\n\t\t\t\t\t`category_id`,\n\t\t\t\t\t`create_time`,\n\t\t\t\t\t`update_time`\n\t\t\t\t)VALUES(\n\t\t\t\t\tNULL,\n\t\t\t\t\t{$title},\n\t\t\t\t\t{$abstract},\n\t\t\t\t\t{$main_editor_id},\n\t\t\t\t\t{$category_id},\n\t\t\t\t\tNOW(),\n\t\t\t\t\tNOW()\n\t\t\t\t);\n\t\t\t";
         // MeinBlog::log("create file header sql: ".$sql);
         $file_id = $this->pdo->insert($sql);
         if (empty($file_id)) {
             throw new Exception("Error on creating file header.", 1);
         }
         $FC = new MBFileContent();
         $afx = $FC->create($file_id, $content, $main_editor_id);
         if (empty($afx)) {
             throw new Exception("Error on creating file content.", 1);
         }
         $this->pdo->commit();
         return $file_id;
     } catch (Exception $e) {
         $this->pdo->rollBack();
         MeinBlog::log($e->getMessage());
     }
     return false;
 }