* INSERT/UPDATE/DELETE [#xa124878]
 $sql = 'insert into t1 (num, str) values (?,?)';
 $sth = $dbh->prepare($sql);
 $sth->execute(time,"i'm happy");
** prepare()とexecute()をまとめて行う [#d338218c]
 $num_of_rows = $dbh->do('update t1 set num = 1 where num > 0'); 
 $num_of_rows = $dbh->do('update t1 set num = ? where num > ?', {}, 10,1); 
影響した行数が0の場合は、$num_of_rowsには"0E0"が入ってる。よって$dbh->do(XXX) or die $dbh->errstrと記述できる。

** 影響した行数 [#b599df14]
 $num_of_rows = $sth->rows;
 $num_of_rows = $sth->execute;

** シリアル(AUTO_INCREMNT)型の値の取得 [#n8102093]
 print $dbh->last_insert_id(undef,undef,'t1','id');   # テーブル名とカラム名を指定
 print $dbh->last_insert_id(undef,undef,undef,undef); # MySQLだとこれでも取れる

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS