依頼されたツールを誰かが作るスレat PHP依頼されたツールを誰かが作るスレ - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト106:nobodyさん 05/01/04 00:07:21 -- テーブルこんな感じで create table quiz ( id integer unsigned not null auto_increment, question text not null, answer enum('A', 'B', 'C', 'D'), A varchar(64) not null, B varchar(64) not null, C varchar(64) not null, primary key (id) ); 107:nobodyさん 05/01/04 00:07:49 データベース周りの操作をまとめたクラス quiz.php.inc <?php class Quiz { var $table='quiz'; function Quiz() {} function connectDB($dbserver, $username, $password, $database) { @mysql_connect($dbserver, $username, $password); @mysql_select_db($database); } function query($query_string) { $result = @mysql_query($query_string); if (! $result) { printf("MySQL error(%d): %s\n", @mysql_errno(), @mysql_error()); return NULL; } return @mysql_fetch_object($result); } function getAnswer($id) { return $this->query("SELECT `answer` FROM $this->table WHERE `id`=$id;"); } function getQuestion($id) { return $this->query("SELECT `question`,`A`,`B`,`C`,`D` FROM $this->table WHERE `id`=$id;"); } function addQuestion($question, $answer, $answers) { assert(in_array($answer, array('A', 'B', 'C', 'D'))); assert(4 == count($answers)); list($A, $B, $C, $D) = $answers; $this->query("INSERT INTO `$this->table` VALUES(NULL,`$question`,`$answer`,`$A`,`$B`,`$C`,`$D`);"); } } ?> 続きは、また今度。 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch