開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- MySQL (データベース)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP & MySQL 第2版』(Michele E. Davis、Jon A. Phillips 著、西沢 直木 訳、オライリー・ジャパン、2008年、ISBN978-4-87311-365-4)の7章(MySQLとの連携)の問題を解いてみる。
問6-1.
入出力結果(Terminal)
$ mysql -u kamimura -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 204 Server version: 5.5.18 MySQL Community Server (GPL) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sample_store | | store | | test | +--------------------+ 6 rows in set (0.01 sec) mysql> use store Database changed mysql> create table months( -> month_id int not null auto_increment, -> name varchar(10), -> days int, -> primary key(month_id)); Query OK, 0 rows affected (0.31 sec) mysql> insert into months values(1,'January',31); Query OK, 1 row affected (0.11 sec) mysql> insert into months values(null,'February',28); Query OK, 1 row affected (0.03 sec) mysql> insert into months values(null,'March',31); Query OK, 1 row affected (0.01 sec) mysql> insert into months values(null,'April',30); Query OK, 1 row affected (0.00 sec) mysql> insert into months values(null,'May',31); Query OK, 1 row affected (0.00 sec) mysql> insert into months values(null,'June',30); Query OK, 1 row affected (0.01 sec) mysql> insert into months values(null,'July',31); Query OK, 1 row affected (0.01 sec) mysql> insert into months values(null,'August',31); Query OK, 1 row affected (0.01 sec) mysql> insert into months values(null,'September',30); Query OK, 1 row affected (0.00 sec) mysql> insert into months values(null,'October',31); Query OK, 1 row affected (0.00 sec) mysql> insert into months values(null,'November',30); Query OK, 1 row affected (0.02 sec) mysql> insert into months values(null,'December',31); Query OK, 1 row affected (0.02 sec) mysql> describe months; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | month_id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(10) | YES | | NULL | | | days | int(11) | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+ 3 rows in set (0.23 sec) mysql> select month_id,name,days from months; +----------+-----------+------+ | month_id | name | days | +----------+-----------+------+ | 1 | January | 31 | | 2 | February | 28 | | 3 | March | 31 | | 4 | April | 30 | | 5 | May | 31 | | 6 | June | 30 | | 7 | July | 31 | | 8 | August | 31 | | 9 | September | 30 | | 10 | October | 31 | | 11 | November | 30 | | 12 | December | 31 | +----------+-----------+------+ 12 rows in set (0.06 sec) mysql> select month_id,name,days from months where days=28 -> ; +----------+----------+------+ | month_id | name | days | +----------+----------+------+ | 2 | February | 28 | +----------+----------+------+ 1 row in set (0.37 sec) mysql> select month_id,name,days from months where name like '%ber'; +----------+-----------+------+ | month_id | name | days | +----------+-----------+------+ | 9 | September | 30 | | 10 | October | 31 | | 11 | November | 30 | | 12 | December | 31 | +----------+-----------+------+ 4 rows in set (0.00 sec) mysql> exit Bye
併せて読んでいる書籍。
Pythonの学習が1周したら上記の2冊を順に取り組む計画。それまではひたすら復習!
0 コメント:
コメントを投稿