ひさびさにCakePHPをいじると、やっぱり疲れる。
簡単なところではsaveですでにはまる。
ループの中にsaveを入れると、最後のsaveしか実行されない。前にそんなことを書いた気がするけど書いてなかった。そういう時はcreateしとけば良いっぽいけど、なんか違う気もする。
foreach ($names as $name) {
$data = array('User' => array());
$data['User']['name'] = $name;
$this->User->save($data);
$this->User->create();
}
まあ、今回は新しくDBを作成(初期化)するときのテンプレートをメモっておく。
・MySQL(4.x?)の場合
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name CHAR(100) NOT NULL UNIQUE,
password CHAR(100) NOT NULL,
nickname CHAR(32),
profile BLOB,
confirm INTEGER DEFAULT 0,
created CHAR(40) DEFAULT NULL,
modified CHAR(40) DEFAULT NULL
);
テーブルがある場合は最初に削除してる。
idは自動でインクリメントされるように「AUTO_INCREMENT PRIMARY KEY」を指定、createdとmodifiedはCHAR(40)くらいにしとく。
・SQLite(2)の場合
DROP TABLE users;
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name CHAR(100) NOT NULL UNIQUE,
password CHAR(100) NOT NULL,
nickname CHAR(32) NOT NULL,
profile BLOB,
confirm INTEGER DEFAULT 0,
created DEFAULT NULL,
modified DEFAULT NULL
);
DROP文にIFが使えない。これを実行したときにusersテーブルがないとエラーが出るけど、まあ気にしない。
idは自動でインクリメントされるように「INTEGER PRIMARY KEY」を指定、createdとmodifiedにCHARとか指定するとうまくいかなかったような・・・。まあ、SQLiteなんで型は適当でいいはず。
以上
You could certainly see your expertise in the work you write. The world hopes for more passionate writers like you who aren’t afraid to say how they believe. Always follow your heart.
you are truly a excellent webmaster. The web site loading velocity is amazing.
It kind of feels that you are doing any unique trick. Moreover,
The contents are masterwork. you have performed a magnificent activity
on this subject!
Hi mates, its fantastic article about tutoringand completely defined,
keep it up all the time.
Hi to all, for the reason that I am really eager of reading this weblog’s post to be updated on a regular basis.
It carries good material.
However, preparing any other part, it could be a smart idea
to, yourself would try to determine the type of look you need to placed on the perfect day so that once the makeup artist
is there it will likely be feasible for the right results on you to make the style
that you would like to achieve. Some professionals even believe that enough time they are getting their face done
is time for reflection and relaxation before
becoming started in their performance. Eyelashes are the way to enhance your vision,
yes even if you have long eyelashes, and an easy,natural approach to make your makeup unique of
another day.