| サンプル集 |
|
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■other |
| Linuxコマンド |
| 用語集 |
| debian メモ |
| apache2 メモ |
| MySQL メモ |
| Oracle メモ |
| HOME |
php で MySQL へレコード追加します。
◆環境| OS | Windows XP Professional Version 2002 Service Pack 3 |
|---|---|
| PHP | 5.2.4 |
引数で追加する件数を指定するようにしました。
| insert_test.php | ||
|
test_tbl は以下の SQL で生成しました。
| test_tbl.sql | ||
|
◆実行結果
>php insert_test.php 10
接続成功
DB選択成功
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
コミット成功
DB切断
接続成功
DB選択成功
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
追加件数:1
コミット成功
DB切断
DB を検索したらちゃんと 10件追加されていました。
mysql> select * from test_tbl;
+---------+--------+
| charVal | intVal |
+---------+--------+
| text0 | 0 |
| text1 | 1 |
| text2 | 2 |
| text3 | 3 |
| text4 | 4 |
| text5 | 5 |
| text6 | 6 |
| text7 | 7 |
| text8 | 8 |
| text9 | 9 |
+---------+--------+
10 rows in set (0.00 sec)
+---------+--------+
| charVal | intVal |
+---------+--------+
| text0 | 0 |
| text1 | 1 |
| text2 | 2 |
| text3 | 3 |
| text4 | 4 |
| text5 | 5 |
| text6 | 6 |
| text7 | 7 |
| text8 | 8 |
| text9 | 9 |
+---------+--------+
10 rows in set (0.00 sec)
Copyright (C) 2012 ymlib.com
