CodeIgniter

CRUD

CRUDとは (Create, Read, Update, Delete) クラッド: - IT用語辞典

CRUDとは、データベース管理システム(DBRS)に必要とされる4つの主要な機能、「作成(Create)」「読み出し(Read)」「更新(Update)」「削除(Delete)」をそれぞれ頭文字で表したもののことである。

Create

  • MySQL INSERT構文
    http://dev.mysql.com/doc/refman/5.1/ja/insert.html

    INSERT は既存テーブルに新しい行を挿入します。
    INSERT ... VALUES と INSERT ... SET 型のステートメントは、明示的に指定された値に基づいて行を挿入します。
    INSERT ... SELECT 型は別のテーブルから選択された行を挿入します。

    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
     
     
     
     
    
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name [(col_name,...)]
        VALUES ({expr | DEFAULT},...),(...),...
        [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]

    または:

    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
     
     
     
     
    
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        SET col_name={expr | DEFAULT}, ...
        [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]

    または:

    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
     
     
     
     
    
    INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name [(col_name,...)]
        SELECT ...
        [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
  • CodeIgniterのモデルクラスの記述例
      1
      2
      3
      4
      5
      6
      7
      8
      9
    
    <?php function insert($arg) {
      $this->load->database();
      $sql = 'INSERT IGNORE `table_name` SET
        `column_name1` = ? ,
        `column_name2` = ? ,
        `column_name3` = ?';
      $param = array($arg[1], $arg[2], $arg[3]);
      $this->db->query($sql, $param);
      return $this->db->insert_id();
    } ?>

Read

Update

Delete


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS